Skip to content

Commit 08d6cd7

Browse files
Abby010aryanjassal
authored andcommitted
chore: making tests randomized
chore: addressed PR comments
1 parent 0d73101 commit 08d6cd7

17 files changed

+2466
-2412
lines changed

jest.config.mjs

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
import path from 'node:path';
22
import url from 'node:url';
3-
import tsconfigJSON from './tsconfig.json' assert { type: "json" };
3+
import tsconfigJSON from './tsconfig.json' assert { type: 'json' };
44

55
const projectPath = path.dirname(url.fileURLToPath(import.meta.url));
66

7-
// Global variables that are shared across the jest worker pool
8-
// These variables must be static and serializable
97
const globals = {
10-
// Absolute directory to the project root
118
projectDir: projectPath,
12-
// Absolute directory to the test root
139
testDir: path.join(projectPath, 'tests'),
14-
// Default asynchronous test timeout
1510
defaultTimeout: 20000,
16-
// Timeouts rely on setTimeout which takes 32 bit numbers
1711
maxTimeout: Math.pow(2, 31) - 1,
1812
};
1913

20-
// The `globalSetup` and `globalTeardown` cannot access the `globals`
21-
// They run in their own process context
22-
// They can however receive the process environment
23-
// Use `process.env` to set variables
24-
2514
const config = {
2615
testEnvironment: 'node',
2716
verbose: true,
@@ -30,55 +19,61 @@ const config = {
3019
coverageDirectory: '<rootDir>/tmp/coverage',
3120
roots: ['<rootDir>/tests'],
3221
testMatch: ['**/?(*.)+(spec|test|unit.test).+(ts|tsx|js|jsx)'],
22+
23+
// Use SWC to transpile TS/JS/TSX
3324
transform: {
34-
"^.+\\.(t|j)sx?$": [
35-
"@swc/jest",
25+
'^.+\\.(t|j)sx?$': [
26+
'@swc/jest',
3627
{
3728
jsc: {
3829
parser: {
39-
syntax: "typescript",
30+
syntax: 'typescript',
4031
tsx: true,
4132
decorators: tsconfigJSON.compilerOptions.experimentalDecorators,
4233
dynamicImport: true,
4334
},
4435
target: tsconfigJSON.compilerOptions.target.toLowerCase(),
4536
keepClassNames: true,
4637
},
47-
}
38+
module: {
39+
type: 'es6', // Crucial for ESM-style imports
40+
},
41+
},
4842
],
4943
},
44+
45+
// Required to treat TS/TSX as ESM in Jest
46+
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],
47+
48+
moduleNameMapper: {
49+
// Remove `.js` extension from relative imports in source like `./foo.js` → `./foo`
50+
'^(\\.{1,2}/.*)\\.js$': '$1',
51+
},
52+
5053
reporters: [
5154
'default',
52-
['jest-junit', {
53-
outputDirectory: '<rootDir>/tmp/junit',
54-
classNameTemplate: '{classname}',
55-
ancestorSeparator: ' > ',
56-
titleTemplate: '{title}',
57-
addFileAttribute: 'true',
58-
reportTestSuiteErrors: 'true',
59-
}],
55+
[
56+
'jest-junit',
57+
{
58+
outputDirectory: '<rootDir>/tmp/junit',
59+
classNameTemplate: '{classname}',
60+
ancestorSeparator: ' > ',
61+
titleTemplate: '{title}',
62+
addFileAttribute: 'true',
63+
reportTestSuiteErrors: 'true',
64+
},
65+
],
6066
],
67+
6168
collectCoverageFrom: ['src/**/*.{ts,tsx,js,jsx}', '!src/**/*.d.ts'],
6269
coverageReporters: ['text', 'cobertura'],
70+
6371
globals,
64-
// Global setup script executed once before all test files
72+
6573
globalSetup: '<rootDir>/tests/globalSetup.ts',
66-
// Global teardown script executed once after all test files
6774
globalTeardown: '<rootDir>/tests/globalTeardown.ts',
68-
// Setup files are executed before each test file
69-
// Can access globals
7075
setupFiles: ['<rootDir>/tests/setup.ts'],
71-
// Setup files after env are executed before each test file
72-
// after the jest test environment is installed
73-
// Can access globals
74-
setupFilesAfterEnv: [
75-
'jest-extended/all',
76-
'<rootDir>/tests/setupAfterEnv.ts'
77-
],
78-
moduleNameMapper: {
79-
"^(\\.{1,2}/.*)\\.js$": "$1",
80-
},
81-
extensionsToTreatAsEsm: ['.ts', '.tsx', '.mts'],
76+
setupFilesAfterEnv: ['jest-extended/all', '<rootDir>/tests/setupAfterEnv.ts'],
8277
};
8378

8479
export default config;

0 commit comments

Comments
 (0)