|
1 | 1 | const t = require('tap')
|
2 | 2 | const { spawnSync } = require('child_process')
|
3 | 3 | const { resolve, join, extname, basename, sep } = require('path')
|
4 |
| -const { readFileSync, chmodSync, readdirSync, statSync } = require('fs') |
| 4 | +const { readFileSync, chmodSync, readdirSync, rmSync, statSync } = require('fs') |
5 | 5 | const Diff = require('diff')
|
6 | 6 | const { sync: which } = require('which')
|
7 | 7 | const { version } = require('../../package.json')
|
8 | 8 |
|
9 |
| -const ROOT = resolve(__dirname, '../..') |
10 |
| -const BIN = join(ROOT, 'bin') |
11 |
| -const NODE = readFileSync(process.execPath) |
12 |
| -const SHIMS = readdirSync(BIN).reduce((acc, shim) => { |
13 |
| - const p = join(BIN, shim) |
| 9 | +const readNonJsFiles = (dir) => readdirSync(dir).reduce((acc, shim) => { |
| 10 | + const p = join(dir, shim) |
14 | 11 | if (extname(p) !== '.js' && !statSync(p).isDirectory()) {
|
15 | 12 | acc[shim] = readFileSync(p, 'utf-8')
|
16 | 13 | }
|
17 | 14 | return acc
|
18 | 15 | }, {})
|
19 | 16 |
|
| 17 | +const ROOT = resolve(__dirname, '../..') |
| 18 | +const BIN = join(ROOT, 'bin') |
| 19 | +const SHIMS = readNonJsFiles(BIN) |
| 20 | +const NODE_GYP = readNonJsFiles(join(BIN, 'node-gyp-bin')) |
20 | 21 | const SHIM_EXTS = [...new Set(Object.keys(SHIMS).map(p => extname(p)))]
|
21 | 22 |
|
22 | 23 | // windows requires each segment of a command path to be quoted when using shell: true
|
@@ -65,6 +66,21 @@ t.test('shim contents', t => {
|
65 | 66 | })
|
66 | 67 | })
|
67 | 68 |
|
| 69 | +t.test('node-gyp', t => { |
| 70 | + // these files need to exist to avoid breaking yarn 1.x |
| 71 | + |
| 72 | + for (const [key, file] of Object.entries(NODE_GYP)) { |
| 73 | + t.match(file, /npm_config_node_gyp/, `${key} contains env var`) |
| 74 | + t.match( |
| 75 | + file, |
| 76 | + /[\\/]\.\.[\\/]\.\.[\\/]node_modules[\\/]node-gyp[\\/]bin[\\/]node-gyp\.js/, |
| 77 | + `${key} contains path` |
| 78 | + ) |
| 79 | + } |
| 80 | + |
| 81 | + t.end() |
| 82 | +}) |
| 83 | + |
68 | 84 | t.test('run shims', t => {
|
69 | 85 | const path = t.testdir({
|
70 | 86 | ...SHIMS,
|
|
0 commit comments