Skip to content

Commit 611adc2

Browse files
committed
ensure tests are forced to install and use most recent ts-node tarball and cannot accidentally use project-root nor outdated tarball
1 parent 3f21c31 commit 611adc2

File tree

4 files changed

+67
-15
lines changed

4 files changed

+67
-15
lines changed

ava.config.cjs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const expect = require('expect');
2+
const { createRequire } = require('module');
3+
4+
module.exports = {
5+
files: ['dist/test/**/*.spec.js'],
6+
failWithoutAssertions: false,
7+
environmentVariables: {
8+
ts_node_install_lock: `id-${Math.floor(Math.random() * 10e9)}`,
9+
// Force jest expect() errors to generate colorized strings, makes output more readable.
10+
// Delete the env var within ava processes via `require` option below.
11+
// This avoids passing it to spawned processes under test, which would negatively affect
12+
// their behavior.
13+
FORCE_COLOR: '3',
14+
},
15+
require: ['./src/test/remove-env-var-force-color.js'],
16+
timeout: '300s',
17+
concurrency: 1,
18+
};
19+
20+
{
21+
/*
22+
* Tests *must* install and use our most recent ts-node tarball.
23+
* We must prevent them from accidentally require-ing a different version of
24+
* ts-node, from either node_modules or tests/node_modules
25+
*/
26+
27+
const { rmSync, existsSync } = require('fs-extra');
28+
const { resolve } = require('path');
29+
30+
remove(resolve(__dirname, 'node_modules/ts-node'));
31+
remove(resolve(__dirname, 'tests/node_modules/ts-node'));
32+
33+
// Prove that we did it correctly
34+
expect(() => {createRequire(resolve(__dirname, 'tests/foo.js')).resolve('ts-node')}).toThrow();
35+
36+
function remove(p) {
37+
if(existsSync(p)) rmSync(p, {recursive: true})
38+
}
39+
}

ava.config.js

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

package-lock.json

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"axios": "^0.21.1",
128128
"chai": "^4.0.1",
129129
"expect": "^27.0.2",
130+
"fs-extra": "^10.0.1",
130131
"get-stream": "^6.0.0",
131132
"lodash": "^4.17.15",
132133
"ntypescript": "^1.201507091536.1",

0 commit comments

Comments
 (0)