Skip to content

Commit

Permalink
test: add ts eval snapshots
Browse files Browse the repository at this point in the history
PR-URL: nodejs#56358
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
  • Loading branch information
marco-ippolito committed Feb 4, 2025
1 parent fce90fc commit 6366839
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 99 deletions.
7 changes: 0 additions & 7 deletions test/fixtures/eval/eval_messages.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ with(this){__filename}

SyntaxError: Strict mode code may not include a with statement








Node.js *
42
42
Expand Down
25 changes: 25 additions & 0 deletions test/fixtures/eval/eval_typescript.js
Original file line number Diff line number Diff line change
@@ -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<Number>(1);',
'interface Foo{};const foo;',
'function foo(){ await Promise.resolve(1)};',
];

for (const cmd of queue) {
const args = ['--disable-warning=ExperimentalWarning','--experimental-strip-types', '-p', cmd];
const result = spawnSync(process.execPath, args, {
stdio: 'pipe'
});
process.stdout.write(result.stdout);
process.stdout.write(result.stderr);
}
48 changes: 48 additions & 0 deletions test/fixtures/eval/eval_typescript.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[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)};
: ^^^^^^^
`----

SyntaxError: await is only valid in async functions and the top level bodies of modules

Node.js *
1 change: 0 additions & 1 deletion test/fixtures/eval/stdin_messages.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ with(this){__filename}
: ^^^^
`----


SyntaxError: Strict mode code may not include a with statement

Node.js *
Expand Down
88 changes: 0 additions & 88 deletions test/fixtures/eval/stdin_typescript.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,8 @@ enum Foo{};
: ^^^^^^^^^^
`----


SyntaxError: Unexpected reserved word









Node.js *
[stdin]:1
enum Foo{};
Expand All @@ -28,81 +19,36 @@ enum Foo{};
: ^^^^^^^^^^
`----


SyntaxError: Unexpected reserved word









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

SyntaxError: hello











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

SyntaxError: hello











Node.js *
[stdin]:1
const foo;
^^^

SyntaxError: Missing initializer in const declaration









Node.js *
[stdin]:1
const foo;
^^^

SyntaxError: Missing initializer in const declaration









Node.js *
100
100
Expand All @@ -116,29 +62,13 @@ false

SyntaxError: Missing initializer in const declaration









Node.js *
[stdin]:1
;const foo;
^^^

SyntaxError: Missing initializer in const declaration









Node.js *
[stdin]:1
function foo(){ await Promise.resolve(1)};
Expand All @@ -149,17 +79,8 @@ function foo(){ await Promise.resolve(1)};
: ^^^^^^^
`----


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)};
Expand All @@ -170,16 +91,7 @@ function foo(){ await Promise.resolve(1)};
: ^^^^^^^
`----


SyntaxError: await is only valid in async functions and the top level bodies of modules









Node.js *
done
7 changes: 4 additions & 3 deletions test/parallel/test-node-output-eval.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 6366839

Please sign in to comment.