-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmake-spawn-args.js
144 lines (137 loc) · 3.66 KB
/
make-spawn-args.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const t = require('tap')
const spawk = require('spawk')
const runScript = require('..')
const pkg = {
name: '@npmcli/run-script-test-package',
version: '1.0.0-test',
config: {
test_string: 'a value',
test_array: ['a string', 'another string'],
test_null: null,
test_false: false,
},
engines: {
node: '>0.10',
npm: '>1.2.3',
},
bin: 'index.js',
scripts: {
test: 'echo test',
'weird<x>\x04': 'echo weird',
},
}
t.test('spawn args', async t => {
const testdir = t.testdir({})
await t.test('defaults', async t => {
spawk.spawn(
/.*/,
a => a.includes('echo test'),
e => {
return e.cwd === testdir &&
e.stdio === 'pipe' &&
e.stdioString === undefined &&
e.shell === false &&
e.env.npm_package_json.endsWith('package.json') &&
e.env.npm_package_name === pkg.name &&
e.env.npm_package_version === pkg.version &&
e.env.npm_package_config_test_null === '' &&
e.env.npm_package_config_test_false === '' &&
e.env.npm_package_config_test_string === pkg.config.test_string &&
e.env.npm_package_config_test_array_0 === pkg.config.test_array[0] &&
e.env.npm_package_config_test_array_1 === pkg.config.test_array[1] &&
e.env.npm_package_bin === pkg.bin &&
e.env.npm_package_engines_npm === pkg.engines.npm &&
e.env.npm_package_engines_node === pkg.engines.node &&
e.env.npm_lifecycle_event === 'test' &&
e.env.npm_lifecycle_script === 'echo test' &&
e.env.npm_config_node_gyp === require.resolve('node-gyp/bin/node-gyp.js')
}
)
await t.resolves(() => runScript({
pkg,
path: testdir,
event: 'test',
}))
t.ok(spawk.done())
})
await t.test('provided env', async t => {
spawk.spawn(
/.*/,
a => a.includes('echo test'),
e => {
return e.env.test_fixture === 'a string' &&
e.env.npm_config_node_gyp === '/test/path.js'
}
)
await t.resolves(() => runScript({
pkg,
path: testdir,
env: {
npm_config_node_gyp: '/test/path.js',
test_fixture: 'a string',
},
event: 'test',
}))
t.ok(spawk.done())
})
await t.test('provided options.nodeGyp', async t => {
spawk.spawn(
/.*/,
a => a.includes('echo test'),
e => {
return e.env.npm_config_node_gyp === '/test/path.js'
}
)
await t.resolves(() => runScript({
pkg,
path: testdir,
nodeGyp: '/test/path.js',
event: 'test',
}))
t.ok(spawk.done())
})
await t.test('provided args', async t => {
spawk.spawn(
/.*/,
a => a.find(arg => arg.includes('echo test') && arg.includes('argtest'))
)
await t.resolves(() => runScript({
pkg,
path: testdir,
args: ['argtest'],
event: 'test',
}))
t.ok(spawk.done())
})
t.test('event with invalid characters', async t => {
spawk.spawn(
/.*/,
a => a.includes('echo weird'),
e => {
return e.env.npm_lifecycle_event === 'weird<x>\x04' &&
e.env.npm_lifecycle_script === 'echo weird'
}
)
await t.resolves(() => runScript({
pkg,
path: testdir,
event: 'weird<x>\x04',
}))
t.ok(spawk.done())
})
await t.test('provided binPaths', async t => {
spawk.spawn(
/.*/,
false,
e => (e.env.PATH || e.env.Path).startsWith('/tmp/test-fixture/binpath')
)
await t.resolves(() => runScript({
pkg,
binPaths: ['/tmp/test-fixture/binpath'],
path: testdir,
args: ['test arg'],
event: 'test',
}))
t.ok(spawk.done())
})
})