test: migrate message eval tests from Python to JS

Migrate the eval tests in the `test/message` folder from Python to JS.

PR-URL: https://github.com/nodejs/node/pull/50482
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
This commit is contained in:
Yiyun Lei authored and Antoine du Hamel committed 2025-01-02 15:28:13 +01:00
1 parent eaefd90128
commit d4404f0d0e
7 files changed
+201 -168

No files matched your search

@@ -21,7 +21,7 @@
'use strict';
require('../common');
require('../../common');
const spawn = require('child_process').spawn;
+76
View File
@@ -0,0 +1,76 @@
[eval]
[eval]:1
with(this){__filename}
^^^^
SyntaxError: Strict mode code may not include a with statement
Node.js *
42
42
[eval]:1
throw new Error("hello")
^
Error: hello
Node.js *
[eval]:1
throw new Error("hello")
^
Error: hello
Node.js *
100
[eval]:1
var x = 100; y = x;
^
ReferenceError: y is not defined
Node.js *
[eval]:1
var ______________________________________________; throw 10
^
10
(Use `node --trace-uncaught ...` to show where the exception was thrown)
Node.js *
[eval]:1
var ______________________________________________; throw 10
^
10
(Use `node --trace-uncaught ...` to show where the exception was thrown)
Node.js *
done
@@ -21,7 +21,7 @@
'use strict';
require('../common');
require('../../common');
const spawn = require('child_process').spawn;
+89
View File
@@ -0,0 +1,89 @@
[stdin]
[stdin]:1
with(this){__filename}
^^^^
SyntaxError: Strict mode code may not include a with statement
Node.js *
42
42
[stdin]:1
throw new Error("hello")
^
Error: hello
Node.js *
[stdin]:1
throw new Error("hello")
^
Error: hello
Node.js *
100
[stdin]:1
let x = 100; y = x;
^
ReferenceError: y is not defined
Node.js *
[stdin]:1
let ______________________________________________; throw 10
^
10
(Use `node --trace-uncaught ...` to show where the exception was thrown)
Node.js *
[stdin]:1
let ______________________________________________; throw 10
^
10
(Use `node --trace-uncaught ...` to show where the exception was thrown)
Node.js *
done
-77
View File
@@ -1,77 +0,0 @@
[eval]
[eval]:1
with(this){__filename}
^^^^
SyntaxError: Strict mode code may not include a with statement
at makeContextifyScript (node:internal/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 *
42
42
[eval]:1
throw new Error("hello")
^
Error: hello
at [eval]:1:7
at runScriptInThisContext (node:internal/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 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 *
100
[eval]:1
var x = 100; y = x;
^
ReferenceError: y is not defined
at [eval]:1:16
at runScriptInThisContext (node:internal/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
var ______________________________________________; throw 10
^
10
(Use `* --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)
Node.js *
done
-89
View File
@@ -1,89 +0,0 @@
[stdin]
[stdin]:1
with(this){__filename}
^^^^
SyntaxError: Strict mode code may not include a with statement
at makeContextifyScript (node:internal/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
42
[stdin]:1
throw new Error("hello")
^
Error: hello
at [stdin]:1:7
at runScriptInThisContext (node:internal/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 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
[stdin]:1
let x = 100; y = x;
^
ReferenceError: y is not defined
at [stdin]:1:16
at runScriptInThisContext (node:internal/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)
Node.js *
[stdin]:1
let ______________________________________________; throw 10
^
10
(Use `* --trace-uncaught ...` to show where the exception was thrown)
Node.js *
done
+34
View File
@@ -0,0 +1,34 @@
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(
removeStackTraces,
normalize,
snapshot.replaceWindowsLineEndings,
snapshot.replaceWindowsPaths,
snapshot.replaceNodeVersion
);
function removeStackTraces(output) {
return output.replaceAll(/^ *at .+$/gm, '');
}
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);
});
}
});