| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,14 +1,14 @@ | |||
| 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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ process.env.FORCE_COLOR = '1'; | |||
| 3 | 3 | delete process.env.NODE_DISABLE_COLORS; | |
| 4 | 4 | delete process.env.NO_COLOR; | |
| 5 | 5 | ||
| 6 | - require('../common'); | ||
| 6 | + require('../../../common'); | ||
| 7 | 7 | const test = require('node:test'); | |
| 8 | 8 | ||
| 9 | 9 | test('should pass', () => {}); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,57 @@ | |||
| 1 | + [32m✔ should pass [90m(*ms)[39m[39m | ||
| 2 | + [31m✖ should fail [90m(*ms)[39m[39m | ||
| 3 | + Error: fail | ||
| 4 | + *[39m | ||
| 5 | + *[39m | ||
| 6 | + *[39m | ||
| 7 | + *[39m | ||
| 8 | + *[39m | ||
| 9 | + *[39m | ||
| 10 | + *[39m | ||
| 11 | + | ||
| 12 | + [90m﹣ should skip [90m(*ms)[39m # SKIP[39m | ||
| 13 | + ▶ parent | ||
| 14 | + [31m✖ should fail [90m(*ms)[39m[39m | ||
| 15 | + Error: fail | ||
| 16 | + *[39m | ||
| 17 | + *[39m | ||
| 18 | + *[39m | ||
| 19 | + *[39m | ||
| 20 | + *[39m | ||
| 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 | + [31m✖ should fail [90m(*ms)[39m[39m | ||
| 39 | + Error: fail | ||
| 40 | + *[39m | ||
| 41 | + *[39m | ||
| 42 | + *[39m | ||
| 43 | + *[39m | ||
| 44 | + *[39m | ||
| 45 | + *[39m | ||
| 46 | + *[39m | ||
| 47 | + | ||
| 48 | + [31m✖ should fail [90m(*ms)[39m[39m | ||
| 49 | + Error: fail | ||
| 50 | + *[39m | ||
| 51 | + *[39m | ||
| 52 | + *[39m | ||
| 53 | + *[39m | ||
| 54 | + *[39m | ||
| 55 | + | ||
| 56 | + [31m✖ should pass but parent fail [90m(*ms)[39m[39m | ||
| 57 | + [32m'test did not finish before its parent and was cancelled'[39m | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,16 +10,20 @@ function replaceTestDuration(str) { | |||
| 10 | 10 | .replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *'); | |
| 11 | 11 | } | |
| 12 | 12 | ||
| 13 | + const color = '(\\[\\d+m)'; | ||
| 14 | + const stackTraceBasePath = new RegExp(`${color}\\(${process.cwd()}/?${color}(.*)${color}\\)`, 'g'); | ||
| 15 | + | ||
| 13 | 16 | function replaceSpecDuration(str) { | |
| 14 | 17 | return str | |
| 15 | 18 | .replaceAll(/\(0(\r?\n)ms\)/g, '(ZEROms)') | |
| 16 | 19 | .replaceAll(/[0-9.]+ms/g, '*ms') | |
| 17 | - .replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *'); | ||
| 20 | + .replaceAll(/duration_ms [0-9.]+/g, 'duration_ms *') | ||
| 21 | + .replace(stackTraceBasePath, '$3'); | ||
| 18 | 22 | } | |
| 19 | 23 | const defaultTransform = snapshot | |
| 20 | 24 | .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceStackTrace, replaceTestDuration); | |
| 21 | 25 | const specTransform = snapshot | |
| 22 | - .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceStackTrace, replaceSpecDuration); | ||
| 26 | + .transform(replaceSpecDuration, snapshot.replaceWindowsLineEndings, snapshot.replaceStackTrace); | ||
| 23 | 27 | ||
| 24 | 28 | ||
| 25 | 29 | const tests = [ | |
@@ -40,10 +44,11 @@ const tests = [ | |||
| 40 | 44 | { name: 'test-runner/output/name_pattern.js' }, | |
| 41 | 45 | { name: 'test-runner/output/name_pattern_with_only.js' }, | |
| 42 | 46 | { name: 'test-runner/output/unresolved_promise.js' }, | |
| 43 | - ].map(({ name, transform }) => ({ | ||
| 47 | + { name: 'test-runner/output/default_output.js', transform: specTransform, tty: true }, | ||
| 48 | + ].map(({ name, tty, transform }) => ({ | ||
| 44 | 49 | name, | |
| 45 | 50 | fn: common.mustCall(async () => { | |
| 46 | - await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform); | ||
| 51 | + await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { tty }); | ||
| 47 | 52 | }), | |
| 48 | 53 | })); | |
| 49 | 54 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ | |||
| 36 | 36 | from functools import reduce | |
| 37 | 37 | ||
| 38 | 38 | FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") | |
| 39 | - PTY_HELPER = join(dirname(__file__), 'pty_helper.py') | ||
| 39 | + PTY_HELPER = join(dirname(__file__), '../../tools/pseudo-tty.py') | ||
| 40 | 40 | ||
| 41 | 41 | class TTYTestCase(test.TestCase): | |
| 42 | 42 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + #!/usr/bin/env python3 | ||
| 2 | + | ||
| 1 | 3 | import errno | |
| 2 | 4 | import os | |
| 3 | 5 | import pty | |
| Back | FazBrowse Home | New Git URL |
0 commit comments