|
1 | 1 | 'use strict'; |
2 | 2 | constcommon=require('.'); |
3 | 3 | constpath=require('node:path'); |
| 4 | +consttest=require('node:test'); |
4 | 5 | constfs=require('node:fs/promises'); |
5 | 6 | constassert=require('node:assert/strict'); |
6 | 7 |
|
7 | | - |
8 | | -conststackFramesRegexp=/(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\n|$)/g; |
| 8 | +conststackFramesRegexp=/(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g; |
9 | 9 | constwindowNewlineRegexp=/\r/g; |
10 | 10 |
|
11 | | -functionreplaceStackTrace(str,replacement='$1*$7\n'){ |
| 11 | +functionreplaceStackTrace(str,replacement='$1*$7$8\n'){ |
12 | 12 | returnstr.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 | | -asyncfunctionspawnAndAssert(filename,transform=(x)=>x){ |
| 57 | +asyncfunctionspawnAndAssert(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 | constflags=common.parseTestFlags(filename); |
57 | | -const{ stdout, stderr }=awaitcommon.spawnPromisified(process.execPath,[...flags,filename]); |
| 63 | +constexecutable=tty ? 'tools/pseudo-tty.py' : process.execPath; |
| 64 | +constargs=tty ? [process.execPath, ...flags,filename] : [...flags,filename]; |
| 65 | +const{ stdout, stderr }=awaitcommon.spawnPromisified(executable,args); |
58 | 66 | awaitassertSnapshot(transform(`${stdout}${stderr}`),filename); |
59 | 67 | } |
60 | 68 |
|
|
0 commit comments