|
1 | 1 | 'use strict'; |
2 | 2 | const common = require('.'); |
3 | 3 | const path = require('node:path'); |
| 4 | +const test = require('node:test'); |
4 | 5 | const fs = require('node:fs/promises'); |
5 | 6 | const assert = require('node:assert/strict'); |
6 | 7 |
|
7 | | - |
8 | | -const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\n|$)/g; |
| 8 | +const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g; |
9 | 9 | const windowNewlineRegexp = /\r/g; |
10 | 10 |
|
11 | | -function replaceStackTrace(str, replacement = '$1*$7\n') { |
| 11 | +function replaceStackTrace(str, replacement = '$1*$7$8\n') { |
12 | 12 | return str.replace(stackFramesRegexp, replacement); |
13 | 13 | } |
14 | 14 |
|
@@ -50,11 +50,19 @@ async function assertSnapshot(actual, filename = process.argv[1]) { |
50 | 50 | * assertSnapshot.transform(assertSnapshot.replaceStackTrace, assertSnapshot.replaceWindowsLineEndings) |
51 | 51 | * @param {string} filename |
52 | 52 | * @param {function(string): string} [transform] |
| 53 | + * @param {object} [options] - control how the child process is spawned |
| 54 | + * @param {boolean} [options.tty] - whether to spawn the process in a pseudo-tty |
53 | 55 | * @returns {Promise<void>} |
54 | 56 | */ |
55 | | -async function spawnAndAssert(filename, transform = (x) => x) { |
| 57 | +async function spawnAndAssert(filename, transform = (x) => x, { tty = false } = {}) { |
| 58 | + if (tty && common.isWindows) { |
| 59 | + test({ skip: 'Skipping pseudo-tty tests, as pseudo terminals are not available on Windows.' }); |
| 60 | + return; |
| 61 | + } |
56 | 62 | const flags = common.parseTestFlags(filename); |
57 | | - const { stdout, stderr } = await common.spawnPromisified(process.execPath, [...flags, filename]); |
| 63 | + const executable = tty ? 'tools/pseudo-tty.py' : process.execPath; |
| 64 | + const args = tty ? [process.execPath, ...flags, filename] : [...flags, filename]; |
| 65 | + const { stdout, stderr } = await common.spawnPromisified(executable, args); |
58 | 66 | await assertSnapshot(transform(`${stdout}${stderr}`), filename); |
59 | 67 | } |
60 | 68 |
|
|
0 commit comments