diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-12-31 01:52:28 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2021-12-31 01:56:30 +0100 |
commit | 7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f (patch) | |
tree | f8c0450a6e1b62f7e7f8470efd375b3659b91b2b /config | |
parent | refactor: Install devtools extensions earlier (diff) | |
download | sophie-7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f.tar.gz sophie-7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f.tar.zst sophie-7108c642f4ff6dc5f0c4d30b8a8960064ff8e90f.zip |
test: Add tests for main package
- Changed jest to run from the root package and reference the packages
as projects. This required moving the base jest config file away from
the project root.
- Module isolation seems to prevent ts-jest from loading the shared
package, so we disabled it for now.
- To better facilitate mocking, services should be split into interfaces
and implementation
- Had to downgrade to chald 4.1.2 as per
https://github.com/chalk/chalk/releases/tag/v5.0.0 at least until
https://github.com/microsoft/TypeScript/issues/46452 is resolved.
Diffstat (limited to 'config')
-rw-r--r-- | config/buildConstants.js (renamed from config/build-common.js) | 13 | ||||
-rw-r--r-- | config/esbuildConfig.js (renamed from config/esbuild-config.js) | 2 | ||||
-rw-r--r-- | config/jest.config.base.js | 26 | ||||
-rw-r--r-- | config/utils.js | 10 |
4 files changed, 40 insertions, 11 deletions
diff --git a/config/build-common.js b/config/buildConstants.js index ff5a218..4952907 100644 --- a/config/build-common.js +++ b/config/buildConstants.js | |||
@@ -1,6 +1,7 @@ | |||
1 | import { readFileSync } from 'fs'; | 1 | import { readFileSync } from 'fs'; |
2 | import { dirname, join } from 'path'; | 2 | import { join } from 'path'; |
3 | import { fileURLToPath } from 'url'; | 3 | |
4 | import { fileURLToDirname } from './utils.js'; | ||
4 | 5 | ||
5 | const thisDir = fileURLToDirname(import.meta.url); | 6 | const thisDir = fileURLToDirname(import.meta.url); |
6 | 7 | ||
@@ -37,11 +38,3 @@ export const chrome = `chrome${chromeVersion}`; | |||
37 | 38 | ||
38 | /** @type {string} */ | 39 | /** @type {string} */ |
39 | export const node = `node${nodeVersion}`; | 40 | export const node = `node${nodeVersion}`; |
40 | |||
41 | /** | ||
42 | * @param {string} url | ||
43 | * @returns {string} | ||
44 | */ | ||
45 | export function fileURLToDirname(url) { | ||
46 | return dirname(fileURLToPath(url)); | ||
47 | } | ||
diff --git a/config/esbuild-config.js b/config/esbuildConfig.js index 5cef85f..05386b1 100644 --- a/config/esbuild-config.js +++ b/config/esbuildConfig.js | |||
@@ -1,4 +1,4 @@ | |||
1 | import { banner } from './build-common.js'; | 1 | import { banner } from './buildConstants.js'; |
2 | 2 | ||
3 | /** @type {string} */ | 3 | /** @type {string} */ |
4 | const mode = process.env.MODE || 'development'; | 4 | const mode = process.env.MODE || 'development'; |
diff --git a/config/jest.config.base.js b/config/jest.config.base.js new file mode 100644 index 0000000..f265c1c --- /dev/null +++ b/config/jest.config.base.js | |||
@@ -0,0 +1,26 @@ | |||
1 | import { join } from 'path'; | ||
2 | |||
3 | import { fileURLToDirname } from './utils.js'; | ||
4 | |||
5 | const dirname = fileURLToDirname(import.meta.url); | ||
6 | |||
7 | /** @type {import('ts-jest').InitialOptionsTsJest} */ | ||
8 | export default { | ||
9 | preset: 'ts-jest/presets/default-esm', | ||
10 | globals: { | ||
11 | 'ts-jest': { | ||
12 | useESM: true, | ||
13 | }, | ||
14 | }, | ||
15 | moduleNameMapper: { | ||
16 | '@sophie/(.+)': join(dirname, '../packages/$1/src/index.ts'), | ||
17 | '^(\\.{1,2}/.*)\\.js$': '$1', | ||
18 | }, | ||
19 | resetMocks: true, | ||
20 | restoreMocks: true, | ||
21 | testEnvironment: 'node', | ||
22 | testPathIgnorePatterns: [ | ||
23 | '/dist/', | ||
24 | '/node_modules/', | ||
25 | ], | ||
26 | }; | ||
diff --git a/config/utils.js b/config/utils.js new file mode 100644 index 0000000..d3e13d9 --- /dev/null +++ b/config/utils.js | |||
@@ -0,0 +1,10 @@ | |||
1 | import { dirname } from 'path'; | ||
2 | import { fileURLToPath } from 'url'; | ||
3 | |||
4 | /** | ||
5 | * @param {string} url | ||
6 | * @returns {string} | ||
7 | */ | ||
8 | export function fileURLToDirname(url) { | ||
9 | return dirname(fileURLToPath(url)); | ||
10 | } | ||