|
1 | 1 | const t = require('tap') |
2 | 2 | const spawk = require('spawk') |
| 3 | +const { delimiter } = require('node:path') |
| 4 | +const setPATH = require('../lib/set-path.js') |
3 | 5 | const runScript = require('..') |
4 | 6 |
|
5 | 7 | const pkg = { |
@@ -141,4 +143,40 @@ t.test('spawn args', async t => { |
141 | 143 | })) |
142 | 144 | t.ok(spawk.done()) |
143 | 145 | }) |
| 146 | + |
| 147 | + await t.test('binPaths containing delimiter logs warning', async t => { |
| 148 | + const warnings = [] |
| 149 | + const onWarn = (...args) => warnings.push(args) |
| 150 | + process.on('log', onWarn) |
| 151 | + t.teardown(() => process.off('log', onWarn)) |
| 152 | + |
| 153 | + spawk.spawn( |
| 154 | + /.*/, |
| 155 | + false, |
| 156 | + e => (e.env.PATH || e.env.Path).includes(`/path/with${delimiter}delimiter`) |
| 157 | + ) |
| 158 | + await t.resolves(() => runScript({ |
| 159 | + pkg, |
| 160 | + binPaths: [`/path/with${delimiter}delimiter`], |
| 161 | + path: testdir, |
| 162 | + event: 'test', |
| 163 | + })) |
| 164 | + const warning = warnings.find(w => w[0] === 'warn' && w[1] === 'run-script' && w[2].includes('delimiter')) |
| 165 | + t.ok(warning, 'warning should be logged when binPath contains delimiter') |
| 166 | + t.match(warning[2], '"test" script') |
| 167 | + t.ok(spawk.done()) |
| 168 | + }) |
| 169 | + |
| 170 | + await t.test('binPaths containing delimiter uses generic message without event', async t => { |
| 171 | + const warnings = [] |
| 172 | + const onWarn = (...args) => warnings.push(args) |
| 173 | + process.on('log', onWarn) |
| 174 | + t.teardown(() => process.off('log', onWarn)) |
| 175 | + |
| 176 | + setPATH(testdir, [`/path/with${delimiter}delimiter`], {}) |
| 177 | + |
| 178 | + const warning = warnings.find(w => w[0] === 'warn' && w[1] === 'run-script' && w[2].includes('delimiter')) |
| 179 | + t.ok(warning, 'warning should be logged with generic message when no event') |
| 180 | + t.match(warning[2], 'script execution') |
| 181 | + }) |
144 | 182 | }) |
0 commit comments