Skip to content

Commit 3725675

Browse files
committed
fix(test): Update Jest configuration and .gitignore
- Add .nvmrc to .gitignore to prevent Node version files from being tracked. - Update Jest configuration to allow transformation of additional modules and fix Haste module naming collisions. - Adjust the Jest setup to ensure consistent test behavior by importing necessary libraries correctly. These changes enhance the testing environment and maintain cleaner project files.
1 parent 5381c5e commit 3725675

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ uncaughtExceptions.log
1111
src/*.json
1212
.idea
1313
test.ts
14-
notes.md
14+
notes.md
15+
.nvmrc

jest.config.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,28 @@ const config: Config = {
99
testTimeout: 100_000,
1010
coverageProvider: 'v8',
1111
moduleDirectories: ['node_modules', 'src'],
12-
preset: 'ts-jest/presets/js-with-ts-esm',
12+
preset: 'ts-jest/presets/default-esm',
1313
setupFilesAfterEnv: ['<rootDir>/test/jest-setup.ts'],
1414
testEnvironment: 'node',
1515
testRegex: ['.*\\.test\\.ts$'],
16-
transformIgnorePatterns: ['node_modules/(?!cli-testing-library)'],
16+
transformIgnorePatterns: [
17+
'node_modules/(?!(cli-testing-library|@clack|cleye)/.*)'
18+
],
1719
transform: {
18-
'^.+\\.(ts|tsx)$': [
20+
'^.+\\.(ts|tsx|js|jsx|mjs)$': [
1921
'ts-jest',
2022
{
2123
diagnostics: false,
2224
useESM: true
2325
}
2426
]
27+
},
28+
// Fix Haste module naming collision
29+
modulePathIgnorePatterns: [
30+
'<rootDir>/test/e2e/prompt-module/data/'
31+
],
32+
moduleNameMapper: {
33+
'^(\\.{1,2}/.*)\\.js$': '$1'
2534
}
2635
};
2736

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"test": "node --no-warnings --experimental-vm-modules $( [ -f ./node_modules/.bin/jest ] && echo ./node_modules/.bin/jest || which jest ) test/unit",
5555
"test:all": "npm run test:unit:docker && npm run test:e2e:docker",
5656
"test:docker-build": "docker build -t oco-test -f test/Dockerfile .",
57-
"test:unit": "NODE_OPTIONS=--experimental-vm-modules jest test/unit",
57+
"test:unit": "rimraf /tmp/jest_rs && NODE_OPTIONS=--experimental-vm-modules jest test/unit",
5858
"test:unit:docker": "npm run test:docker-build && DOCKER_CONTENT_TRUST=0 docker run --rm oco-test npm run test:unit",
5959
"test:e2e": "npm run test:e2e:setup && jest test/e2e",
6060
"test:e2e:setup": "sh test/e2e/setup.sh",
@@ -108,4 +108,4 @@
108108
"ajv": "^8.17.1",
109109
"whatwg-url": "^14.0.0"
110110
}
111-
}
111+
}

test/jest-setup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import 'cli-testing-library/extend-expect'
2-
import { configure } from 'cli-testing-library'
31
import { jest } from '@jest/globals';
2+
import 'cli-testing-library/extend-expect';
3+
import { configure } from 'cli-testing-library';
44

55
global.jest = jest;
66

77
/**
88
* Adjusted the wait time for waitFor/findByText to 2000ms, because the default 1000ms makes the test results flaky
99
*/
10-
configure({ asyncUtilTimeout: 2000 })
10+
configure({ asyncUtilTimeout: 2000 });

0 commit comments

Comments
 (0)