From 6e6f6b071a7a7b42b0c9f3c14f777965208f5c9a Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Wed, 25 Dec 2024 09:31:01 +0100 Subject: [PATCH] test: add ts eval snapshots PR-URL: https://github.com/nodejs/node/pull/56358 Reviewed-By: James M Snell Reviewed-By: Yagiz Nizipli Reviewed-By: Jacob Smith --- test/fixtures/eval/eval_messages.snapshot | 5 -- test/fixtures/eval/eval_typescript.js | 25 ++++++ test/fixtures/eval/eval_typescript.snapshot | 51 ++++++++++++ test/fixtures/eval/stdin_messages.snapshot | 1 - test/fixtures/eval/stdin_typescript.snapshot | 88 -------------------- test/parallel/test-node-output-eval.mjs | 7 +- 6 files changed, 80 insertions(+), 97 deletions(-) create mode 100644 test/fixtures/eval/eval_typescript.js create mode 100644 test/fixtures/eval/eval_typescript.snapshot diff --git a/test/fixtures/eval/eval_messages.snapshot b/test/fixtures/eval/eval_messages.snapshot index 91ae27b4215626..4a29e96f9c0973 100644 --- a/test/fixtures/eval/eval_messages.snapshot +++ b/test/fixtures/eval/eval_messages.snapshot @@ -8,16 +8,11 @@ with(this){__filename} : ^^^^ `---- - Caused by: failed to parse SyntaxError: Strict mode code may not include a with statement - - - - Node.js * 42 42 diff --git a/test/fixtures/eval/eval_typescript.js b/test/fixtures/eval/eval_typescript.js new file mode 100644 index 00000000000000..2c96b66f70dde1 --- /dev/null +++ b/test/fixtures/eval/eval_typescript.js @@ -0,0 +1,25 @@ +'use strict'; + +require('../../common'); + +const spawnSync = require('child_process').spawnSync; + +const queue = [ + 'enum Foo{};', + 'throw new SyntaxError("hello")', + 'const foo;', + 'let x: number = 100;x;', + 'const foo: string = 10;', + 'function foo(){};foo(1);', + 'interface Foo{};const foo;', + 'function foo(){ await Promise.resolve(1)};', +]; + +for (const cmd of queue) { + const args = ['--disable-warning=ExperimentalWarning', '-p', cmd]; + const result = spawnSync(process.execPath, args, { + stdio: 'pipe' + }); + process.stdout.write(result.stdout); + process.stdout.write(result.stderr); +} diff --git a/test/fixtures/eval/eval_typescript.snapshot b/test/fixtures/eval/eval_typescript.snapshot new file mode 100644 index 00000000000000..b10f8d6a910e4f --- /dev/null +++ b/test/fixtures/eval/eval_typescript.snapshot @@ -0,0 +1,51 @@ +[eval]:1 +enum Foo{}; +^^^^ + x TypeScript enum is not supported in strip-only mode + ,---- + 1 | enum Foo{}; + : ^^^^^^^^^^ + `---- + +SyntaxError: Unexpected reserved word + +Node.js * +[eval]:1 +throw new SyntaxError("hello") +^ + +SyntaxError: hello + +Node.js * +[eval]:1 +const foo; + ^^^ + +SyntaxError: Missing initializer in const declaration + +Node.js * +100 +undefined +false +[eval]:1 + ;const foo; + ^^^ + +SyntaxError: Missing initializer in const declaration + +Node.js * +[eval]:1 +function foo(){ await Promise.resolve(1)}; + ^^^^^ + x await isn't allowed in non-async function + ,---- + 1 | function foo(){ await Promise.resolve(1)}; + : ^^^^^^^ + `---- + +Caused by: + failed to parse + +SyntaxError: await is only valid in async functions and the top level bodies of modules + +Node.js * diff --git a/test/fixtures/eval/stdin_messages.snapshot b/test/fixtures/eval/stdin_messages.snapshot index ff8b6a05d805cb..c2f33ba8475d07 100644 --- a/test/fixtures/eval/stdin_messages.snapshot +++ b/test/fixtures/eval/stdin_messages.snapshot @@ -8,7 +8,6 @@ with(this){__filename} : ^^^^ `---- - Caused by: failed to parse diff --git a/test/fixtures/eval/stdin_typescript.snapshot b/test/fixtures/eval/stdin_typescript.snapshot index a7c98ac932e8b0..ccae9c38ee75e0 100644 --- a/test/fixtures/eval/stdin_typescript.snapshot +++ b/test/fixtures/eval/stdin_typescript.snapshot @@ -7,17 +7,8 @@ enum Foo{}; : ^^^^^^^^^^ `---- - SyntaxError: Unexpected reserved word - - - - - - - - Node.js * [stdin]:1 enum Foo{}; @@ -28,17 +19,8 @@ enum Foo{}; : ^^^^^^^^^^ `---- - SyntaxError: Unexpected reserved word - - - - - - - - Node.js * [stdin]:1 throw new SyntaxError("hello") @@ -46,16 +28,6 @@ throw new SyntaxError("hello") SyntaxError: hello - - - - - - - - - - Node.js * [stdin]:1 throw new SyntaxError("hello") @@ -63,16 +35,6 @@ throw new SyntaxError("hello") SyntaxError: hello - - - - - - - - - - Node.js * [stdin]:1 const foo; @@ -80,14 +42,6 @@ const foo; SyntaxError: Missing initializer in const declaration - - - - - - - - Node.js * [stdin]:1 const foo; @@ -95,14 +49,6 @@ const foo; SyntaxError: Missing initializer in const declaration - - - - - - - - Node.js * 100 100 @@ -116,14 +62,6 @@ false SyntaxError: Missing initializer in const declaration - - - - - - - - Node.js * [stdin]:1 ;const foo; @@ -131,14 +69,6 @@ Node.js * SyntaxError: Missing initializer in const declaration - - - - - - - - Node.js * [stdin]:1 function foo(){ await Promise.resolve(1)}; @@ -149,20 +79,11 @@ function foo(){ await Promise.resolve(1)}; : ^^^^^^^ `---- - Caused by: failed to parse SyntaxError: await is only valid in async functions and the top level bodies of modules - - - - - - - - Node.js * [stdin]:1 function foo(){ await Promise.resolve(1)}; @@ -173,19 +94,10 @@ function foo(){ await Promise.resolve(1)}; : ^^^^^^^ `---- - Caused by: failed to parse SyntaxError: await is only valid in async functions and the top level bodies of modules - - - - - - - - Node.js * done diff --git a/test/parallel/test-node-output-eval.mjs b/test/parallel/test-node-output-eval.mjs index cd22cbfea28cd6..d8c52176b1c3c3 100644 --- a/test/parallel/test-node-output-eval.mjs +++ b/test/parallel/test-node-output-eval.mjs @@ -10,12 +10,12 @@ describe('eval output', { concurrency: true }, () => { } const defaultTransform = snapshot.transform( - removeStackTraces, - filterEmptyLines, normalize, snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, - snapshot.replaceNodeVersion + snapshot.replaceNodeVersion, + removeStackTraces, + filterEmptyLines, ); function removeStackTraces(output) { @@ -30,6 +30,7 @@ describe('eval output', { concurrency: true }, () => { { name: 'eval/eval_messages.js' }, { name: 'eval/stdin_messages.js' }, { name: 'eval/stdin_typescript.js' }, + { name: 'eval/eval_typescript.js' }, ]; for (const { name } of tests) {