|
| 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 | +} |
0 commit comments