Skip to content

Commit d2536ce

Browse files
author
Yiyun Lei
committed
test: migrate message eval tests from Python to JS
Migrate the eval tests in the `test/message` folder from Python to JS.
1 parent aa4248d commit d2536ce

File tree

5 files changed

+59
-26
lines changed

5 files changed

+59
-26
lines changed

test/message/eval_messages.js renamed to test/fixtures/eval/eval_messages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
'use strict';
2323

24-
require('../common');
24+
require('../../common');
2525

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

test/message/eval_messages.out renamed to test/fixtures/eval/eval_messages.snapshot

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ with(this){__filename}
44
^^^^
55

66
SyntaxError: Strict mode code may not include a with statement
7-
at makeContextifyScript (node:internal/vm:*:*)
7+
at new Script (node:vm:*:*)
8+
at createScript (node:vm:*:*)
9+
at Object.runInThisContext (node:vm:*:*)
810
at node:internal/process/execution:*:*
911
at [eval]-wrapper:*:*
1012
at runScript (node:internal/process/execution:*:*)
@@ -19,23 +21,24 @@ throw new Error("hello")
1921
^
2022

2123
Error: hello
22-
at [eval]:1:7
23-
at runScriptInThisContext (node:internal/vm:*:*)
24+
at [eval]:*:*
25+
at Script.runInThisContext (node:vm:*:*)
26+
at Object.runInThisContext (node:vm:*:*)
2427
at node:internal/process/execution:*:*
2528
at [eval]-wrapper:*:*
2629
at runScript (node:internal/process/execution:*:*)
2730
at evalScript (node:internal/process/execution:*:*)
2831
at node:internal/main/eval_string:*:*
2932

3033
Node.js *
31-
3234
[eval]:1
3335
throw new Error("hello")
3436
^
3537

3638
Error: hello
37-
at [eval]:1:7
38-
at runScriptInThisContext (node:internal/vm:*:*)
39+
at [eval]:*:*
40+
at Script.runInThisContext (node:vm:*:*)
41+
at Object.runInThisContext (node:vm:*:*)
3942
at node:internal/process/execution:*:*
4043
at [eval]-wrapper:*:*
4144
at runScript (node:internal/process/execution:*:*)
@@ -49,8 +52,9 @@ var x = 100; y = x;
4952
^
5053

5154
ReferenceError: y is not defined
52-
at [eval]:1:16
53-
at runScriptInThisContext (node:internal/vm:*:*)
55+
at [eval]:*:*
56+
at Script.runInThisContext (node:vm:*:*)
57+
at Object.runInThisContext (node:vm:*:*)
5458
at node:internal/process/execution:*:*
5559
at [eval]-wrapper:*:*
5660
at runScript (node:internal/process/execution:*:*)
@@ -63,15 +67,15 @@ Node.js *
6367
var ______________________________________________; throw 10
6468
^
6569
10
66-
(Use `* --trace-uncaught ...` to show where the exception was thrown)
70+
(Use `node --trace-uncaught ...` to show where the exception was thrown)
6771

6872
Node.js *
6973

7074
[eval]:1
7175
var ______________________________________________; throw 10
7276
^
7377
10
74-
(Use `* --trace-uncaught ...` to show where the exception was thrown)
78+
(Use `node --trace-uncaught ...` to show where the exception was thrown)
7579

7680
Node.js *
7781
done

test/message/stdin_messages.js renamed to test/fixtures/eval/stdin_messages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
'use strict';
2323

24-
require('../common');
24+
require('../../common');
2525

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

test/message/stdin_messages.out renamed to test/fixtures/eval/stdin_messages.snapshot

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ with(this){__filename}
44
^^^^
55

66
SyntaxError: Strict mode code may not include a with statement
7-
at makeContextifyScript (node:internal/vm:*:*)
7+
at new Script (node:vm:*:*)
8+
at createScript (node:vm:*:*)
9+
at Object.runInThisContext (node:vm:*:*)
810
at node:internal/process/execution:*:*
911
at [stdin]-wrapper:*:*
1012
at runScript (node:internal/process/execution:*:*)
1113
at evalScript (node:internal/process/execution:*:*)
1214
at node:internal/main/eval_stdin:*:*
1315
at Socket.<anonymous> (node:internal/process/execution:*:*)
1416
at Socket.emit (node:events:*:*)
15-
at endReadableNT (node:internal/streams/readable:*:*)
16-
at process.processTicksAndRejections (node:internal/process/task_queues:*:*)
1717

