Skip to content

Commit

Permalink
test: migrate message eval tests from Python to JS
Browse files Browse the repository at this point in the history
Migrate the eval tests in the `test/message` folder from Python to JS.
  • Loading branch information
yiyunlei authored and marco-ippolito committed Dec 24, 2024
1 parent 81f7c76 commit 965ba46
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

require('../common');
require('../../common');

const spawn = require('child_process').spawn;

Expand Down
76 changes: 76 additions & 0 deletions test/fixtures/eval/eval_messages.snapshot
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

'use strict';

require('../common');
require('../../common');

const spawn = require('child_process').spawn;

Expand Down
89 changes: 89 additions & 0 deletions test/fixtures/eval/stdin_messages.snapshot
Original file line number Diff line number Diff line change
@@ -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
77 changes: 0 additions & 77 deletions test/message/eval_messages.out

This file was deleted.

89 changes: 0 additions & 89 deletions test/message/stdin_messages.out

This file was deleted.

34 changes: 34 additions & 0 deletions test/parallel/test-node-output-eval.mjs
Original file line number Diff line number Diff line change
@@ -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);
});
}
});

0 comments on commit 965ba46

Please sign in to comment.