(t, mocks, { level = 0 } = {})
| 1 | const t = require('tap') |
| 2 | |
| 3 | const mockRunScript = async (t, mocks, { level = 0 } = {}) => { |
| 4 | const mockedRunScript = t.mock('../lib/run-script.js', mocks) |
| 5 | const { Chalk } = await import('chalk') |
| 6 | |
| 7 | const outputs = [] |
| 8 | const handleOutput = (_level, msg) => { |
| 9 | if (_level === 'standard') { |
| 10 | outputs.push(msg) |
| 11 | } |
| 12 | } |
| 13 | process.on('output', handleOutput) |
| 14 | t.teardown(() => process.off('output', handleOutput)) |
| 15 | |
| 16 | const logs = [] |
| 17 | const handleLog = (_level, title, msg) => { |
| 18 | logs.push(`${_level} ${title} ${msg}`) |
| 19 | } |
| 20 | process.on('log', handleLog) |
| 21 | t.teardown(() => process.off('log', handleLog)) |
| 22 | |
| 23 | const runScript = (opts) => mockedRunScript({ |
| 24 | args: [], |
| 25 | call: '', |
| 26 | path: '', |
| 27 | runPath: '', |
| 28 | shell: process.platform === 'win32' |
| 29 | ? process.env.ComSpec || 'cmd' |
| 30 | : process.env.SHELL || 'sh', |
| 31 | ...opts, |
| 32 | flatOptions: { chalk: new Chalk({ level }) }, |
| 33 | }) |
| 34 | return { runScript, outputs, logs } |
| 35 | } |
| 36 | |
| 37 | t.test('no package.json', async t => { |
| 38 | t.plan(1) |
no test coverage detected