Skip to content

Commit 3a8a3fc

Browse files
authored
Merge pull request #670 from rajbos/rajbos/fix-chat-leakage
Stabilize VS Code extension npm test runs
2 parents 66f5ed5 + ddced8d commit 3a8a3fc

4 files changed

Lines changed: 65 additions & 6 deletions

File tree

scripts/prepare-test-output.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const repoRoot = path.resolve(__dirname, '..');
5+
const extensionRoot = path.join(repoRoot, 'vscode-extension');
6+
const outDir = path.join(extensionRoot, 'out');
7+
const outTestDir = path.join(outDir, 'test');
8+
const packageJsonPath = path.join(extensionRoot, 'package.json');
9+
10+
fs.mkdirSync(outTestDir, { recursive: true });
11+
fs.cpSync(packageJsonPath, path.join(outDir, 'package.json'), { force: true });
12+
fs.cpSync(packageJsonPath, path.join(outTestDir, 'package.json'), { force: true });

scripts/run-node-unit-tests.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const { spawnSync } = require('child_process');
4+
5+
const repoRoot = path.resolve(__dirname, '..');
6+
const extensionRoot = path.join(repoRoot, 'vscode-extension');
7+
const outUnitDir = path.join(extensionRoot, 'out', 'test', 'unit');
8+
const shimPath = path.join(outUnitDir, 'vscode-shim-register.js');
9+
10+
const testFiles = fs.readdirSync(outUnitDir)
11+
.filter((name) => name.endsWith('.test.js'))
12+
.sort((a, b) => a.localeCompare(b));
13+
14+
for (const fileName of testFiles) {
15+
const testFilePath = path.join(outUnitDir, fileName);
16+
const result = spawnSync(
17+
process.execPath,
18+
['--require', shimPath, '--test', '--test-force-exit', testFilePath],
19+
{
20+
cwd: extensionRoot,
21+
encoding: 'utf8',
22+
},
23+
);
24+
25+
if (result.status !== 0) {
26+
if (result.stdout) {
27+
process.stdout.write(result.stdout);
28+
}
29+
30+
if (result.stderr) {
31+
process.stderr.write(result.stderr);
32+
}
33+
34+
process.exit(result.status ?? 1);
35+
}
36+
37+
if (result.error) {
38+
throw result.error;
39+
}
40+
41+
process.stdout.write(`PASS ${fileName}\n`);
42+
}

vscode-extension/.npmrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ legacy-peer-deps=false
1717
# Save exact versions (no ^ or ~ prefixes) when adding new dependencies
1818
# This ensures maximum reproducibility
1919
save-exact=true
20+
21+
# Disable npm progress UI/funding prompts for more stable non-interactive runs
22+
progress=false
23+
fund=false

vscode-extension/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -504,21 +504,22 @@
504504
},
505505
"scripts": {
506506
"vscode:prepublish": "npm run package",
507-
"compile": "npm run check-types && npm run lint && node esbuild.js",
507+
"compile": "tsc --noEmit && eslint src && node esbuild.js",
508508
"watch": "npm-run-all -p watch:*",
509509
"watch:esbuild": "node esbuild.js --watch",
510510
"watch:tsc": "tsc --noEmit --watch --project tsconfig.json",
511-
"package": "npm run check-types && npm run lint && node esbuild.js --production",
512-
"compile-tests": "node -e \"const fs = require('fs'); fs.mkdirSync('out/test', { recursive: true }); fs.cpSync('package.json', 'out/package.json', { force: true }); fs.cpSync('package.json', 'out/test/package.json', { force: true });\" && tsc -p tsconfig.tests.json",
511+
"package": "tsc --noEmit && eslint src && node esbuild.js --production",
512+
"prepare-test-output": "node ../scripts/prepare-test-output.js",
513+
"compile-tests": "node ../scripts/prepare-test-output.js && tsc -p tsconfig.tests.json",
513514
"watch-tests": "tsc -p tsconfig.tests.json -w",
514-
"pretest": "npm run compile && npm run compile-tests && npm run lint",
515+
"pretest": "tsc --noEmit && eslint src && node esbuild.js && node ../scripts/prepare-test-output.js && tsc -p tsconfig.tests.json",
515516
"check-types": "tsc --noEmit",
516517
"lint": "eslint src",
517518
"lint:css": "stylelint \"src/webview/**/*.css\"",
518519
"lint:json": "node ../scripts/validate-json.js",
519520
"test": "vscode-test",
520-
"test:node": "npm run compile-tests && node --require ./out/test/unit/vscode-shim-register.js --test --test-force-exit out/test/unit/*.test.js",
521-
"test:coverage": "npm run compile-tests && node --require ./out/test/unit/vscode-shim-register.js --experimental-test-coverage --test --test-force-exit --test-coverage-lines=65 --test-coverage-functions=70 --test-coverage-branches=60 --test-coverage-include=out/src/backend/**/*.js --test-coverage-include=out/src/utils/**/*.js --test-coverage-include=out/src/usageAnalysis.js --test-coverage-include=out/src/tokenEstimation.js --test-coverage-include=out/src/maturityScoring.js out/test/unit/*.test.js",
521+
"test:node": "node ../scripts/prepare-test-output.js && tsc -p tsconfig.tests.json && node ../scripts/run-node-unit-tests.js",
522+
"test:coverage": "node ../scripts/prepare-test-output.js && tsc -p tsconfig.tests.json && node --require ./out/test/unit/vscode-shim-register.js --experimental-test-coverage --test --test-force-exit --test-coverage-lines=65 --test-coverage-functions=70 --test-coverage-branches=60 --test-coverage-include=out/src/backend/**/*.js --test-coverage-include=out/src/utils/**/*.js --test-coverage-include=out/src/usageAnalysis.js --test-coverage-include=out/src/tokenEstimation.js --test-coverage-include=out/src/maturityScoring.js out/test/unit/*.test.js",
522523
"test:coverage:ci": "node --require ./out/test/unit/vscode-shim-register.js --experimental-test-coverage --test --test-force-exit --test-coverage-include=out/src/backend/**/*.js --test-coverage-include=out/src/utils/**/*.js --test-coverage-include=out/src/usageAnalysis.js --test-coverage-include=out/src/tokenEstimation.js --test-coverage-include=out/src/maturityScoring.js out/test/unit/*.test.js",
523524
"test:mutation": "npm run compile-tests && npx stryker run",
524525
"pre-release": "node ../scripts/pre-release.js",

0 commit comments

Comments
 (0)