Skip to content

Commit e247cd9

Browse files
committed
replace ts-node with tsx to fix tests
1 parent 5499331 commit e247cd9

File tree

4 files changed

+371
-148
lines changed

4 files changed

+371
-148
lines changed

.mocharc.jsonc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// See also: https://github.com/mochajs/mocha/blob/b720ec1b3ca630a90f80311da391b2a0cdfead4e/example/config/.mocharc.js
2+
{
3+
"$schema": "https://json.schemastore.org/mocharc",
4+
"color": false,
5+
"extensions": [
6+
"ts"
7+
],
8+
"import": "tsx",
9+
"spec": ["test/*.ts"]
10+
}

package.json

+3-11
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
"coverage:report": "nyc report --reporter=text-lcov > coverage.lcov",
1212
"watch": "tsc -w",
1313
"prepare": "npm run build",
14-
"mocha": "cross-env TS_NODE_FILES=true mocha",
1514
"lint": "eslint --ext .ts .",
16-
"spec": "tsc && npm run mocha -- test/*.ts",
15+
"spec": "tsc && mocha",
1716
"test": "npm run prewarm-headers && npm run lint && npm run spec",
1817
"prewarm-headers": "node-gyp install --ensure"
1918
},
@@ -78,21 +77,14 @@
7877
"@typescript-eslint/parser": "^6.21.0",
7978
"chai": "^4.2.0",
8079
"chai-as-promised": "^7.1.1",
81-
"cross-env": "^7.0.2",
8280
"electron": "^22.0.0",
8381
"eslint": "^7.7.0",
8482
"eslint-plugin-mocha": "^9.0.0",
85-
"mocha": "^10.8.2",
83+
"mocha": "^11.1.0",
8684
"nyc": "^15.1.0",
87-
"ts-node": "^10.9.2",
85+
"tsx": "^4.19.3",
8886
"typescript": "~5.4.5"
8987
},
90-
"mocha": {
91-
"extensions": [
92-
"ts"
93-
],
94-
"require": "ts-node/register"
95-
},
9688
"nyc": {
9789
"extends": "@istanbuljs/nyc-config-typescript"
9890
}

test/helpers/module-setup.ts

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ export function resetMSVSVersion(): void {
2424
const testModuleTmpPath = fs.mkdtempSync(path.resolve(os.tmpdir(), 'e-r-test-module-'));
2525

2626
export async function resetTestModule(testModulePath: string, installModules = true, fixtureName = 'native-app1'): Promise<void> {
27+
/**
28+
* Remove the `--import` CLI flag added by Mocha so Node doesn't try to load
29+
* `tsx` when we spawn the `node-gyp` worker, which would fail because the
30+
* test fixtures don't include that dependency.
31+
*/
32+
process.execArgv = process.execArgv.filter(item => item !== '--import=tsx');
33+
2734
const oneTimeModulePath = path.resolve(testModuleTmpPath, `${crypto.createHash('SHA1').update(testModulePath).digest('hex')}-${fixtureName}-${installModules}`);
2835
if (!fs.existsSync(oneTimeModulePath)) {
2936
d(`creating test module '%s' in %s`, fixtureName, oneTimeModulePath);

0 commit comments

Comments
 (0)