Skip to content

Commit

Permalink
test: migrate message eval tests from Python to JS
Browse files Browse the repository at this point in the history
Migrate the eval tests in the `test/message` folder from Python to JS.
  • Loading branch information
Yiyun Lei committed Oct 31, 2023
1 parent aa4248d commit d2536ce
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

require('../common');
require('../../common');

const spawn = require('child_process').spawn;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ with(this){__filename}
^^^^

SyntaxError: Strict mode code may not include a with statement
at makeContextifyScript (node:internal/vm:*:*)
at new Script (node:vm:*:*)
at createScript (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [eval]-wrapper:*:*
at runScript (node:internal/process/execution:*:*)
Expand All @@ -19,23 +21,24 @@ throw new Error("hello")
^

Error: hello
at [eval]:1:7
at runScriptInThisContext (node:internal/vm:*:*)
at [eval]:*:*
at Script.runInThisContext (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [eval]-wrapper:*:*
at runScript (node:internal/process/execution:*:*)
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_string:*:*

Node.js *

[eval]:1
throw new Error("hello")
^

Error: hello
at [eval]:1:7
at runScriptInThisContext (node:internal/vm:*:*)
at [eval]:*:*
at Script.runInThisContext (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [eval]-wrapper:*:*
at runScript (node:internal/process/execution:*:*)
Expand All @@ -49,8 +52,9 @@ var x = 100; y = x;
^

ReferenceError: y is not defined
at [eval]:1:16
at runScriptInThisContext (node:internal/vm:*:*)
at [eval]:*:*
at Script.runInThisContext (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [eval]-wrapper:*:*
at runScript (node:internal/process/execution:*:*)
Expand All @@ -63,15 +67,15 @@ Node.js *
var ______________________________________________; throw 10
^
10
(Use `* --trace-uncaught ...` to show where the exception was thrown)
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js *

[eval]:1
var ______________________________________________; throw 10
^
10
(Use `* --trace-uncaught ...` to show where the exception was thrown)
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js *
done
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

require('../common');
require('../../common');

const spawn = require('child_process').spawn;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ with(this){__filename}
^^^^

SyntaxError: Strict mode code may not include a with statement
at makeContextifyScript (node:internal/vm:*:*)
at new Script (node:vm:*:*)
at createScript (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [stdin]-wrapper:*:*
at runScript (node:internal/process/execution:*:*)
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_stdin:*:*
at Socket.<anonymous> (node:internal/process/execution:*:*)
at Socket.emit (node:events:*:*)
at endReadableNT (node:internal/streams/readable:*:*)
at process.processTicksAndRejections (node:internal/process/task_queues:*:*)

Node.js *
42
Expand All @@ -23,33 +23,33 @@ throw new Error("hello")
^

Error: hello
at [stdin]:1:7
at runScriptInThisContext (node:internal/vm:*:*)
at [stdin]:*:*
at Script.runInThisContext (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [stdin]-wrapper:*:*
at runScript (node:internal/process/execution:*:*)
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_stdin:*:*
at Socket.<anonymous> (node:internal/process/execution:*:*)
at Socket.emit (node:events:*:*)
at endReadableNT (node:internal/streams/readable:*:*)

Node.js *
[stdin]:1
throw new Error("hello")
^

Error: hello
at [stdin]:1:*
at runScriptInThisContext (node:internal/vm:*:*)
at [stdin]:*:*
at Script.runInThisContext (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [stdin]-wrapper:*:*
at runScript (node:internal/process/execution:*:*)
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_stdin:*:*
at Socket.<anonymous> (node:internal/process/execution:*:*)
at Socket.emit (node:events:*:*)
at endReadableNT (node:internal/streams/readable:*:*)

Node.js *
100
Expand All @@ -58,32 +58,32 @@ let x = 100; y = x;
^

ReferenceError: y is not defined
at [stdin]:1:16
at runScriptInThisContext (node:internal/vm:*:*)
at [stdin]:*:*
at Script.runInThisContext (node:vm:*:*)
at Object.runInThisContext (node:vm:*:*)
at node:internal/process/execution:*:*
at [stdin]-wrapper:*:*
at runScript (node:internal/process/execution:*:*)
at evalScript (node:internal/process/execution:*:*)
at node:internal/main/eval_stdin:*:*
at Socket.<anonymous> (node:internal/process/execution:*:*)
at Socket.emit (node:events:*:*)
at endReadableNT (node:internal/streams/readable:*:*)

Node.js *

[stdin]:1
let ______________________________________________; throw 10
^
10
(Use `* --trace-uncaught ...` to show where the exception was thrown)
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js *

[stdin]:1
let ______________________________________________; throw 10
^
10
(Use `* --trace-uncaught ...` to show where the exception was thrown)
(Use `node --trace-uncaught ...` to show where the exception was thrown)

Node.js *
done
29 changes: 29 additions & 0 deletions test/parallel/test-node-output-eval.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import '../common/index.mjs';
import * as fixtures from '../common/fixtures.mjs';
import * as snapshot from '../common/assertSnapshot.js';
import { describe, it } from 'node:test';

describe('eval output', { concurrency: true }, () => {
function normalize(str) {
return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
.replaceAll(/\d+:\d+/g, '*:*');
}

const defaultTransform = snapshot.transform(
normalize,
snapshot.replaceWindowsLineEndings,
snapshot.replaceWindowsPaths,
snapshot.replaceNodeVersion
);

const tests = [
{ name: 'eval/eval_messages.js' },
{ name: 'eval/stdin_messages.js' },
];

for (const { name } of tests) {
it(name, async () => {
await snapshot.spawnAndAssert(fixtures.path(name), defaultTransform);

Check failure on line 26 in test/parallel/test-node-output-eval.mjs

View workflow job for this annotation

GitHub Actions / test-macOS

--- stdout --- ::debug::starting to run eval output ▶ eval output ✖ eval/eval_messages.js (1870.031356ms) AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: + actual - expected ... Lines skipped '[eval]\n' + '[eval]:1\n' + ... '\n' + 'SyntaxError: Strict mode code may not include a with statement\n' + + ' at makeContextifyScript (node:internal/vm:*:*)\n' + + ' at node:internal/process/execution:*:*\n' + + ' at [eval]-wrapper:*:*\n' + + ' at runScript (node:internal/process/execution:*:*)\n' + + ' at evalScript (node:internal/process/execution:*:*)\n' + + ' at node:internal/main/eval_string:*:*\n' + + '\n' + + 'Node.js *\n' + + '42\n' + + '42\n' + + '[eval]:1\n' + + 'throw new Error("hello")\n' + + '^\n' + + '\n' + + 'Error: hello\n' + + ' at [eval]:*:*\n' + + ' at runScriptInThisContext (node:internal/vm:*:*)\n' + + ' at node:internal/process/execution:*:*\n' + + ' at [eval]-wrapper:*:*\n' + + ' at runScript (node:internal/process/execution:*:*)\n' + + ' at evalScript (node:internal/process/execution:*:*)\n' + + ' at node:internal/main/eval_string:*:*\n' + + '\n' + + 'Node.js *\n' + ... - ' at new Script (node:vm:*:*)\n' + - ' at createScript (node:vm:*:*)\n' + - ' at Object.runInThisContext (node:vm:*:*)\n' + - ' at node:internal/process/execution:*:*\n' + - ' at [eval]-wrapper:*:*\n' + - ' at runScript (node:internal/process/execution:*:*)\n' + - ' at evalScript (node:internal/process/execution:*:*)\n' + - ' at node:internal/main/eval_string:*:*\n' + - '\n' + - 'Node.js *\n' + - '42\n' + - '42\n' + - '[eval]:1\n' + - 'throw new Error("hello")\n' + - '^\n' + - '\n' + - 'Error: hello\n' + - ' at [eval]:*:*\n' + - ' at Script.runInThisContext (node:vm:*:*)\n' + - ' at Object.runInThisContext (node:vm:*:*)\n' + - ' at node:internal/process/execution:*:*\n' + - ' at [eval]-wrapper:*:*\n' + - ' at runScript (node:internal/process/execution:*:*)\n' + - ' at evalScript (node:internal/process/execution:*:*)\n' + ... at assertSnapshot (/Users/runner/work/node/node/test/common/assertSnapshot.js:56:12) at async Module.spawnAndAssert (/Users/runner/work/node/node/test/common/assertSnapshot.js:84:3) at async TestContext.<anonymous> (file:///Users/runner/work/node/node/test/parallel/test-node-output-eval.mjs:26:7) at async Test.run (node:internal/test_runner/test:632:9) at async Promise.all (index 0) at async Suite.run (node:internal/test_runner/test:948:7) at async startSubtest (node:internal/test_runner/harness:216:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: '[eval]\n[eval]:1\nwith(this){__filename}\n^^^^\n\nSyntaxError: Strict mode code may not include a with statement\n at makeContextifyScript (node:internal/vm:*:*)\n at node:internal/process/execution:*:*\n at [eval]-wrapper:*:*\n at runScript (node:internal/process/execution:*:*)\n...', expected: '[eval]\n[eval]:1\nwith(this){__filename}\n^^^^\n\nSyntaxError: Strict mode code may not include a with statement\n at new Script (node:vm:*:*)\n at createScript (node:vm:*:*)\n at Object.runInThisContext (node:vm:*:*)\n at node:internal/process/execution:*:*\n...', operator: 'strictEqual' } ✖ eval/stdin_messages.js (1831.284708ms) AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: + actual - expected ... Lines skipped '[stdin]\n' + '[stdin]:1\n' + ... '\n' + 'SyntaxError: Strict mode code may not include a with statement\n' + + ' at makeContextifyScript (node:internal/vm:*:*)\n' + + ' at node:internal/process/execution:*:*\n' +

Check failure on line 26 in test/parallel/test-node-output-eval.mjs

View workflow job for this annotation

GitHub Actions / test-linux

--- stdout --- ::debug::starting to run eval output ▶ eval output ✖ eval/eval_messages.js (1166.020344ms) AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: + actual - expected ... Lines skipped '[eval]\n' + '[eval]:1\n' + ... '\n' + 'SyntaxError: Strict mode code may not include a with statement\n' + + ' at makeContextifyScript (node:internal/vm:*:*)\n' + + ' at node:internal/process/execution:*:*\n' + + ' at [eval]-wrapper:*:*\n' + + ' at runScript (node:internal/process/execution:*:*)\n' + + ' at evalScript (node:internal/process/execution:*:*)\n' + + ' at node:internal/main/eval_string:*:*\n' + + '\n' + + 'Node.js *\n' + + '42\n' + + '42\n' + + '[eval]:1\n' + + 'throw new Error("hello")\n' + + '^\n' + + '\n' + + 'Error: hello\n' + + ' at [eval]:*:*\n' + + ' at runScriptInThisContext (node:internal/vm:*:*)\n' + + ' at node:internal/process/execution:*:*\n' + + ' at [eval]-wrapper:*:*\n' + + ' at runScript (node:internal/process/execution:*:*)\n' + + ' at evalScript (node:internal/process/execution:*:*)\n' + + ' at node:internal/main/eval_string:*:*\n' + + '\n' + + 'Node.js *\n' + ... - ' at new Script (node:vm:*:*)\n' + - ' at createScript (node:vm:*:*)\n' + - ' at Object.runInThisContext (node:vm:*:*)\n' + - ' at node:internal/process/execution:*:*\n' + - ' at [eval]-wrapper:*:*\n' + - ' at runScript (node:internal/process/execution:*:*)\n' + - ' at evalScript (node:internal/process/execution:*:*)\n' + - ' at node:internal/main/eval_string:*:*\n' + - '\n' + - 'Node.js *\n' + - '42\n' + - '42\n' + - '[eval]:1\n' + - 'throw new Error("hello")\n' + - '^\n' + - '\n' + - 'Error: hello\n' + - ' at [eval]:*:*\n' + - ' at Script.runInThisContext (node:vm:*:*)\n' + - ' at Object.runInThisContext (node:vm:*:*)\n' + - ' at node:internal/process/execution:*:*\n' + - ' at [eval]-wrapper:*:*\n' + - ' at runScript (node:internal/process/execution:*:*)\n' + - ' at evalScript (node:internal/process/execution:*:*)\n' + ... at assertSnapshot (/home/runner/work/node/node/test/common/assertSnapshot.js:56:12) at async Module.spawnAndAssert (/home/runner/work/node/node/test/common/assertSnapshot.js:84:3) at async TestContext.<anonymous> (file:///home/runner/work/node/node/test/parallel/test-node-output-eval.mjs:26:7) at async Test.run (node:internal/test_runner/test:632:9) at async Promise.all (index 0) at async Suite.run (node:internal/test_runner/test:948:7) at async startSubtest (node:internal/test_runner/harness:216:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: '[eval]\n[eval]:1\nwith(this){__filename}\n^^^^\n\nSyntaxError: Strict mode code may not include a with statement\n at makeContextifyScript (node:internal/vm:*:*)\n at node:internal/process/execution:*:*\n at [eval]-wrapper:*:*\n at runScript (node:internal/process/execution:*:*)\n...', expected: '[eval]\n[eval]:1\nwith(this){__filename}\n^^^^\n\nSyntaxError: Strict mode code may not include a with statement\n at new Script (node:vm:*:*)\n at createScript (node:vm:*:*)\n at Object.runInThisContext (node:vm:*:*)\n at node:internal/process/execution:*:*\n...', operator: 'strictEqual' } ✖ eval/stdin_messages.js (1160.830248ms) AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: + actual - expected ... Lines skipped '[stdin]\n' + '[stdin]:1\n' + ... '\n' + 'SyntaxError: Strict mode code may not include a with statement\n' + + ' at makeContextifyScript (node:internal/vm:*:*)\n' + + ' at node:internal/process/execution:*:*\n' + +

Check failure on line 26 in test/parallel/test-node-output-eval.mjs

View workflow job for this annotation

GitHub Actions / test-asan

--- stdout --- ::debug::starting to run eval output ▶ eval output ✖ eval/eval_messages.js (5815.101612ms) AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: + actual - expected ... Lines skipped '[eval]\n' + '[eval]:1\n' + ... '\n' + 'SyntaxError: Strict mode code may not include a with statement\n' + + ' at makeContextifyScript (node:internal/vm:*:*)\n' + + ' at node:internal/process/execution:*:*\n' + + ' at [eval]-wrapper:*:*\n' + + ' at runScript (node:internal/process/execution:*:*)\n' + + ' at evalScript (node:internal/process/execution:*:*)\n' + + ' at node:internal/main/eval_string:*:*\n' + + '\n' + + 'Node.js *\n' + + '42\n' + + '42\n' + + '[eval]:1\n' + + 'throw new Error("hello")\n' + + '^\n' + + '\n' + + 'Error: hello\n' + + ' at [eval]:*:*\n' + + ' at runScriptInThisContext (node:internal/vm:*:*)\n' + + ' at node:internal/process/execution:*:*\n' + + ' at [eval]-wrapper:*:*\n' + + ' at runScript (node:internal/process/execution:*:*)\n' + + ' at evalScript (node:internal/process/execution:*:*)\n' + + ' at node:internal/main/eval_string:*:*\n' + + '\n' + + 'Node.js *\n' + ... - ' at new Script (node:vm:*:*)\n' + - ' at createScript (node:vm:*:*)\n' + - ' at Object.runInThisContext (node:vm:*:*)\n' + - ' at node:internal/process/execution:*:*\n' + - ' at [eval]-wrapper:*:*\n' + - ' at runScript (node:internal/process/execution:*:*)\n' + - ' at evalScript (node:internal/process/execution:*:*)\n' + - ' at node:internal/main/eval_string:*:*\n' + - '\n' + - 'Node.js *\n' + - '42\n' + - '42\n' + - '[eval]:1\n' + - 'throw new Error("hello")\n' + - '^\n' + - '\n' + - 'Error: hello\n' + - ' at [eval]:*:*\n' + - ' at Script.runInThisContext (node:vm:*:*)\n' + - ' at Object.runInThisContext (node:vm:*:*)\n' + - ' at node:internal/process/execution:*:*\n' + - ' at [eval]-wrapper:*:*\n' + - ' at runScript (node:internal/process/execution:*:*)\n' + - ' at evalScript (node:internal/process/execution:*:*)\n' + ... at assertSnapshot (/home/runner/work/node/node/test/common/assertSnapshot.js:56:12) at async Module.spawnAndAssert (/home/runner/work/node/node/test/common/assertSnapshot.js:84:3) at async TestContext.<anonymous> (file:///home/runner/work/node/node/test/parallel/test-node-output-eval.mjs:26:7) at async Test.run (node:internal/test_runner/test:632:9) at async Promise.all (index 0) at async Suite.run (node:internal/test_runner/test:948:7) at async startSubtest (node:internal/test_runner/harness:216:3) { generatedMessage: true, code: 'ERR_ASSERTION', actual: '[eval]\n[eval]:1\nwith(this){__filename}\n^^^^\n\nSyntaxError: Strict mode code may not include a with statement\n at makeContextifyScript (node:internal/vm:*:*)\n at node:internal/process/execution:*:*\n at [eval]-wrapper:*:*\n at runScript (node:internal/process/execution:*:*)\n...', expected: '[eval]\n[eval]:1\nwith(this){__filename}\n^^^^\n\nSyntaxError: Strict mode code may not include a with statement\n at new Script (node:vm:*:*)\n at createScript (node:vm:*:*)\n at Object.runInThisContext (node:vm:*:*)\n at node:internal/process/execution:*:*\n...', operator: 'strictEqual' } ::debug::starting to run eval/eval_messages.js ::error title=eval/eval_messages.js,file=test/parallel/test-node-output-eval.mjs,line=26,col=7::Error [ERR_TEST_FAILURE]: Expected values to be strictly equal: + actual - expected ... Lines skipped '[eval]\n' + '[eval]:1\n' + ... '\n' + 'SyntaxError: Strict mode code may not include a with statement\n' + + ' at makeContextifyScript (node:internal/vm:*:*)\n' + + '
});
}
});

0 comments on commit d2536ce

Please sign in to comment.