* Spawn a process and assert its output against a snapshot. * if you want to automatically update the snapshot, run tests with NODE_REGENERATE_SNAPSHOTS=1 * transform is a function that takes the output and returns a string that will be compared against the snapshot * this is useful for normalizi
(filename, transform = (x) => x, { tty = false, ...options } = {})
| 190 | * @returns {Promise<void>} |
| 191 | */ |
| 192 | async function spawnAndAssert(filename, transform = (x) => x, { tty = false, ...options } = {}) { |
| 193 | if (tty && common.isWindows) { |
| 194 | test({ skip: 'Skipping pseudo-tty tests, as pseudo terminals are not available on Windows.' }); |
| 195 | return; |
| 196 | } |
| 197 | let { flags } = common.parseTestMetadata(filename); |
| 198 | if (options.flags) { |
| 199 | flags = [...options.flags, ...flags]; |
| 200 | } |
| 201 | |
| 202 | const executable = tty ? (process.env.PYTHON || 'python3') : process.execPath; |
| 203 | const args = |
| 204 | tty ? |
| 205 | [path.join(__dirname, '../..', 'tools/pseudo-tty.py'), process.execPath, ...flags, filename] : |
| 206 | [...flags, filename]; |
| 207 | const { stdout, stderr } = await common.spawnPromisified(executable, args, options); |
| 208 | await assertSnapshot(transform(`${stdout}${stderr}`), filename); |
| 209 | } |
| 210 | |
| 211 | function replaceTestDuration(str) { |
| 212 | return str |
no test coverage detected
searching dependent graphs…