| 239 | }) |
| 240 | |
| 241 | const matchCmd = (t, cmd, bin, match, params, expected) => { |
| 242 | const args = [] |
| 243 | const opts = {} |
| 244 | |
| 245 | switch (basename(cmd).toLowerCase()) { |
| 246 | case 'cmd.exe': |
| 247 | cmd = `${bin}.cmd` |
| 248 | break |
| 249 | case 'bash.exe': |
| 250 | args.push(bin) |
| 251 | break |
| 252 | case 'powershell.exe': |
| 253 | case 'pwsh.exe': |
| 254 | args.push(`${bin}.ps1`) |
| 255 | break |
| 256 | default: |
| 257 | throw new Error('unknown shell') |
| 258 | } |
| 259 | |
| 260 | const result = spawnPath(cmd, [...args, ...params], opts) |
| 261 | |
| 262 | // skip the first 3 lines of "npm test" to get the actual script output |
| 263 | if (params[0].startsWith('test')) { |
| 264 | result.stdout = result.stdout?.toString().split('\n').slice(3).join('\n').trim() |
| 265 | } |
| 266 | |
| 267 | t.match(result, { |
| 268 | status: 0, |
| 269 | signal: null, |
| 270 | stderr: '', |
| 271 | stdout: expected, |
| 272 | ...match, |
| 273 | }, `${cmd} ${bin} ${params[0]}`) |
| 274 | } |
| 275 | |
| 276 | // Array with command line parameters and expected output |
| 277 | const tests = [ |