1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Optimize registration of injectables in unit tests to make tests faster

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-06-29 10:56:55 +03:00
parent 9910f042d1
commit b9c239701b
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A
4 changed files with 47 additions and 52 deletions

View File

@ -209,11 +209,11 @@
"@hapi/subtext": "^7.0.4",
"@kubernetes/client-node": "^0.16.3",
"@material-ui/styles": "^4.11.5",
"@ogre-tools/fp": "9.0.0",
"@ogre-tools/injectable": "9.0.0",
"@ogre-tools/injectable-extension-for-auto-registration": "9.0.0",
"@ogre-tools/injectable-extension-for-mobx": "9.0.0",
"@ogre-tools/injectable-react": "9.0.0",
"@ogre-tools/fp": "9.0.1",
"@ogre-tools/injectable": "9.0.1",
"@ogre-tools/injectable-extension-for-auto-registration": "9.0.1",
"@ogre-tools/injectable-extension-for-mobx": "9.0.1",
"@ogre-tools/injectable-react": "9.0.1",
"@sentry/electron": "^3.0.7",
"@sentry/integrations": "^6.19.3",
"@side/jest-runtime": "^1.0.1",

View File

@ -4,7 +4,7 @@
*/
import glob from "glob";
import { kebabCase, memoize, noop } from "lodash/fp";
import { kebabCase, memoize, noop, chunk } from "lodash/fp";
import type { DiContainer, Injectable } from "@ogre-tools/injectable";
import { createContainer } from "@ogre-tools/injectable";
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
@ -112,15 +112,13 @@ export function getDiForUnitTesting(opts: { doGeneralOverrides?: boolean } = {})
setLegacyGlobalDiForExtensionApi(di, Environments.main);
for (const filePath of getInjectableFilePaths()) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const injectableInstance = require(filePath).default;
const filePaths = getInjectableFilePaths();
di.register({
...injectableInstance,
aliases: [injectableInstance, ...(injectableInstance.aliases || [])],
});
}
const injectables = filePaths.map(filePath => require(filePath).default);
chunk(100)(injectables).forEach(chunkInjectables => {
di.register(...chunkInjectables);
});
di.preventSideEffects();

View File

@ -4,10 +4,8 @@
*/
import glob from "glob";
import { memoize, noop } from "lodash/fp";
import type {
DiContainer,
Injectable } from "@ogre-tools/injectable";
import { memoize, noop, chunk } from "lodash/fp";
import type { DiContainer, Injectable } from "@ogre-tools/injectable";
import {
createContainer,
} from "@ogre-tools/injectable";
@ -82,14 +80,13 @@ export const getDiForUnitTesting = (opts: { doGeneralOverrides?: boolean } = {})
setLegacyGlobalDiForExtensionApi(di, Environments.renderer);
for (const filePath of getInjectableFilePaths()) {
const injectableInstance = require(filePath).default;
const filePaths = getInjectableFilePaths();
di.register({
...injectableInstance,
aliases: [injectableInstance, ...(injectableInstance.aliases || [])],
});
}
const injectables = filePaths.map(filePath => require(filePath).default);
chunk(100)(injectables).forEach(chunkInjectables => {
di.register(...chunkInjectables);
});
di.preventSideEffects();

View File

