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 2023-10-31 01:08:25 -04:00 committed by Antoine du Hamel
parent 8319dc6bc5
commit 6ae9950f08
No known key found for this signature in database
GPG Key ID: 21D900FFDB233756
7 changed files with 201 additions and 168 deletions

View File

@ -21,7 +21,7 @@
'use strict';
require('../common');
require('../../common');
const spawn = require('child_process').spawn;

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

View File

@ -21,7 +21,7 @@
'use strict';
require('../common');
require('../../common');
const spawn = require('child_process').spawn;

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

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

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

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);
});
}
});