Skip to content

Commit

Permalink
test: add ts eval snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Dec 25, 2024
1 parent f4d892d commit 0986177
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
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 = ['--experimental-strip-types', '--disable-warning=ExperimentalWarning', '-p', cmd];
const result = spawnSync(process.execPath, args, {
stdio: 'pipe'
});
process.stdout.write(result.stdout);
process.stdout.write(result.stderr);
}
51 changes: 51 additions & 0 deletions test/fixtures/eval/eval_typescript.snapshot
Original file line number Diff line number Diff line change
@@ -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 *
1 change: 1 addition & 0 deletions test/parallel/test-node-output-eval.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('eval output', { concurrency: true }, () => {
const tests = [
{ name: 'eval/eval_messages.js' },
{ name: 'eval/stdin_messages.js' },
{ name: 'eval/eval_typescript.js' },
];

for (const { name } of tests) {
Expand Down

0 comments on commit 0986177

Please sign in to comment.