@ -1211,46 +1211,46 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"
"@ogre-tools/fp@9.0.0", "@ogre-tools/fp@^9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@ogre-tools/fp/-/fp-9.0.0.tgz#926cd4f13b52961156161feeeafddf22a0ad39c0"
integrity sha512-kMUgzhdjHuph0UWteOfyXNGBavZJX23NOA5su6fx9NdTzWhl9yB5Uf6Q//nOvL9COftjZDwnAgIaDU4MPdjyqA==
"@ogre-tools/fp@9.0.1", "@ogre-tools/fp@^9.0.1":
version "9.0.1"
resolved "https://registry.yarnpkg.com/@ogre-tools/fp/-/fp-9.0.1.tgz#22c23bd209f6f56bf66a5ff4514930334a3a4782"
integrity sha512-7kORUcvR9DZz5/2qDSSKExGeisXzfmOafP+Z6l8C+WQXEmEQm7CmFMyBEyMkei0eNFzNghlKYgRFpsvBdU3KAg==
dependencies:
lodash "^4.17.21"
"@ogre-tools/injectable-extension-for-auto-registration@9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-extension-for-auto-registration/-/injectable-extension-for-auto-registration-9.0.0.tgz#69463737ef4f7777db4703964b8a72a5fb82d6b3"
integrity sha512-+3I9Z0GfA04zZoj7Nw5WhJLDFLJgr5xv8Kp1zPDuT9/OvE9EA6hzAqakMDLbvn1zZOJjkJCGk44x6UjSQJp/9w==
"@ogre-tools/injectable-extension-for-auto-registration@9.0.1":
version "9.0.1"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-extension-for-auto-registration/-/injectable-extension-for-auto-registration-9.0.1.tgz#e00dff5bd833068faa58d8fa514b218515c55775"
integrity sha512-reyhW2wWPrNnGXo88QKWUsLyhjF195i0/iXfdAoR8/4lRxWmzka58bc8r6jFvTBBJ6eXaGidhUa5DqZe+Oia2Q==
dependencies:
"@ogre-tools/fp" "^9.0.0"
"@ogre-tools/injectable" "^9.0.0"
"@ogre-tools/fp" "^9.0.1"
"@ogre-tools/injectable" "^9.0.1"
lodash "^4.17.21"
"@ogre-tools/injectable-extension-for-mobx@9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-extension-for-mobx/-/injectable-extension-for-mobx-9.0.0.tgz#ed14df39b266e521272977821d3e05bcbd647577"
integrity sha512-9Hrtr7AdibcD+Fqn2qNsjiOUakAACO55TB1IqNsOJMMuqQHVB5SFZTHBzdVRqqqY2MwQvWYvd4xfy+beItD/xw==
"@ogre-tools/injectable-extension-for-mobx@9.0.1":
version "9.0.1"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-extension-for-mobx/-/injectable-extension-for-mobx-9.0.1.tgz#3d9e6e119b7db5a4e4309e89ba6b301635c8da90"
integrity sha512-wNHIG73NTGfmRb0b2nNhJD9ek4RcyBp/189KfrXhTt6/5KwMEuOeJjAbh8xwbhpYJnWFcMzWKLTqePozc+Ntww==
dependencies:
"@ogre-tools/fp" "^9.0.0"
"@ogre-tools/injectable" "^9.0.0"
"@ogre-tools/fp" "^9.0.1"
"@ogre-tools/injectable" "^9.0.1"
lodash "^4.17.21"
"@ogre-tools/injectable-react@9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-react/-/injectable-react-9.0.0.tgz#c5c510e893a5c1d7994d8709f70606967cabdec2"
integrity sha512-vGQrwkcWibRUWFPbu392riBYY4dXK051FxwyMsDYNRqmvaLo8HuumwjzS1DWS7db/P9Li+Kc+Ms670xIZepcpA==
"@ogre-tools/injectable-react@9.0.1":
version "9.0.1"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable-react/-/injectable-react-9.0.1.tgz#d72a155b914873f1a5e35ee167aa14dd7c0e7454"
integrity sha512-GjkhhONy4hamw5Mx79ZxhL3Pbgnfnf1mrkixDkqlXFzhdPBHDtCYIZu9Y6NjSRLgEwXTrAPYv9lDqREnRbUwLA==
dependencies:
"@ogre-tools/fp" "^9.0.0"
"@ogre-tools/injectable" "^9.0.0"
"@ogre-tools/fp" "^9.0.1"
"@ogre-tools/injectable" "^9.0.1"
lodash "^4.17.21"
"@ogre-tools/injectable@9.0.0", "@ogre-tools/injectable@^9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable/-/injectable-9.0.0.tgz#0819bc7b5fbae0a467f3250b10b4adb003268067"
integrity sha512-z9X86Q9AEkkilLu9V33j/aXv/IUoG944AdfN6WX2zZgJqRNjESN9spoOMqdKqib6JmEjCRxpMvaMwHLQSh14fg==
"@ogre-tools/injectable@9.0.1", "@ogre-tools/injectable@^9.0.1":
version "9.0.1"
resolved "https://registry.yarnpkg.com/@ogre-tools/injectable/-/injectable-9.0.1.tgz#611a2dd8468bfe3610f005178837d76071a44a70"
integrity sha512-orcERUOeUEP2oBAcr9rKYbik+r/xJEIb5uedPMMqPzPJnNwZ9JA/1rDEJcx1/I9aHgjUQpeFANjYI4eYDcwEYQ==
dependencies:
"@ogre-tools/fp" "^9.0.0"
"@ogre-tools/fp" "^9.0.1"
lodash "^4.17.21"
"@panva/asn1.js@^1.0.0":