Skip to content

Commit 429aba7

Browse files
committed
fix: Configure Jest to run snapshot tests properly
- Add separate jest.snapshot.config.js for snapshot tests - Configure module mappings for pyright-internal dependencies - Disable TypeScript diagnostics in Jest to avoid compilation errors - Ensure build runs before snapshot tests in GitHub workflow - Clean up unused run-tests.js file
1 parent 42a32be commit 429aba7

4 files changed

Lines changed: 32 additions & 24 deletions

File tree

.github/workflows/scip-snapshot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ jobs:
4141
exit 1
4242
fi
4343
- run: npm install
44-
- run: cd ./packages/pyright-scip/ && npm install
44+
- run: cd ./packages/pyright-scip/ && npm install && npm run build
4545
- run: python --version
4646
- run: cd ./packages/pyright-scip/ && npm run check-snapshots
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* jest.snapshot.config.js
3+
*
4+
* Configuration for snapshot tests that need to import pyright-internal.
5+
*/
6+
7+
const { pathsToModuleNameMapper } = require('ts-jest');
8+
const { compilerOptions } = require('./tsconfig');
9+
10+
module.exports = {
11+
testEnvironment: 'node',
12+
roots: ['<rootDir>/test/'],
13+
transform: {
14+
'^.+\\.tsx?$': ['ts-jest', {
15+
tsconfig: 'tsconfig.test.json',
16+
isolatedModules: true,
17+
diagnostics: false,
18+
}],
19+
},
20+
testMatch: ['**/test/test-*.ts'],
21+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
22+
moduleNameMapper: {
23+
...pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>' }),
24+
'^typescript-char$': '<rootDir>/../pyright-internal/node_modules/.pnpm/typescript-char@0.0.0/node_modules/typescript-char',
25+
'^vscode-uri$': '<rootDir>/../pyright-internal/node_modules/.pnpm/vscode-uri@3.1.0/node_modules/vscode-uri',
26+
'^vscode-languageserver-protocol$': '<rootDir>/../pyright-internal/node_modules/.pnpm/vscode-languageserver-protocol@3.17.3/node_modules/vscode-languageserver-protocol',
27+
'^vscode-languageserver-types$': '<rootDir>/../pyright-internal/node_modules/.pnpm/vscode-languageserver-types@3.17.3/node_modules/vscode-languageserver-types',
28+
},
29+
};

packages/pyright-scip/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"build-agent": "webpack --mode development",
99
"clean": "shx rm -rf ./dist ./out README.md LICENSE.txt",
1010
"prepack": "npm run clean && shx cp ../../README.md . && shx cp ../../LICENSE.txt . && npm run build",
11-
"check-snapshots": "node ./run-tests.js",
12-
"update-snapshots": "node ./run-tests.js --update",
11+
"check-snapshots": "npm run build && jest --config jest.snapshot.config.js --testPathPattern=test/test-main.ts --forceExit --detectOpenHandles",
12+
"update-snapshots": "npm run build && UPDATE_SNAPSHOTS=true jest --config jest.snapshot.config.js --testPathPattern=test/test-main.ts --forceExit --detectOpenHandles",
1313
"test": "jest --forceExit --detectOpenHandles",
1414
"webpack": "webpack --mode development --progress",
1515
"watch": "webpack --mode development --progress --watch",

packages/pyright-scip/run-tests.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)