Skip to content

Commit

Permalink
replace ts-node with tsx to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erikian committed Feb 24, 2025
1 parent 5499331 commit e247cd9
Show file tree
Hide file tree
Showing 4 changed files with 371 additions and 148 deletions.
10 changes: 10 additions & 0 deletions .mocharc.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// See also: https://github.com/mochajs/mocha/blob/b720ec1b3ca630a90f80311da391b2a0cdfead4e/example/config/.mocharc.js
{
"$schema": "https://json.schemastore.org/mocharc",
"color": false,
"extensions": [
"ts"
],
"import": "tsx",
"spec": ["test/*.ts"]
}
14 changes: 3 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"coverage:report": "nyc report --reporter=text-lcov > coverage.lcov",
"watch": "tsc -w",
"prepare": "npm run build",
"mocha": "cross-env TS_NODE_FILES=true mocha",
"lint": "eslint --ext .ts .",
"spec": "tsc && npm run mocha -- test/*.ts",
"spec": "tsc && mocha",
"test": "npm run prewarm-headers && npm run lint && npm run spec",
"prewarm-headers": "node-gyp install --ensure"
},
Expand Down Expand Up @@ -78,21 +77,14 @@
"@typescript-eslint/parser": "^6.21.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.2",
"electron": "^22.0.0",
"eslint": "^7.7.0",
"eslint-plugin-mocha": "^9.0.0",
"mocha": "^10.8.2",
"mocha": "^11.1.0",
"nyc": "^15.1.0",
"ts-node": "^10.9.2",
"tsx": "^4.19.3",
"typescript": "~5.4.5"
},
"mocha": {
"extensions": [
"ts"
],
"require": "ts-node/register"
},
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript"
}
Expand Down
7 changes: 7 additions & 0 deletions test/helpers/module-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export function resetMSVSVersion(): void {
const testModuleTmpPath = fs.mkdtempSync(path.resolve(os.tmpdir(), 'e-r-test-module-'));

export async function resetTestModule(testModulePath: string, installModules = true, fixtureName = 'native-app1'): Promise<void> {
/**
* Remove the `--import` CLI flag added by Mocha so Node doesn't try to load
* `tsx` when we spawn the `node-gyp` worker, which would fail because the
* test fixtures don't include that dependency.
*/
process.execArgv = process.execArgv.filter(item => item !== '--import=tsx');

const oneTimeModulePath = path.resolve(testModuleTmpPath, `${crypto.createHash('SHA1').update(testModulePath).digest('hex')}-${fixtureName}-${installModules}`);
if (!fs.existsSync(oneTimeModulePath)) {
d(`creating test module '%s' in %s`, fixtureName, oneTimeModulePath);
Expand Down
Loading

0 comments on commit e247cd9

Please sign in to comment.