|
1 | 1 | import * as childProcess from 'child_process'; |
2 | 2 | import * as fs from 'fs'; |
3 | | -import * as path from 'path'; |
4 | 3 |
|
5 | 4 | const CURRENT_NODE_VERSION = process.version.replace('v', '').split('.')[0]; |
6 | 5 |
|
@@ -62,42 +61,6 @@ function installLegacyDeps(legacyDeps: string[] = []): void { |
62 | 61 | run(`yarn add --dev --ignore-engines --ignore-scripts --ignore-workspace-root-check ${legacyDeps.join(' ')}`); |
63 | 62 | } |
64 | 63 |
|
65 | | -/** |
66 | | - * Add a tranformer to our jest config, to do the same `const`-to-`var` replacement as our rollup plugin does. |
67 | | - * |
68 | | - * This is needed because Node 8 doesn't like the way we shadow `global` (`const global = getGlobalObject()`). Changing |
69 | | - * it to a `var` solves this by making it redeclarable. |
70 | | - * |
71 | | - */ |
72 | | -function addJestTransformer(): void { |
73 | | - // Though newer `ts-jest` versions support transformers written in TS, the legacy version does not. |
74 | | - run('yarn tsc --skipLibCheck jest/transformers/constReplacer.ts'); |
75 | | - |
76 | | - // Loading the existing Jest config will error out unless the config file has an accompanying types file, so we have |
77 | | - // to create that before we can load it. |
78 | | - run('yarn tsc --allowJs --skipLibCheck --declaration --emitDeclarationOnly jest/jest.config.js'); |
79 | | - // eslint-disable-next-line @typescript-eslint/no-var-requires |
80 | | - const jestConfig = require('../jest/jest.config.js'); |
81 | | - |
82 | | - // Inject the transformer |
83 | | - jestConfig.globals['ts-jest'].astTransformers = ['<rootDir>/../../jest/transformers/constReplacer.js']; |
84 | | - |
85 | | - // When we required the jest config file above, all expressions it contained were evaluated. Specifically, the |
86 | | - // `rootDir: process.cwd()` |
87 | | - // entry was replaced with |
88 | | - // `rootDir: "<hard-coded string result of running `process.cwd()` in the current process>"`, |
89 | | - // Though it's a little brute-force-y, the easiest way to fix this is to just stringify the code and perform the |
90 | | - // substitution in reverse. |
91 | | - const stringifiedConfig = JSON.stringify(jestConfig, null, 2).replace( |
92 | | - `"rootDir": "${process.cwd()}"`, |
93 | | - 'rootDir: process.cwd()', |
94 | | - ); |
95 | | - |
96 | | - // Now we just have to convert it back to a module and write it to disk |
97 | | - const code = `module.exports = ${stringifiedConfig}`; |
98 | | - fs.writeFileSync(path.resolve('jest/jest.config.js'), code); |
99 | | -} |
100 | | - |
101 | 64 | /** |
102 | 65 | * Modify a json file on disk. |
103 | 66 | * |
@@ -151,8 +114,6 @@ function runWithIgnores(skipPackages: string[] = []): void { |
151 | 114 | function runTests(): void { |
152 | 115 | if (CURRENT_NODE_VERSION === '8') { |
153 | 116 | installLegacyDeps(NODE_8_LEGACY_DEPENDENCIES); |
154 | | - // Inject a `const`-to-`var` transformer, in order to stop Node 8 from complaining when we shadow `global` |
155 | | - addJestTransformer(); |
156 | 117 | // TODO Right now, this just skips incompatible tests, but it could be skipping more (hence the aspirational name), |
157 | 118 | // and not just in Node 8. See `skipNonNodeTests`'s docstring. |
158 | 119 | skipNonNodeTests(); |
|
0 commit comments