-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
tools: add node-pty as a dependency #47793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,9 +3,11 @@ const common = require('.'); | |
| const path = require('node:path'); | ||
| const fs = require('node:fs/promises'); | ||
| const assert = require('node:assert/strict'); | ||
| const pty = require('../../tools/node_modules/node-pty'); | ||
|
|
||
|
|
||
| const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\n|$)/g; | ||
| // eslint-disable-next-line no-control-regex | ||
| const stackFramesRegexp = /(\s+)((.+?)\s+\()?(?:\(?(.+?):(\d+)(?::(\d+))?)\)?(\s+\{)?(\u001b\[\d+m)?(\n|$)/g; | ||
| const windowNewlineRegexp = /\r/g; | ||
|
|
||
| function replaceStackTrace(str, replacement = '$1*$7\n') { | ||
|
|
@@ -39,6 +41,33 @@ async function assertSnapshot(actual, filename = process.argv[1]) { | |
| } | ||
| } | ||
|
|
||
| function spawnPTYPromisifyied(...args) { | ||
| const stderr = ''; | ||
| let stdout = ''; | ||
|
|
||
| const child = pty.spawn(...args); | ||
| child.onData((data) => { stdout += data; }); | ||
|
|
||
| return new Promise((resolve, reject) => { | ||
| child.on('close', (code, signal) => { | ||
| resolve({ | ||
| code, | ||
| signal, | ||
| stderr, | ||
| stdout, | ||
| }); | ||
| }); | ||
| child.on('error', (code, signal) => { | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| reject({ | ||
| code, | ||
| signal, | ||
| stderr, | ||
| stdout, | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * 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 | ||
|
|
@@ -53,9 +82,11 @@ async function assertSnapshot(actual, filename = process.argv[1]) { | |
| * @param {function(string): string} [transform] | ||
| * @returns {Promise<void>} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably be updated.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? it still returns
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, either GitHub or myself messed up the reference. I meant to select the entire doc comment, not just the |
||
| */ | ||
| async function spawnAndAssert(filename, transform = (x) => x) { | ||
| async function spawnAndAssert(filename, transform = (x) => x, options = {}) { | ||
| const flags = common.parseTestFlags(filename); | ||
| const { stdout, stderr } = await common.spawnPromisified(process.execPath, [...flags, filename]); | ||
| const { stdout, stderr } = await (options.tty ? | ||
| spawnPTYPromisifyied(process.execPath, [...flags, filename]) : | ||
MoLow marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| common.spawnPromisified(process.execPath, [...flags, filename])); | ||
| await assertSnapshot(transform(`${stdout}${stderr}`), filename); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| [32m✔ should pass [90m(*ms)[39m[39m | ||
| [31m✖ should fail [90m(*ms)[39m[39m | ||
| Error: fail | ||
| * | ||
| * | ||
| * | ||
| * | ||
| * | ||
| * | ||
| * | ||
|
|
||
| [90m﹣ should skip [90m(*ms)[39m # SKIP[39m | ||
| ▶ parent | ||
| [31m✖ should fail [90m(*ms)[39m[39m | ||
| Error: fail | ||
| * | ||
| * | ||
| * | ||
| * | ||
| * | ||
|
|
||
| [31m✖ should pass but parent fail [90m(*ms)[39m[39m | ||
| [32m'test did not finish before its parent and was cancelled'[39m | ||
|
|
||
| [31m▶ [39mparent [90m(*ms)[39m | ||
|
|
||
| [34mℹ tests 6[39m | ||
| [34mℹ suites 0[39m | ||
| [34mℹ pass 1[39m | ||
| [34mℹ fail 3[39m | ||
| [34mℹ cancelled 1[39m | ||
| [34mℹ skipped 1[39m | ||
| [34mℹ todo 0[39m | ||
| [34mℹ duration_ms *[39m | ||
|
|
||
| [31m✖ failing tests:[39m | ||
|
|
||
| [31m✖ should fail [90m(*ms)[39m[39m | ||
| Error: fail | ||
| * | ||
| * | ||
| * | ||
| * | ||
| * | ||
| * | ||
| * | ||
|
|
||
| [31m✖ should fail [90m(*ms)[39m[39m | ||
| Error: fail | ||
| * | ||
| * | ||
| * | ||
| * | ||
| * | ||
|
|
||
| [31m✖ should pass but parent fail [90m(*ms)[39m[39m | ||
| [32m'test did not finish before its parent and was cancelled'[39m |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,12 +14,13 @@ 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(new RegExp(`(\\u001b\\[\\d+m)\\(${process.cwd()}/?(\\u001b\\[\\d+m)(.*)(\\u001b\\[\\d+m)\\)`, 'g'), '$3'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment to this line and explain what it does? |
||
| } | ||
| const defaultTransform = snapshot | ||
| .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceStackTrace, replaceTestDuration); | ||
| const specTransform = snapshot | ||
| .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceStackTrace, replaceSpecDuration); | ||
| .transform(replaceSpecDuration, snapshot.replaceWindowsLineEndings, snapshot.replaceStackTrace); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we have to change the ordering of this transform? Would it be helpful to document this with a comment? |
||
|
|
||
|
|
||
| const tests = [ | ||
|
|
@@ -40,10 +41,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 }); | ||
| }), | ||
| })); | ||
|
|
||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Shell script to update node-pty in the source tree to the latest release. | ||
|
|
||
| # This script must be in the tools directory when it runs because it uses the | ||
| # script source file path to determine directories to work in. | ||
|
|
||
| set -ex | ||
|
|
||
| ROOT=$(cd "$(dirname "$0")/../.." && pwd) | ||
|
|
||
| [ -z "$NODE" ] && NODE="$ROOT/out/Release/node" | ||
| [ -x "$NODE" ] || NODE=$(command -v node) | ||
| NPM="$ROOT/deps/npm/bin/npm-cli.js" | ||
|
|
||
| NEW_VERSION=$("$NODE" "$NPM" view node-pty latest) | ||
| CURRENT_VERSION=$("$NODE" -p "require('./tools/node_modules/node-pty/package.json').version") | ||
|
|
||
| if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then | ||
| echo "Skipped because node-pty is on the latest version." | ||
| exit 0 | ||
| fi | ||
|
|
||
| cd "$( dirname "$0" )" || exit | ||
| rm -rf ../node_modules/node-pty | ||
| ( | ||
| rm -rf node-pty-tmp | ||
| mkdir node-pty-tmp | ||
| cd node-pty-tmp || exit | ||
|
|
||
| "$NODE" "$NPM" init --yes | ||
| "$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts node-pty | ||
| ) | ||
|
|
||
| mv node-pty-tmp/node_modules/node-pty ../node_modules/node-pty | ||
| rm -rf node-pty-tmp/ | ||
|
|
||
| echo ".buildstamp | ||
| build/" >> ../node_modules/node-pty/.gitignore | ||
|
|
||
| # The last line of the script should always print the new version, | ||
| # as we need to add it to $GITHUB_ENV variable. | ||
| echo "NEW_VERSION=$NEW_VERSION" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.