From a9e65f61d4488b868a38dd8ae95d4a0d8cb7b8f0 Mon Sep 17 00:00:00 2001 From: Yiyun Lei Date: Tue, 31 Oct 2023 01:08:25 -0400 Subject: [PATCH] test: migrate message eval tests from Python to JS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../eval}/eval_messages.js | 2 +- test/fixtures/eval/eval_messages.snapshot | 76 ++++++++++++++++ .../eval}/stdin_messages.js | 2 +- test/fixtures/eval/stdin_messages.snapshot | 89 +++++++++++++++++++ test/message/eval_messages.out | 77 ---------------- test/message/stdin_messages.out | 89 ------------------- test/parallel/test-node-output-eval.mjs | 34 +++++++ 7 files changed, 201 insertions(+), 168 deletions(-) rename test/{message => fixtures/eval}/eval_messages.js (98%) create mode 100644 test/fixtures/eval/eval_messages.snapshot rename test/{message => fixtures/eval}/stdin_messages.js (98%) create mode 100644 test/fixtures/eval/stdin_messages.snapshot delete mode 100644 test/message/eval_messages.out delete mode 100644 test/message/stdin_messages.out create mode 100644 test/parallel/test-node-output-eval.mjs diff --git a/test/message/eval_messages.js b/test/fixtures/eval/eval_messages.js similarity index 98% rename from test/message/eval_messages.js rename to test/fixtures/eval/eval_messages.js index 69dcbd6efa23a7..171bff06b8d6e9 100644 --- a/test/message/eval_messages.js +++ b/test/fixtures/eval/eval_messages.js @@ -21,7 +21,7 @@ 'use strict'; -require('../common'); +require('../../common'); const spawn = require('child_process').spawn; diff --git a/test/fixtures/eval/eval_messages.snapshot b/test/fixtures/eval/eval_messages.snapshot new file mode 100644 index 00000000000000..6a37ad22634617 --- /dev/null +++ b/test/fixtures/eval/eval_messages.snapshot @@ -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 diff --git a/test/message/stdin_messages.js b/test/fixtures/eval/stdin_messages.js similarity index 98% rename from test/message/stdin_messages.js rename to test/fixtures/eval/stdin_messages.js index 79475bd4d217b6..874b473be38e00 100644 --- a/test/message/stdin_messages.js +++ b/test/fixtures/eval/stdin_messages.js @@ -21,7 +21,7 @@ 'use strict'; -require('../common'); +require('../../common'); const spawn = require('child_process').spawn; diff --git a/test/fixtures/eval/stdin_messages.snapshot b/test/fixtures/eval/stdin_messages.snapshot new file mode 100644 index 00000000000000..3c03bd64072061 --- /dev/null +++ b/test/fixtures/eval/stdin_messages.snapshot @@ -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 diff --git a/test/message/eval_messages.out b/test/message/eval_messages.out deleted file mode 100644 index e07bbe4d6acd3c..00000000000000 --- a/test/message/eval_messages.out +++ /dev/null @@ -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 diff --git a/test/message/stdin_messages.out b/test/message/stdin_messages.out deleted file mode 100644 index 6afc8a62d7fcd9..00000000000000 --- a/test/message/stdin_messages.out +++ /dev/null @@ -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. (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. (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. (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. (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 diff --git a/test/parallel/test-node-output-eval.mjs b/test/parallel/test-node-output-eval.mjs new file mode 100644 index 00000000000000..2fa60206e1ea1c --- /dev/null +++ b/test/parallel/test-node-output-eval.mjs @@ -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); + }); + } +});