aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-01-27 18:26:21 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-02-08 21:43:18 +0100
commitbfc1f4d55d02553f761fbc9acc5ed15103455149 (patch)
treecb1650750c2ff1587f7cd0fd215d2179822568ae
parentrefactor: Extract main window hardening (diff)
downloadsophie-bfc1f4d55d02553f761fbc9acc5ed15103455149.tar.gz
sophie-bfc1f4d55d02553f761fbc9acc5ed15103455149.tar.zst
sophie-bfc1f4d55d02553f761fbc9acc5ed15103455149.zip
build: Add test-utils package
Added as a common devDependency, this lets us handle test utility code from one place. For now, the main reason for its existence is the workaround code for importing jest-each from ESM. Signed-off-by: Kristóf Marussy <kristof@marussy.com>
-rw-r--r--package.json3
-rw-r--r--packages/main/package.json2
-rw-r--r--packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.spec.ts6
-rw-r--r--packages/main/tsconfig.json3
-rw-r--r--packages/test-utils/.eslintrc.cjs6
-rw-r--r--packages/test-utils/package.json17
-rw-r--r--packages/test-utils/src/each.ts27
-rw-r--r--packages/test-utils/src/index.ts22
-rw-r--r--packages/test-utils/tsconfig.build.json10
-rw-r--r--packages/test-utils/tsconfig.json12
-rw-r--r--yarn.lock12
11 files changed, 112 insertions, 8 deletions
diff --git a/package.json b/package.json
index 6cad5f8..5350fcf 100644
--- a/package.json
+++ b/package.json
@@ -48,7 +48,8 @@
48 "service-inject": "yarn workspace @sophie/service-inject", 48 "service-inject": "yarn workspace @sophie/service-inject",
49 "service-preload": "yarn workspace @sophie/service-preload", 49 "service-preload": "yarn workspace @sophie/service-preload",
50 "service-shared": "yarn workspace @sophie/service-shared", 50 "service-shared": "yarn workspace @sophie/service-shared",
51 "shared": "yarn workspace @sophie/shared" 51 "shared": "yarn workspace @sophie/shared",
52 "test-utils": "yarn workspace @sophie/test-utils"
52 }, 53 },
53 "workspaces": [ 54 "workspaces": [
54 "packages/*" 55 "packages/*"
diff --git a/packages/main/package.json b/packages/main/package.json
index ea10b84..4f4a6cb 100644
--- a/packages/main/package.json
+++ b/packages/main/package.json
@@ -27,6 +27,7 @@
27 }, 27 },
28 "devDependencies": { 28 "devDependencies": {
29 "@jest/globals": "^27.4.6", 29 "@jest/globals": "^27.4.6",
30 "@sophie/test-utils": "workspace:*",
30 "@types/deep-equal": "^1.0.1", 31 "@types/deep-equal": "^1.0.1",
31 "@types/electron-devtools-installer": "^2.2.1", 32 "@types/electron-devtools-installer": "^2.2.1",
32 "@types/lodash-es": "^4.17.5", 33 "@types/lodash-es": "^4.17.5",
@@ -38,7 +39,6 @@
38 "esbuild": "^0.14.14", 39 "esbuild": "^0.14.14",
39 "git-repo-info": "^2.1.1", 40 "git-repo-info": "^2.1.1",
40 "jest": "^27.4.7", 41 "jest": "^27.4.7",
41 "jest-each": "^27.4.6",
42 "jest-mock": "^27.4.6", 42 "jest-mock": "^27.4.6",
43 "source-map-support": "^0.5.21" 43 "source-map-support": "^0.5.21"
44 } 44 }
diff --git a/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.spec.ts b/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.spec.ts
index d045e54..e7e9d71 100644
--- a/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.spec.ts
+++ b/packages/main/src/infrastructure/resources/impl/__tests__/getDistResources.spec.ts
@@ -20,15 +20,11 @@
20 20
21import os from 'node:os'; 21import os from 'node:os';
22 22
23import eachModule from 'jest-each'; 23import { each } from '@sophie/test-utils';
24 24
25import Resources from '../../Resources'; 25import Resources from '../../Resources';
26import getDistResources from '../getDistResources'; 26import getDistResources from '../getDistResources';
27 27
28// Workaround for jest ESM loader incorrectly wrapping the import in another layer of `default`.
29const each =
30 (eachModule as Partial<typeof import('jest-each')>).default ?? eachModule;
31
32const defaultDevServerURL = 'http://localhost:3000/'; 28const defaultDevServerURL = 'http://localhost:3000/';
33 29
34const [ 30const [
diff --git a/packages/main/tsconfig.json b/packages/main/tsconfig.json
index dad597d..e18e7d3 100644
--- a/packages/main/tsconfig.json
+++ b/packages/main/tsconfig.json
@@ -10,6 +10,9 @@
10 }, 10 },
11 { 11 {
12 "path": "../shared/tsconfig.build.json" 12 "path": "../shared/tsconfig.build.json"
13 },
14 {
15 "path": "../test-utils/tsconfig.build.json"
13 } 16 }
14 ], 17 ],
15 "include": [ 18 "include": [
diff --git a/packages/test-utils/.eslintrc.cjs b/packages/test-utils/.eslintrc.cjs
new file mode 100644
index 0000000..548ea34
--- /dev/null
+++ b/packages/test-utils/.eslintrc.cjs
@@ -0,0 +1,6 @@
1module.exports = {
2 env: {
3 node: true,
4 browser: false,
5 },
6};
diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json
new file mode 100644
index 0000000..9270af2
--- /dev/null
+++ b/packages/test-utils/package.json
@@ -0,0 +1,17 @@
1{
2 "name": "@sophie/test-utils",
3 "version": "0.1.0",
4 "private": true,
5 "sideEffects": false,
6 "type": "module",
7 "types": "dist/index.d.ts",
8 "scripts": {
9 "typecheck:workspace": "yarn g:typecheck",
10 "types": "yarn g:types"
11 },
12 "dependencies": {
13 "@types/jest": "^27.4.0",
14 "jest": "^27.4.7",
15 "jest-each": "^27.4.6"
16 }
17}
diff --git a/packages/test-utils/src/each.ts b/packages/test-utils/src/each.ts
new file mode 100644
index 0000000..c5271ae
--- /dev/null
+++ b/packages/test-utils/src/each.ts
@@ -0,0 +1,27 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import eachModule from 'jest-each';
22
23// Workaround for jest ESM loader incorrectly wrapping the import in another layer of `default`.
24const each =
25 (eachModule as Partial<typeof import('jest-each')>).default ?? eachModule;
26
27export default each;
diff --git a/packages/test-utils/src/index.ts b/packages/test-utils/src/index.ts
new file mode 100644
index 0000000..5de84f1
--- /dev/null
+++ b/packages/test-utils/src/index.ts
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21// eslint-disable-next-line import/prefer-default-export -- More exports will be added here.
22export { default as each } from './each';
diff --git a/packages/test-utils/tsconfig.build.json b/packages/test-utils/tsconfig.build.json
new file mode 100644
index 0000000..d300514
--- /dev/null
+++ b/packages/test-utils/tsconfig.build.json
@@ -0,0 +1,10 @@
1{
2 "extends": "../../config/tsconfig.base.json",
3 "compilerOptions": {
4 "composite": true,
5 "declarationDir": "dist",
6 "emitDeclarationOnly": true,
7 "rootDir": "src"
8 },
9 "include": ["src/**/*.ts"]
10}
diff --git a/packages/test-utils/tsconfig.json b/packages/test-utils/tsconfig.json
new file mode 100644
index 0000000..d01eb81
--- /dev/null
+++ b/packages/test-utils/tsconfig.json
@@ -0,0 +1,12 @@
1{
2 "extends": "./tsconfig.build.json",
3 "compilerOptions": {
4 "composite": false,
5 "emitDeclarationOnly": false,
6 "declarationDir": null,
7 "noEmit": true,
8 "rootDir": null,
9 "types": ["@types/jest", "node"]
10 },
11 "include": ["src/**/*.ts", ".eslintrc.cjs"]
12}
diff --git a/yarn.lock b/yarn.lock
index a22d873..85f7b61 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1237,6 +1237,7 @@ __metadata:
1237 "@jest/globals": ^27.4.6 1237 "@jest/globals": ^27.4.6
1238 "@sophie/service-shared": "workspace:*" 1238 "@sophie/service-shared": "workspace:*"
1239 "@sophie/shared": "workspace:*" 1239 "@sophie/shared": "workspace:*"
1240 "@sophie/test-utils": "workspace:*"
1240 "@types/deep-equal": ^1.0.1 1241 "@types/deep-equal": ^1.0.1
1241 "@types/electron-devtools-installer": ^2.2.1 1242 "@types/electron-devtools-installer": ^2.2.1
1242 "@types/lodash-es": ^4.17.5 1243 "@types/lodash-es": ^4.17.5
@@ -1252,7 +1253,6 @@ __metadata:
1252 fs-extra: ^10.0.0 1253 fs-extra: ^10.0.0
1253 git-repo-info: ^2.1.1 1254 git-repo-info: ^2.1.1
1254 jest: ^27.4.7 1255 jest: ^27.4.7
1255 jest-each: ^27.4.6
1256 jest-mock: ^27.4.6 1256 jest-mock: ^27.4.6
1257 json5: ^2.2.0 1257 json5: ^2.2.0
1258 lodash-es: ^4.17.21 1258 lodash-es: ^4.17.21
@@ -1353,6 +1353,16 @@ __metadata:
1353 languageName: unknown 1353 languageName: unknown
1354 linkType: soft 1354 linkType: soft
1355 1355
1356"@sophie/test-utils@workspace:*, @sophie/test-utils@workspace:packages/test-utils":
1357 version: 0.0.0-use.local
1358 resolution: "@sophie/test-utils@workspace:packages/test-utils"
1359 dependencies:
1360 "@types/jest": ^27.4.0
1361 jest: ^27.4.7
1362 jest-each: ^27.4.6
1363 languageName: unknown
1364 linkType: soft
1365
1356"@szmarczak/http-timer@npm:^1.1.2": 1366"@szmarczak/http-timer@npm:^1.1.2":
1357 version: 1.1.2 1367 version: 1.1.2
1358 resolution: "@szmarczak/http-timer@npm:1.1.2" 1368 resolution: "@szmarczak/http-timer@npm:1.1.2"