mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix unit tests and make tests fail if a promise rejects after the test harness is finishes
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
f287b8a3d0
commit
e69f07d1af
8
Makefile
8
Makefile
@ -16,16 +16,16 @@ node_modules: yarn.lock
|
|||||||
yarn install --frozen-lockfile
|
yarn install --frozen-lockfile
|
||||||
yarn check --verify-tree --integrity
|
yarn check --verify-tree --integrity
|
||||||
|
|
||||||
static/build/LensDev.html:
|
static/build/LensDev.html: node_modules
|
||||||
yarn compile:renderer
|
yarn compile:renderer
|
||||||
|
|
||||||
.PHONY: compile-dev
|
.PHONY: compile-dev
|
||||||
compile-dev:
|
compile-dev: node_modules
|
||||||
yarn compile:main --cache
|
yarn compile:main --cache
|
||||||
yarn compile:renderer --cache
|
yarn compile:renderer --cache
|
||||||
|
|
||||||
.PHONY: dev
|
.PHONY: dev
|
||||||
dev: node_modules binaries/client build-extensions static/build/LensDev.html
|
dev: binaries/client build-extensions static/build/LensDev.html
|
||||||
yarn dev
|
yarn dev
|
||||||
|
|
||||||
.PHONY: lint
|
.PHONY: lint
|
||||||
@ -77,7 +77,7 @@ $(extension_dists): src/extensions/npm/extensions/dist
|
|||||||
cd $(@:/dist=) && npm run build
|
cd $(@:/dist=) && npm run build
|
||||||
|
|
||||||
.PHONY: build-extensions
|
.PHONY: build-extensions
|
||||||
build-extensions: $(extension_node_modules) $(extension_dists)
|
build-extensions: node_modules $(extension_node_modules) $(extension_dists)
|
||||||
|
|
||||||
.PHONY: test-extensions
|
.PHONY: test-extensions
|
||||||
test-extensions: $(extension_node_modules)
|
test-extensions: $(extension_node_modules)
|
||||||
|
|||||||
@ -35,7 +35,8 @@ jest.mock("electron", () => {
|
|||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
getLocale: () => "en"
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
handle: jest.fn(),
|
handle: jest.fn(),
|
||||||
|
|||||||
@ -1,3 +1,7 @@
|
|||||||
|
import { Console } from "console";
|
||||||
|
|
||||||
|
console = new Console(process.stdout, process.stderr);
|
||||||
|
|
||||||
import mockFs from "mock-fs";
|
import mockFs from "mock-fs";
|
||||||
|
|
||||||
jest.mock("electron", () => {
|
jest.mock("electron", () => {
|
||||||
@ -5,7 +9,8 @@ jest.mock("electron", () => {
|
|||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
getLocale: () => "en"
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,7 +5,8 @@ jest.mock("electron", () => {
|
|||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
getPath: () => "tmp",
|
getPath: () => "tmp",
|
||||||
getLocale: () => "en"
|
getLocale: () => "en",
|
||||||
|
setLoginItemSettings: jest.fn(),
|
||||||
},
|
},
|
||||||
ipcMain: {
|
ipcMain: {
|
||||||
handle: jest.fn(),
|
handle: jest.fn(),
|
||||||
|
|||||||
@ -19,7 +19,7 @@ export interface BaseStoreParams<T = any> extends ConfOptions<T> {
|
|||||||
* Note: T should only contain base JSON serializable types.
|
* Note: T should only contain base JSON serializable types.
|
||||||
*/
|
*/
|
||||||
export abstract class BaseStore<T = any> extends Singleton {
|
export abstract class BaseStore<T = any> extends Singleton {
|
||||||
protected storeConfig: Config<T>;
|
protected storeConfig?: Config<T>;
|
||||||
protected syncDisposers: Function[] = [];
|
protected syncDisposers: Function[] = [];
|
||||||
|
|
||||||
whenLoaded = when(() => this.isLoaded);
|
whenLoaded = when(() => this.isLoaded);
|
||||||
@ -36,7 +36,7 @@ export abstract class BaseStore<T = any> extends Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return path.basename(this.storeConfig.path);
|
return path.basename(this.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected get syncRendererChannel() {
|
protected get syncRendererChannel() {
|
||||||
@ -48,7 +48,7 @@ export abstract class BaseStore<T = any> extends Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get path() {
|
get path() {
|
||||||
return this.storeConfig.path;
|
return this.storeConfig?.path || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async init() {
|
protected async init() {
|
||||||
@ -82,10 +82,13 @@ export abstract class BaseStore<T = any> extends Singleton {
|
|||||||
|
|
||||||
protected async saveToFile(model: T) {
|
protected async saveToFile(model: T) {
|
||||||
logger.info(`[STORE]: SAVING ${this.path}`);
|
logger.info(`[STORE]: SAVING ${this.path}`);
|
||||||
|
|
||||||
// todo: update when fixed https://github.com/sindresorhus/conf/issues/114
|
// todo: update when fixed https://github.com/sindresorhus/conf/issues/114
|
||||||
Object.entries(model).forEach(([key, value]) => {
|
if (this.storeConfig) {
|
||||||
|
for (const [key, value] of Object.entries(model)) {
|
||||||
this.storeConfig.set(key, value);
|
this.storeConfig.set(key, value);
|
||||||
});
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enableSync() {
|
enableSync() {
|
||||||
|
|||||||
@ -4,3 +4,7 @@ fetchMock.enableMocks();
|
|||||||
|
|
||||||
// Mock __non_webpack_require__ for tests
|
// Mock __non_webpack_require__ for tests
|
||||||
globalThis.__non_webpack_require__ = jest.fn();
|
globalThis.__non_webpack_require__ = jest.fn();
|
||||||
|
|
||||||
|
process.on("unhandledRejection", (err) => {
|
||||||
|
fail(err);
|
||||||
|
});
|
||||||
|
|||||||
@ -1,14 +1,22 @@
|
|||||||
|
jest.mock("../kube-object");
|
||||||
|
jest.mock("../kube-api");
|
||||||
|
jest.mock("../api-manager", () => ({
|
||||||
|
apiManager() {
|
||||||
|
return {
|
||||||
|
registerStore: jest.fn(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
import { IKubeApiParsed, parseKubeApi } from "../kube-api-parse";
|
import { IKubeApiParsed, parseKubeApi } from "../kube-api-parse";
|
||||||
|
|
||||||
interface KubeApiParseTestData {
|
/**
|
||||||
url: string;
|
* [<input-url>, <expected-result>]
|
||||||
expected: Required<IKubeApiParsed>;
|
*/
|
||||||
}
|
type KubeApiParseTestData = [string, Required<IKubeApiParsed>];
|
||||||
|
|
||||||
const tests: KubeApiParseTestData[] = [
|
const tests: KubeApiParseTestData[] = [
|
||||||
{
|
["/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/prometheuses.monitoring.coreos.com", {
|
||||||
url: "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/prometheuses.monitoring.coreos.com",
|
|
||||||
expected: {
|
|
||||||
apiBase: "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions",
|
apiBase: "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions",
|
||||||
apiPrefix: "/apis",
|
apiPrefix: "/apis",
|
||||||
apiGroup: "apiextensions.k8s.io",
|
apiGroup: "apiextensions.k8s.io",
|
||||||
@ -17,11 +25,8 @@ const tests: KubeApiParseTestData[] = [
|
|||||||
namespace: undefined,
|
namespace: undefined,
|
||||||
resource: "customresourcedefinitions",
|
resource: "customresourcedefinitions",
|
||||||
name: "prometheuses.monitoring.coreos.com"
|
name: "prometheuses.monitoring.coreos.com"
|
||||||
},
|
}],
|
||||||
},
|
["/api/v1/namespaces/kube-system/pods/coredns-6955765f44-v8p27", {
|
||||||
{
|
|
||||||
url: "/api/v1/namespaces/kube-system/pods/coredns-6955765f44-v8p27",
|
|
||||||
expected: {
|
|
||||||
apiBase: "/api/v1/pods",
|
apiBase: "/api/v1/pods",
|
||||||
apiPrefix: "/api",
|
apiPrefix: "/api",
|
||||||
apiGroup: "",
|
apiGroup: "",
|
||||||
@ -30,11 +35,8 @@ const tests: KubeApiParseTestData[] = [
|
|||||||
namespace: "kube-system",
|
namespace: "kube-system",
|
||||||
resource: "pods",
|
resource: "pods",
|
||||||
name: "coredns-6955765f44-v8p27"
|
name: "coredns-6955765f44-v8p27"
|
||||||
},
|
}],
|
||||||
},
|
["/apis/stable.example.com/foo1/crontabs", {
|
||||||
{
|
|
||||||
url: "/apis/stable.example.com/foo1/crontabs",
|
|
||||||
expected: {
|
|
||||||
apiBase: "/apis/stable.example.com/foo1/crontabs",
|
apiBase: "/apis/stable.example.com/foo1/crontabs",
|
||||||
apiPrefix: "/apis",
|
apiPrefix: "/apis",
|
||||||
apiGroup: "stable.example.com",
|
apiGroup: "stable.example.com",
|
||||||
@ -43,11 +45,8 @@ const tests: KubeApiParseTestData[] = [
|
|||||||
resource: "crontabs",
|
resource: "crontabs",
|
||||||
name: undefined,
|
name: undefined,
|
||||||
namespace: undefined,
|
namespace: undefined,
|
||||||
},
|
}],
|
||||||
},
|
["/apis/cluster.k8s.io/v1alpha1/clusters", {
|
||||||
{
|
|
||||||
url: "/apis/cluster.k8s.io/v1alpha1/clusters",
|
|
||||||
expected: {
|
|
||||||
apiBase: "/apis/cluster.k8s.io/v1alpha1/clusters",
|
apiBase: "/apis/cluster.k8s.io/v1alpha1/clusters",
|
||||||
apiPrefix: "/apis",
|
apiPrefix: "/apis",
|
||||||
apiGroup: "cluster.k8s.io",
|
apiGroup: "cluster.k8s.io",
|
||||||
@ -56,11 +55,8 @@ const tests: KubeApiParseTestData[] = [
|
|||||||
resource: "clusters",
|
resource: "clusters",
|
||||||
name: undefined,
|
name: undefined,
|
||||||
namespace: undefined,
|
namespace: undefined,
|
||||||
},
|
}],
|
||||||
},
|
["/api/v1/namespaces", {
|
||||||
{
|
|
||||||
url: "/api/v1/namespaces",
|
|
||||||
expected: {
|
|
||||||
apiBase: "/api/v1/namespaces",
|
apiBase: "/api/v1/namespaces",
|
||||||
apiPrefix: "/api",
|
apiPrefix: "/api",
|
||||||
apiGroup: "",
|
apiGroup: "",
|
||||||
@ -69,11 +65,8 @@ const tests: KubeApiParseTestData[] = [
|
|||||||
resource: "namespaces",
|
resource: "namespaces",
|
||||||
name: undefined,
|
name: undefined,
|
||||||
namespace: undefined,
|
namespace: undefined,
|
||||||
},
|
}],
|
||||||
},
|
["/api/v1/secrets", {
|
||||||
{
|
|
||||||
url: "/api/v1/secrets",
|
|
||||||
expected: {
|
|
||||||
apiBase: "/api/v1/secrets",
|
apiBase: "/api/v1/secrets",
|
||||||
apiPrefix: "/api",
|
apiPrefix: "/api",
|
||||||
apiGroup: "",
|
apiGroup: "",
|
||||||
@ -82,11 +75,8 @@ const tests: KubeApiParseTestData[] = [
|
|||||||
resource: "secrets",
|
resource: "secrets",
|
||||||
name: undefined,
|
name: undefined,
|
||||||
namespace: undefined,
|
namespace: undefined,
|
||||||
},
|
}],
|
||||||
},
|
["/api/v1/nodes/minikube", {
|
||||||
{
|
|
||||||
url: "/api/v1/nodes/minikube",
|
|
||||||
expected: {
|
|
||||||
apiBase: "/api/v1/nodes",
|
apiBase: "/api/v1/nodes",
|
||||||
apiPrefix: "/api",
|
apiPrefix: "/api",
|
||||||
apiGroup: "",
|
apiGroup: "",
|
||||||
@ -95,11 +85,8 @@ const tests: KubeApiParseTestData[] = [
|
|||||||
resource: "nodes",
|
resource: "nodes",
|
||||||
name: "minikube",
|
name: "minikube",
|
||||||
namespace: undefined,
|
namespace: undefined,
|
||||||
},
|
}],
|
||||||
},
|
["/api/foo-bar/nodes/minikube", {
|
||||||
{
|
|
||||||
url: "/api/foo-bar/nodes/minikube",
|
|
||||||
expected: {
|
|
||||||
apiBase: "/api/foo-bar/nodes",
|
apiBase: "/api/foo-bar/nodes",
|
||||||
apiPrefix: "/api",
|
apiPrefix: "/api",
|
||||||
apiGroup: "",
|
apiGroup: "",
|
||||||
@ -108,11 +95,8 @@ const tests: KubeApiParseTestData[] = [
|
|||||||
resource: "nodes",
|
resource: "nodes",
|
||||||
name: "minikube",
|
name: "minikube",
|
||||||
namespace: undefined,
|
namespace: undefined,
|
||||||
},
|
}],
|
||||||
},
|
["/api/v1/namespaces/kube-public", {
|
||||||
{
|
|
||||||
url: "/api/v1/namespaces/kube-public",
|
|
||||||
expected: {
|
|
||||||
apiBase: "/api/v1/namespaces",
|
apiBase: "/api/v1/namespaces",
|
||||||
apiPrefix: "/api",
|
apiPrefix: "/api",
|
||||||
apiGroup: "",
|
apiGroup: "",
|
||||||
@ -121,14 +105,11 @@ const tests: KubeApiParseTestData[] = [
|
|||||||
resource: "namespaces",
|
resource: "namespaces",
|
||||||
name: "kube-public",
|
name: "kube-public",
|
||||||
namespace: undefined,
|
namespace: undefined,
|
||||||
},
|
}],
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
|
||||||
describe("parseApi unit tests", () => {
|
describe("parseApi unit tests", () => {
|
||||||
for (const { url, expected } of tests) {
|
it.each(tests)("testing %s", (url, expected) => {
|
||||||
test(`testing "${url}"`, () => {
|
|
||||||
expect(parseKubeApi(url)).toStrictEqual(expected);
|
expect(parseKubeApi(url)).toStrictEqual(expected);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -6,6 +6,20 @@ import { DockTabs } from "../dock-tabs";
|
|||||||
import { dockStore, IDockTab, TabKind } from "../dock.store";
|
import { dockStore, IDockTab, TabKind } from "../dock.store";
|
||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
|
|
||||||
|
Object.defineProperty(window, "matchMedia", {
|
||||||
|
writable: true,
|
||||||
|
value: jest.fn().mockImplementation(query => ({
|
||||||
|
matches: false,
|
||||||
|
media: query,
|
||||||
|
onchange: null,
|
||||||
|
addListener: jest.fn(), // deprecated
|
||||||
|
removeListener: jest.fn(), // deprecated
|
||||||
|
addEventListener: jest.fn(),
|
||||||
|
removeEventListener: jest.fn(),
|
||||||
|
dispatchEvent: jest.fn(),
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
const onChangeTab = jest.fn();
|
const onChangeTab = jest.fn();
|
||||||
|
|
||||||
const getComponent = () => (
|
const getComponent = () => (
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user