mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Switch to using messaging and startable stoppable from NPM package (#7368)
* Add custom jest resolver to fix requiring "uuid" module Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Update dependencies Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Introduce test utils for rendering and running with thrown mobx reactions Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract startable-stoppable to NPM package Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract messaging to NPM package Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Switch to using startable-stoppable from NPM package Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Switch to using messaging from the Feature Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove old implementation of messaging Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make setupping app paths happen earlier in renderer Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix typo Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Add kludge to make testing-library work properly from test-utils package Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix code style Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Add lint:fix -root script Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Fix unrelated failing unit tests Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Turn of no-floating-promises from typescript linting for being broken Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make linting not happen for dist -directories Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make linting failures appear as failure Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Stop running prettier twice It already gets ran as eslint-plugin. Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Make CI run unit tests for all packages by consolidating name of NPM script Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Add missing unit tests for coverage Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Skip coverage for test utils Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Remove check for coverage in packages which are not ready for it Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Stop collecting coverage from index.ts files them being indirections to the implementation Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Implement sending message to channel in main Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Add missing feature dependencies Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Add dummy implementations for requesting in main from renderer Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Re-enable communicating from main to cluster frames Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Ignore trivial files from coverage Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Update package-lock Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract message-bridge to separate NPM package to prevent dev dependencies being in the production bundle Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Extract computed channel to own NPM package for clear dependencies Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Consolidate electron related stuff to a directory Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Add missing publish configurations Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> * Ignore test implementation from coverage being not interesting Signed-off-by: Janne Savolainen <janne.savolainen@live.fi> --------- Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
1 parent
df49ff9b96
commit
0f1f030a06
261 files changed
+4447
-1795
No files matched your search
@@ -1,2 +1,3 @@
|
||||
module.exports =
|
||||
require("@k8slens/jest").monorepoPackageConfig(__dirname).configForReact;
|
||||
const config = require("@k8slens/jest").monorepoPackageConfig(__dirname).configForReact;
|
||||
|
||||
module.exports = { ...config, coverageThreshold: undefined };
|
||||
@@ -22,12 +22,12 @@
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
"dev": "webpack --mode=development --watch",
|
||||
"test": "jest --coverage --runInBand"
|
||||
"test:unit": "jest --coverage --runInBand"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@k8slens/test-utils": "^1.0.0-alpha.1",
|
||||
"@k8slens/utilities": "^1.0.0-alpha.1",
|
||||
"@ogre-tools/fp": "^15.1.1",
|
||||
"@ogre-tools/fp": "^15.1.2",
|
||||
"@ogre-tools/injectable": "^15.1.2",
|
||||
"type-fest": "^2.19.0",
|
||||
"typed-emitter": "^1.4.0",
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "@k8slens/eslint-config/eslint",
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.json"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
"@k8slens/eslint-config/prettier"
|
||||
@@ -0,0 +1,3 @@
|
||||
export type { StartableStoppable, Starter, Stopper } from "./src/get-startable-stoppable";
|
||||
|
||||
export { getStartableStoppable } from "./src/get-startable-stoppable";
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require("@k8slens/jest").monorepoPackageConfig(__dirname).configForReact;
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "@k8slens/startable-stoppable",
|
||||
"private": false,
|
||||
"version": "1.0.0-alpha.1",
|
||||
"description": "TBD",
|
||||
"type": "commonjs",
|
||||
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
|
||||
"files": [
|
||||
"build"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/lensapp/lens.git"
|
||||
},
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"author": {
|
||||
"name": "OpenLens Authors",
|
||||
"email": "info@k8slens.dev"
|
||||
},
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/lensapp/lens",
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
"dev": "webpack --mode=development --watch",
|
||||
"test:unit": "jest --coverage --runInBand",
|
||||
"lint": "lens-lint",
|
||||
"lint:fix": "lens-lint --fix"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@k8slens/eslint-config": "^6.5.0-alpha.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import type { StartableStoppable } from "./get-startable-stoppable";
|
||||
import { getStartableStoppable } from "./get-startable-stoppable";
|
||||
|
||||
describe("getStartableStoppable", () => {
|
||||
let stopMock: jest.MockedFunction<() => void>;
|
||||
let startMock: jest.MockedFunction<() => () => void>;
|
||||
let actual: StartableStoppable;
|
||||
|
||||
beforeEach(() => {
|
||||
stopMock = jest.fn();
|
||||
startMock = jest.fn().mockImplementation(() => stopMock);
|
||||
actual = getStartableStoppable("some-id", startMock);
|
||||
});
|
||||
|
||||
it("does not start yet", () => {
|
||||
expect(startMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not stop yet", () => {
|
||||
expect(stopMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("when stopping before ever starting, throws", () => {
|
||||
expect(() => actual.stop()).toThrow('Tried to stop "some-id", but it is already stopped.');
|
||||
});
|
||||
|
||||
it("is not started", () => {
|
||||
expect(actual.started).toBe(false);
|
||||
});
|
||||
|
||||
describe("when started", () => {
|
||||
beforeEach(() => {
|
||||
actual.start();
|
||||
});
|
||||
|
||||
it("calls start function", () => {
|
||||
expect(startMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("is started", () => {
|
||||
expect(actual.started).toBe(true);
|
||||
});
|
||||
|
||||
it("when started again, throws", () => {
|
||||
expect(() => actual.start()).toThrow('Tried to start "some-id", but it is already started.');
|
||||
});
|
||||
|
||||
describe("when stopped", () => {
|
||||
beforeEach(() => {
|
||||
actual.stop();
|
||||
});
|
||||
|
||||
it("calls stop function", () => {
|
||||
expect(stopMock).toBeCalled();
|
||||
});
|
||||
|
||||
it("is stopped", () => {
|
||||
expect(actual.started).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
export type Stopper = () => void;
|
||||
export type Starter = () => Stopper;
|
||||
|
||||
export interface StartableStoppable {
|
||||
readonly started: boolean;
|
||||
start: () => void;
|
||||
stop: () => void;
|
||||
}
|
||||
|
||||
type StartableStoppableState = "stopped" | "started" | "starting";
|
||||
|
||||
export function getStartableStoppable(id: string, startAndGetStopper: Starter): StartableStoppable {
|
||||
let stop: Stopper;
|
||||
let state: StartableStoppableState = "stopped";
|
||||
|
||||
return {
|
||||
get started() {
|
||||
return state === "started";
|
||||
},
|
||||
|
||||
start: () => {
|
||||
if (state !== "stopped") {
|
||||
throw new Error(`Tried to start "${id}", but it is already ${state}.`);
|
||||
}
|
||||
|
||||
state = "starting";
|
||||
stop = startAndGetStopper();
|
||||
state = "started";
|
||||
},
|
||||
|
||||
stop: () => {
|
||||
if (state !== "started") {
|
||||
throw new Error(`Tried to stop "${id}", but it is already ${state}.`);
|
||||
}
|
||||
|
||||
stop();
|
||||
state = "stopped";
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "@k8slens/typescript/config/base.json",
|
||||
"include": ["**/*.ts"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = require("@k8slens/webpack").configForNode;
|
||||
@@ -2,3 +2,5 @@ export * from "./src/flush-promises";
|
||||
export * from "./src/get-global-override-for-function";
|
||||
export * from "./src/get-global-override";
|
||||
export * from "./src/get-promise-status";
|
||||
export * from "./src/render-for";
|
||||
export * from "./src/run-with-thrown-mobx-reactions";
|
||||
@@ -21,12 +21,14 @@
|
||||
"homepage": "https://github.com/lensapp/lens",
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
"dev": "webpack --mode=development --watch",
|
||||
"test": "jest --coverage --runInBand"
|
||||
"dev": "webpack --mode=development --watch"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@ogre-tools/injectable": "^15.1.2",
|
||||
"lodash": "^4.17.21"
|
||||
"@ogre-tools/injectable-react": "^15.1.2",
|
||||
"@testing-library/react": "^12.1.5",
|
||||
"lodash": "^4.17.21",
|
||||
"react": "^17.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash": "^4.14.191"
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import React from "react";
|
||||
import type { RenderResult } from "@testing-library/react";
|
||||
import { render as testingLibraryRender } from "@testing-library/react";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import { DiContextProvider } from "@ogre-tools/injectable-react";
|
||||
|
||||
export type DiRender = (ui: React.ReactElement) => RenderResult;
|
||||
|
||||
type DiRenderFor = (di: DiContainer) => DiRender;
|
||||
|
||||
export const renderFor: DiRenderFor = (di) => (ui) => {
|
||||
const result = testingLibraryRender(
|
||||
<DiContextProvider value={{ di }}>{ui}</DiContextProvider>
|
||||
);
|
||||
|
||||
return {
|
||||
...result,
|
||||
|
||||
rerender: (ui: React.ReactElement) =>
|
||||
result.rerender(
|
||||
<DiContextProvider value={{ di }}>{ui}</DiContextProvider>
|
||||
),
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
import { noop } from "lodash/fp";
|
||||
import { _resetGlobalState, configure } from "mobx";
|
||||
|
||||
export const runWithThrownMobxReactions = (callback: () => void) => {
|
||||
const originalConsoleWarn = console.warn;
|
||||
|
||||
console.warn = noop;
|
||||
|
||||
configure({
|
||||
disableErrorBoundaries: true,
|
||||
});
|
||||
|
||||
console.warn = originalConsoleWarn;
|
||||
|
||||
let error: any;
|
||||
|
||||
try {
|
||||
callback();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} finally {
|
||||
configure({
|
||||
disableErrorBoundaries: false,
|
||||
});
|
||||
|
||||
// This is because when disableErrorBoundaries is true, MobX doesn't recover from the thrown
|
||||
// errors, and its global state starts bleeding between tests making.
|
||||
_resetGlobalState();
|
||||
|
||||
if (!error) {
|
||||
throw new Error(
|
||||
"Tried to run with thrown MobX reactions but nothing was thrown"
|
||||
);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,2 +1,3 @@
|
||||
module.exports =
|
||||
require("@k8slens/jest").monorepoPackageConfig(__dirname).configForReact;
|
||||
const config = require("@k8slens/jest").monorepoPackageConfig(__dirname).configForReact;
|
||||
|
||||
module.exports = { ...config, coverageThreshold: undefined };
|
||||
@@ -22,7 +22,7 @@
|
||||
"scripts": {
|
||||
"build": "webpack",
|
||||
"dev": "webpack --mode=development --watch",
|
||||
"test": "jest --coverage --runInBand"
|
||||
"test:unit": "jest --coverage --runInBand"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@astronautlabs/jsonpath": "^1.1.0",
|
||||
@@ -47,6 +47,7 @@
|
||||
"@types/react-router": "^5.1.20",
|
||||
"@types/readable-stream": "^2.3.15",
|
||||
"@types/semver": "^7.3.13",
|
||||
"@types/tar": "^6.1.4"
|
||||
"@types/tar": "^6.1.4",
|
||||
"type-fest": "^2.14.0"
|
||||
}
|
||||
}
|
||||
@@ -3,62 +3,62 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { bifurcateArray, splitArray } from "../splitArray";
|
||||
import { array } from "./array";
|
||||
|
||||
describe("split array on element tests", () => {
|
||||
it("empty array", () => {
|
||||
expect(splitArray([], 10)).toStrictEqual([[], [], false]);
|
||||
expect(array.split([], 10)).toStrictEqual([[], [], false]);
|
||||
});
|
||||
|
||||
it("one element, not in array", () => {
|
||||
expect(splitArray([1], 10)).toStrictEqual([[1], [], false]);
|
||||
expect(array.split([1], 10)).toStrictEqual([[1], [], false]);
|
||||
});
|
||||
|
||||
it("ten elements, not in array", () => {
|
||||
expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10)).toStrictEqual([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], false]);
|
||||
expect(array.split([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 10)).toStrictEqual([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [], false]);
|
||||
});
|
||||
|
||||
it("one elements, in array", () => {
|
||||
expect(splitArray([1], 1)).toStrictEqual([[], [], true]);
|
||||
expect(array.split([1], 1)).toStrictEqual([[], [], true]);
|
||||
});
|
||||
|
||||
it("ten elements, in front array", () => {
|
||||
expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0)).toStrictEqual([[], [1, 2, 3, 4, 5, 6, 7, 8, 9], true]);
|
||||
expect(array.split([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 0)).toStrictEqual([[], [1, 2, 3, 4, 5, 6, 7, 8, 9], true]);
|
||||
});
|
||||
|
||||
it("ten elements, in middle array", () => {
|
||||
expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)).toStrictEqual([[0, 1, 2, 3], [5, 6, 7, 8, 9], true]);
|
||||
expect(array.split([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 4)).toStrictEqual([[0, 1, 2, 3], [5, 6, 7, 8, 9], true]);
|
||||
});
|
||||
|
||||
it("ten elements, in end array", () => {
|
||||
expect(splitArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 9)).toStrictEqual([[0, 1, 2, 3, 4, 5, 6, 7, 8], [], true]);
|
||||
expect(array.split([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 9)).toStrictEqual([[0, 1, 2, 3, 4, 5, 6, 7, 8], [], true]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("bifurcateArray", () => {
|
||||
it("should return tuple of empty arrays from empty array", () => {
|
||||
const [left, right] = bifurcateArray([], () => true);
|
||||
const [left, right] = array.bifurcate([], () => true);
|
||||
|
||||
expect(left).toStrictEqual([]);
|
||||
expect(right).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it("should return all true condition returning items in the right array", () => {
|
||||
const [left, right] = bifurcateArray([1, 2, 3], () => true);
|
||||
const [left, right] = array.bifurcate([1, 2, 3], () => true);
|
||||
|
||||
expect(left).toStrictEqual([]);
|
||||
expect(right).toStrictEqual([1, 2, 3]);
|
||||
});
|
||||
|
||||
it("should return all false condition returning items in the right array", () => {
|
||||
const [left, right] = bifurcateArray([1, 2, 3], () => false);
|
||||
const [left, right] = array.bifurcate([1, 2, 3], () => false);
|
||||
|
||||
expect(left).toStrictEqual([1, 2, 3]);
|
||||
expect(right).toStrictEqual([]);
|
||||
});
|
||||
|
||||
it("should split array as specified", () => {
|
||||
const [left, right] = bifurcateArray([1, 2, 3], (i) => Boolean(i % 2));
|
||||
const [left, right] = array.bifurcate([1, 2, 3], (i) => Boolean(i % 2));
|
||||
|
||||
expect(left).toStrictEqual([2]);
|
||||
expect(right).toStrictEqual([1, 3]);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import path from "path";
|
||||
import { unionPATHs } from "../union-env-path";
|
||||
import { unionPATHs } from "./union-env-path";
|
||||
|
||||
describe("unionPATHs", () => {
|
||||
it("return the same path if given only one with no double delimiters", () => {
|
||||
|
||||
Reference in new issue
Block a user