1818
Node.js *
1919
42
@@ -23,33 +23,33 @@ throw new Error("hello")
2323
^
2424

2525
Error: hello
26-
at [stdin]:1:7
27-
at runScriptInThisContext (node:internal/vm:*:*)
26+
at [stdin]:*:*
27+
at Script.runInThisContext (node:vm:*:*)
28+
at Object.runInThisContext (node:vm:*:*)
2829
at node:internal/process/execution:*:*
2930
at [stdin]-wrapper:*:*
3031
at runScript (node:internal/process/execution:*:*)
3132
at evalScript (node:internal/process/execution:*:*)
3233
at node:internal/main/eval_stdin:*:*
3334
at Socket.<anonymous> (node:internal/process/execution:*:*)
3435
at Socket.emit (node:events:*:*)
35-
at endReadableNT (node:internal/streams/readable:*:*)
3636

3737
Node.js *
3838
[stdin]:1
3939
throw new Error("hello")
4040
^
4141

4242
Error: hello
43-
at [stdin]:1:*
44-
at runScriptInThisContext (node:internal/vm:*:*)
43+
at [stdin]:*:*
44+
at Script.runInThisContext (node:vm:*:*)
45+
at Object.runInThisContext (node:vm:*:*)
4546
at node:internal/process/execution:*:*
4647
at [stdin]-wrapper:*:*
4748
at runScript (node:internal/process/execution:*:*)
4849
at evalScript (node:internal/process/execution:*:*)
4950
at node:internal/main/eval_stdin:*:*
5051
at Socket.<anonymous> (node:internal/process/execution:*:*)
5152
at Socket.emit (node:events:*:*)
52-
at endReadableNT (node:internal/streams/readable:*:*)
5353

5454
Node.js *
5555
100
@@ -58,32 +58,32 @@ let x = 100; y = x;
5858
^
5959

6060
ReferenceError: y is not defined
61-
at [stdin]:1:16
62-
at runScriptInThisContext (node:internal/vm:*:*)
61+
at [stdin]:*:*
62+
at Script.runInThisContext (node:vm:*:*)
63+
at Object.runInThisContext (node:vm:*:*)
6364
at node:internal/process/execution:*:*
6465
at [stdin]-wrapper:*:*
6566
at runScript (node:internal/process/execution:*:*)
6667
at evalScript (node:internal/process/execution:*:*)
6768
at node:internal/main/eval_stdin:*:*
6869
at Socket.<anonymous> (node:internal/process/execution:*:*)
6970
at Socket.emit (node:events:*:*)
70-
at endReadableNT (node:internal/streams/readable:*:*)
7171

7272
Node.js *
7373

7474
[stdin]:1
7575
let ______________________________________________; throw 10
7676
^
7777
10
78-
(Use `* --trace-uncaught ...` to show where the exception was thrown)
78+
(Use `node --trace-uncaught ...` to show where the exception was thrown)
7979

8080
Node.js *
8181

8282
[stdin]:1
8383
let ______________________________________________; throw 10
8484
^
8585
10
86-
(Use `* --trace-uncaught ...` to show where the exception was thrown)
86+
(Use `node --trace-uncaught ...` to show where the exception was thrown)
8787

8888
Node.js *
8989
done
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import '../common/index.mjs';
2+
import * as fixtures from '../common/fixtures.mjs';
3+
import * as snapshot from '../common/assertSnapshot.js';
4+
import { describe, it } from 'node:test';
5+
6+
describe('eval output', { concurrency: true }, () => {
7+
function normalize(str) {
8+
return str.replaceAll(snapshot.replaceWindowsPaths(process.cwd()), '')
9+
.replaceAll(/\d+:\d+/g, '*:*');
10+
}
11+
12+
const defaultTransform = snapshot.transform(
13+
normalize,
14+
snapshot.replaceWindowsLineEndings,
15+
snapshot.replaceWindowsPaths,
16+
snapshot.replaceNodeVersion
17+
);
18+
19+
const tests = [
20+
{ name: 'eval/eval_messages.js' },
21+
{ name: 'eval/stdin_messages.js' },
22+
];
23+
24+
for (const { name } of tests) {
25+
it(name, async () => {
26+
await snapshot.spawnAndAssert(fixtures.path(name), defaultTransform);
27+
});
28+
}
29+
});

0 commit comments

Comments
 (0)