From bfc1f4d55d02553f761fbc9acc5ed15103455149 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Thu, 27 Jan 2022 18:26:21 +0100 Subject: build: Add test-utils package MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- package.json | 3 ++- packages/main/package.json | 2 +- .../impl/__tests__/getDistResources.spec.ts | 6 +---- packages/main/tsconfig.json | 3 +++ packages/test-utils/.eslintrc.cjs | 6 +++++ packages/test-utils/package.json | 17 ++++++++++++++ packages/test-utils/src/each.ts | 27 ++++++++++++++++++++++ packages/test-utils/src/index.ts | 22 ++++++++++++++++++ packages/test-utils/tsconfig.build.json | 10 ++++++++ packages/test-utils/tsconfig.json | 12 ++++++++++ yarn.lock | 12 +++++++++- 11 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 packages/test-utils/.eslintrc.cjs create mode 100644 packages/test-utils/package.json create mode 100644 packages/test-utils/src/each.ts create mode 100644 packages/test-utils/src/index.ts create mode 100644 packages/test-utils/tsconfig.build.json create mode 100644 packages/test-utils/tsconfig.json diff --git a/package.json b/package.json index 6cad5f8..5350fcf 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,8 @@ "service-inject": "yarn workspace @sophie/service-inject", "service-preload": "yarn workspace @sophie/service-preload", "service-shared": "yarn workspace @sophie/service-shared", - "shared": "yarn workspace @sophie/shared" + "shared": "yarn workspace @sophie/shared", + "test-utils": "yarn workspace @sophie/test-utils" }, "workspaces": [ "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 @@ }, "devDependencies": { "@jest/globals": "^27.4.6", + "@sophie/test-utils": "workspace:*", "@types/deep-equal": "^1.0.1", "@types/electron-devtools-installer": "^2.2.1", "@types/lodash-es": "^4.17.5", @@ -38,7 +39,6 @@ "esbuild": "^0.14.14", "git-repo-info": "^2.1.1", "jest": "^27.4.7", - "jest-each": "^27.4.6", "jest-mock": "^27.4.6", "source-map-support": "^0.5.21" } 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 @@ import os from 'node:os'; -import eachModule from 'jest-each'; +import { each } from '@sophie/test-utils'; import Resources from '../../Resources'; import getDistResources from '../getDistResources'; -// Workaround for jest ESM loader incorrectly wrapping the import in another layer of `default`. -const each = - (eachModule as Partial).default ?? eachModule; - const defaultDevServerURL = 'http://localhost:3000/'; const [ 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 @@ }, { "path": "../shared/tsconfig.build.json" + }, + { + "path": "../test-utils/tsconfig.build.json" } ], "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 @@ +module.exports = { + env: { + node: true, + browser: false, + }, +}; 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 @@ +{ + "name": "@sophie/test-utils", + "version": "0.1.0", + "private": true, + "sideEffects": false, + "type": "module", + "types": "dist/index.d.ts", + "scripts": { + "typecheck:workspace": "yarn g:typecheck", + "types": "yarn g:types" + }, + "dependencies": { + "@types/jest": "^27.4.0", + "jest": "^27.4.7", + "jest-each": "^27.4.6" + } +} 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 @@ +/* + * Copyright (C) 2022 Kristóf Marussy + * + * This file is part of Sophie. + * + * Sophie is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import eachModule from 'jest-each'; + +// Workaround for jest ESM loader incorrectly wrapping the import in another layer of `default`. +const each = + (eachModule as Partial).default ?? eachModule; + +export 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 @@ +/* + * Copyright (C) 2022 Kristóf Marussy + * + * This file is part of Sophie. + * + * Sophie is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: AGPL-3.0-only + */ + +// eslint-disable-next-line import/prefer-default-export -- More exports will be added here. +export { 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 @@ +{ + "extends": "../../config/tsconfig.base.json", + "compilerOptions": { + "composite": true, + "declarationDir": "dist", + "emitDeclarationOnly": true, + "rootDir": "src" + }, + "include": ["src/**/*.ts"] +} 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 @@ +{ + "extends": "./tsconfig.build.json", + "compilerOptions": { + "composite": false, + "emitDeclarationOnly": false, + "declarationDir": null, + "noEmit": true, + "rootDir": null, + "types": ["@types/jest", "node"] + }, + "include": ["src/**/*.ts", ".eslintrc.cjs"] +} diff --git a/yarn.lock b/yarn.lock index a22d873..85f7b61 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1237,6 +1237,7 @@ __metadata: "@jest/globals": ^27.4.6 "@sophie/service-shared": "workspace:*" "@sophie/shared": "workspace:*" + "@sophie/test-utils": "workspace:*" "@types/deep-equal": ^1.0.1 "@types/electron-devtools-installer": ^2.2.1 "@types/lodash-es": ^4.17.5 @@ -1252,7 +1253,6 @@ __metadata: fs-extra: ^10.0.0 git-repo-info: ^2.1.1 jest: ^27.4.7 - jest-each: ^27.4.6 jest-mock: ^27.4.6 json5: ^2.2.0 lodash-es: ^4.17.21 @@ -1353,6 +1353,16 @@ __metadata: languageName: unknown linkType: soft +"@sophie/test-utils@workspace:*, @sophie/test-utils@workspace:packages/test-utils": + version: 0.0.0-use.local + resolution: "@sophie/test-utils@workspace:packages/test-utils" + dependencies: + "@types/jest": ^27.4.0 + jest: ^27.4.7 + jest-each: ^27.4.6 + languageName: unknown + linkType: soft + "@szmarczak/http-timer@npm:^1.1.2": version: 1.1.2 resolution: "@szmarczak/http-timer@npm:1.1.2" -- cgit v1.2.3-54-g00ecf