Skip to content

Commit a7d6bae

Browse files
committed
tests
1 parent ed204e6 commit a7d6bae

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed
+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
'use strict';
2+
3+
const fixtures = require('../common/fixtures');
4+
const assert = require('assert');
5+
const { spawnSync } = require('child_process');
6+
7+
{
8+
// known limitation:
9+
// imports should not be imported when evaluating text
10+
const { status, stderr, stdout } = spawnSync(
11+
process.execPath,
12+
[
13+
'--experimental-import',
14+
fixtures.path('es-modules', 'mjs-file.mjs'),
15+
'-e', 'console.log("log")'
16+
],
17+
{ encoding: 'utf8' },
18+
);
19+
20+
assert.strictEqual(status, 0);
21+
assert.strictEqual(stderr, '');
22+
assert.strictEqual(stdout, 'log\n');
23+
}
24+
25+
{
26+
const { status, stderr, stdout } = spawnSync(
27+
process.execPath,
28+
[
29+
'--experimental-import',
30+
fixtures.path('es-modules', 'mjs-file.mjs'),
31+
fixtures.path('es-modules', 'cjs-file.cjs')
32+
],
33+
{ encoding: 'utf8' },
34+
);
35+
36+
assert.strictEqual(status, 0);
37+
assert.strictEqual(stderr, '');
38+
assert.strictEqual(stdout, '.mjs file\n.cjs file\n');
39+
}
40+
41+
{
42+
const { status, stderr, stdout } = spawnSync(
43+
process.execPath,
44+
[
45+
'--experimental-import',
46+
fixtures.path('es-modules', 'mjs-file.mjs'),
47+
fixtures.path('es-modules', 'mjs-file.mjs')
48+
],
49+
{ encoding: 'utf8' },
50+
);
51+
52+
assert.strictEqual(status, 0);
53+
assert.strictEqual(stderr, '');
54+
assert.strictEqual(stdout, '.mjs file\n.mjs file\n');
55+
}
56+
57+
{
58+
let start = Date.now();
59+
const { status, stderr, stdout } = spawnSync(
60+
process.execPath,
61+
[
62+
'--experimental-import',
63+
fixtures.path('es-modules', 'esm-top-level-await.mjs'),
64+
fixtures.path('es-modules', 'print_imported.mjs')
65+
],
66+
{ encoding: 'utf8' },
67+
);
68+
69+
assert.strictEqual(status, 0);
70+
assert.strictEqual(stderr, '');
71+
const output = JSON.parse(stdout);
72+
assert.ok(output.time >= start);
73+
assert.ok(output.time_async > start);
74+
assert.ok(output.time_async_delayed >= start + 100);
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { setTimeout } from 'timers/promises';
2+
3+
export const time = Date.now();
4+
5+
export const time_async = await new Promise((resolve) => {
6+
process.nextTick(() => resolve(Date.now()))
7+
})
8+
9+
export const time_async_delayed = await new Promise(async (resolve) => {
10+
await setTimeout(100)
11+
resolve(Date.now());
12+
});
13+
14+
globalThis.imported = {
15+
time,
16+
time_async,
17+
time_async_delayed
18+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process.stdout.write(JSON.stringify(imported));

0 commit comments

Comments
 (0)