10BC0
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e53e823 commit 17945a2Copy full SHA for 17945a2
test/common/assertSnapshot.js
@@ -1,14 +1,14 @@
1
'use strict';
2
const common = require('.');
3
const path = require('node:path');
4
+const test = require('node:test');
5
const fs = require('node:fs/promises');
6
const assert = require('node:assert/strict');
7
-
8
-const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\n|$)/g;
+const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\[\d+m)?(\n|$)/g;
9
const windowNewlineRegexp = /\r/g;
10
11
-function replaceStackTrace(str, replacement = '$1*$7\n') {
+function replaceStackTrace(str, replacement = '$1*$7$8\n') {
12
return str.replace(stackFramesRegexp, replacement);
13
}
14
@@ -50,11 +50,19 @@ async function assertSnapshot(actual, filename = process.argv[1]) {
50
* assertSnapshot.transform(assertSnapshot.replaceStackTrace, assertSnapshot.replaceWindowsLineEndings)
51
* @param {string} filename
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
55
* @returns {Promise<void>}
56
*/
-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
+ }
62
const flags = common.parseTestFlags(filename);
- 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);
66
await assertSnapshot(transform(`${stdout}${stderr}`), filename);
67
68
…eudo-tty/test_runner_default_reporter.js …res/test-runner/output/default_output.jstest/pseudo-tty/test_runner_default_reporter.js renamed to test/fixtures/test-runner/output/default_output.js
@@ -3,7 +3,7 @@ process.env.FORCE_COLOR = '1';
delete process.env.NODE_DISABLE_COLORS;
delete process.env.NO_COLOR;
-require('../common');
+require('../../../common');
const test = require('node:test');
test('should pass', () => {});
test/fixtures/test-runner/output/default_output.snapshot
@@ -0,0 +1,57 @@
+[32m✔ should pass [90m(*ms)[39m[39m
+[31m✖ should fail [90m(*ms)[39m[39m
+ Error: fail
+ *[39m
+
+[90m﹣ should skip [90m(*ms)[39m # SKIP[39m
+▶ parent
+ [31m✖ should fail [90m(*ms)[39m[39m
15
16
17
18
19
20
21
22
+ [31m✖ should pass but parent fail [90m(*ms)[39m[39m
23
+ [32m'test did not finish before its parent and was cancelled'[39m
24
25
+[31m▶ [39mparent [90m(*ms)[39m
26
27
+[34mℹ tests 6[39m
28
+[34mℹ suites 0[39m
29
+[34mℹ pass 1[39m
30
+[34mℹ fail 3[39m
31
+[34mℹ cancelled 1[39m
32
+[34mℹ skipped 1[39m
33
+[34mℹ todo 0[39m
34
+[34mℹ duration_ms *[39m
35
36
+[31m✖ failing tests:[39m
37
38
39
40
41
42
43
44
45
46
47
48
49
+[31m✖ should pass but parent fail [90m(*ms)[39m[39m
test/parallel/test-runner-output.mjs
@@ -10,16 +10,20 @@ function replaceTestDuration(str) {
.replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *');
+const color = '(\\[\\d+m)';
+const stackTraceBasePath = new RegExp(`${color}\\(${process.cwd()}/?${color}(.*)${color}\\)`, 'g');
function replaceSpecDuration(str) {
return str
.replaceAll(/\(0(\r?\n)ms\)/g, '(ZEROms)')
.replaceAll(/[0-9.]+ms/g, '*ms')
- .replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *');
+ .replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *')
+ .replace(stackTraceBasePath, '$3');
const defaultTransform = snapshot
.transform(snapshot.replaceWindowsLineEndings, snapshot.replaceStackTrace, replaceTestDuration);
const specTransform = snapshot
- .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceStackTrace, replaceSpecDuration);
+ .transform(replaceSpecDuration, snapshot.replaceWindowsLineEndings, snapshot.replaceStackTrace);
const tests = [
@@ -40,10 +44,11 @@ const tests = [
{ name: 'test-runner/output/name_pattern.js' },
{ name: 'test-runner/output/name_pattern_with_only.js' },
{ name: 'test-runner/output/unresolved_promise.js' },
-].map(({ name, transform }) => ({
+ { name: 'test-runner/output/default_output.js', transform: specTransform, tty: true },
+].map(({ name, tty, transform }) => ({
name,
fn: common.mustCall(async () => {
- await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform);
+ await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty });
}),
}));
test/pseudo-tty/test_runner_default_reporter.out
test/pseudo-tty/testcfg.py
@@ -36,7 +36,7 @@
from functools import reduce
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
-PTY_HELPER = join(dirname(__file__), 'pty_helper.py')
+PTY_HELPER = join(dirname(__file__), '../../tools/pseudo-tty.py')
class TTYTestCase(test.TestCase):
test/pseudo-tty/pty_helper.py tools/pseudo-tty.pytest/pseudo-tty/pty_helper.py renamed to tools/pseudo-tty.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
import errno
import os
import pty