-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict'; | ||
|
||
const fixtures = require('../common/fixtures'); | ||
const assert = require('assert'); | ||
const { spawnSync } = require('child_process'); | ||
|
||
{ | ||
// known limitation: | ||
// imports should not be imported when evaluating text | ||
const { status, stderr, stdout } = spawnSync( | ||
process.execPath, | ||
[ | ||
'--experimental-import', | ||
fixtures.path('es-modules', 'mjs-file.mjs'), | ||
'-e', 'console.log("log")' | ||
], | ||
{ encoding: 'utf8' }, | ||
); | ||
|
||
assert.strictEqual(status, 0); | ||
assert.strictEqual(stderr, ''); | ||
assert.strictEqual(stdout, 'log\n'); | ||
} | ||
|
||
{ | ||
const { status, stderr, stdout } = spawnSync( | ||
process.execPath, | ||
[ | ||
'--experimental-import', | ||
fixtures.path('es-modules', 'mjs-file.mjs'), | ||
fixtures.path('es-modules', 'cjs-file.cjs') | ||
], | ||
{ encoding: 'utf8' }, | ||
); | ||
|
||
assert.strictEqual(status, 0); | ||
assert.strictEqual(stderr, ''); | ||
assert.strictEqual(stdout, '.mjs file\n.cjs file\n'); | ||
} | ||
|
||
{ | ||
const { status, stderr, stdout } = spawnSync( | ||
process.execPath, | ||
[ | ||
'--experimental-import', | ||
fixtures.path('es-modules', 'mjs-file.mjs'), | ||
fixtures.path('es-modules', 'mjs-file.mjs') | ||
], | ||
{ encoding: 'utf8' }, | ||
); | ||
|
||
assert.strictEqual(status, 0); | ||
assert.strictEqual(stderr, ''); | ||
assert.strictEqual(stdout, '.mjs file\n.mjs file\n'); | ||
} | ||
|
||
{ | ||
let start = Date.now(); | ||
const { status, stderr, stdout } = spawnSync( | ||
process.execPath, | ||
[ | ||
'--experimental-import', | ||
fixtures.path('es-modules', 'esm-top-level-await.mjs'), | ||
fixtures.path('es-modules', 'print_imported.mjs') | ||
], | ||
{ encoding: 'utf8' }, | ||
); | ||
|
||
assert.strictEqual(status, 0); | ||
assert.strictEqual(stderr, ''); | ||
const output = JSON.parse(stdout); | ||
assert.ok(output.time >= start); | ||
assert.ok(output.time_async > start); | ||
assert.ok(output.time_async_delayed >= start + 100); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { setTimeout } from 'timers/promises'; | ||
|
||
export const time = Date.now(); | ||
|
||
export const time_async = await new Promise((resolve) => { | ||
process.nextTick(() => resolve(Date.now())) | ||
}) | ||
|
||
export const time_async_delayed = await new Promise(async (resolve) => { | ||
await setTimeout(100) | ||
resolve(Date.now()); | ||
}); | ||
|
||
globalThis.imported = { | ||
time, | ||
time_async, | ||
time_async_delayed | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
process.stdout.write(JSON.stringify(imported)); |