Skip to content

Commit 305487b

Browse files
committed
fix: all tests are passing
1 parent 8cf89f9 commit 305487b

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

jest.config.js renamed to jest.config.mjs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
const path = require('path');
2-
const { pathsToModuleNameMapper } = require('ts-jest');
3-
const { compilerOptions } = require('./tsconfig');
1+
import path from 'node:path';
2+
import url from 'node:url';
3+
import tsconfigJSON from './tsconfig.json' assert { type: "json" };
44

5-
const moduleNameMapper = pathsToModuleNameMapper(compilerOptions.paths, {
6-
prefix: '<rootDir>/src/',
7-
});
5+
const projectPath = path.dirname(url.fileURLToPath(import.meta.url));
86

97
// Global variables that are shared across the jest worker pool
108
// These variables must be static and serializable
119
const globals = {
1210
// Absolute directory to the project root
13-
projectDir: __dirname,
11+
projectDir: projectPath,
1412
// Absolute directory to the test root
15-
testDir: path.join(__dirname, 'tests'),
13+
testDir: path.join(projectPath, 'tests'),
1614
// Default asynchronous test timeout
1715
defaultTimeout: 20000,
1816
// Timeouts rely on setTimeout which takes 32 bit numbers
@@ -24,7 +22,7 @@ const globals = {
2422
// They can however receive the process environment
2523
// Use `process.env` to set variables
2624

27-
module.exports = {
25+
const config = {
2826
testEnvironment: 'node',
2927
verbose: true,
3028
collectCoverage: false,
@@ -40,10 +38,10 @@ module.exports = {
4038
parser: {
4139
syntax: "typescript",
4240
tsx: true,
43-
decorators: compilerOptions.experimentalDecorators,
41+
decorators: tsconfigJSON.compilerOptions.experimentalDecorators,
4442
dynamicImport: true,
4543
},
46-
target: compilerOptions.target.toLowerCase(),
44+
target: tsconfigJSON.compilerOptions.target.toLowerCase(),
4745
keepClassNames: true,
4846
},
4947
}
@@ -77,5 +75,10 @@ module.exports = {
7775
'jest-extended/all',
7876
'<rootDir>/tests/setupAfterEnv.ts'
7977
],
80-
moduleNameMapper: moduleNameMapper,
78+
moduleNameMapper: {
79+
"^(\\.{1,2}/.*)\\.js$": "$1",
80+
},
81+
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],
8182
};
83+
84+
export default config;

scripts/test.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
23
import os from 'node:os';
34
import path from 'node:path';
45
import url from 'node:url';
@@ -12,7 +13,8 @@ const projectPath = path.dirname(
1213
const platform = os.platform();
1314

1415
/* eslint-disable no-console */
15-
async function main() {
16+
async function main(argv = process.argv) {
17+
argv = argv.slice(2);
1618
const tscArgs = [`-p`, path.join(projectPath, 'tsconfig.build.json')];
1719
console.error('Running tsc:');
1820
console.error(['tsc', ...tscArgs].join(' '));
@@ -22,7 +24,7 @@ async function main() {
2224
encoding: 'utf-8',
2325
shell: platform === 'win32' ? true : false,
2426
});
25-
const jestArgs = [];
27+
const jestArgs = [...argv];
2628
console.error('Running jest:');
2729
console.error(['jest', ...jestArgs].join(' '));
2830
childProcess.execFileSync('jest', jestArgs, {
@@ -36,6 +38,7 @@ async function main() {
3638
shell: platform === 'win32' ? true : false,
3739
});
3840
}
41+
/* eslint-enable no-console */
3942

4043
if (import.meta.url.startsWith('file:')) {
4144
const modulePath = url.fileURLToPath(import.meta.url);

tests/setupAfterEnv.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { jest } from '@jest/globals';
2+
13
// Default timeout per test
24
// some tests may take longer in which case you should specify the timeout
35
// explicitly for each test by using the third parameter of test function

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
"./tests/**/*",
3131
"./scripts/**/*",
3232
"./benches/**/*"
33-
],
33+
]
3434
}

0 commit comments

Comments
 (0)