Skip to content

Commit 0302cad

Browse files
committed
test: add smoke tests for defer importing synthetic modules
The tests added ensure that Node.js doesn't crash or produce incorrect results when importing synthetic modules (i.e. JSON, text or builtin modules) with the `defer` modifier. Signed-off-by: Maya Lekova <maya@igalia.com>
1 parent 46a7dbd commit 0302cad

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Flags: js-defer-import-eval --experimental-import-text
2+
3+
// Test that uses import.defer for a builtin module. Currently
4+
// defer importing of a synthetic module should be a no-op
5+
// in Node.js, so the test is mostly a smoke test that Node
6+
// doesn't crash.
7+
8+
import '../common/index.mjs';
9+
import * as assert from 'assert';
10+
11+
// Import the file system builtin module.
12+
import defer * as fs from 'node:fs';
13+
14+
// Check that the imported module contains some known properties.
15+
assert.notStrictEqual(fs.constants, undefined);
16+
assert.notStrictEqual(fs.access, undefined);
17+
assert.strictEqual(typeof fs.access, 'function');
18+
19+
// Check that the builtin module also exports some
20+
// usable contructor functions.
21+
assert.strictEqual(typeof fs.Stats, 'function');
22+
assert.strictEqual(typeof new fs.Stats(), 'object');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Flags: --js-defer-import-eval
2+
3+
// Test that uses import.defer for a JSON module. Currently
4+
// defer importing of a synthetic module should be a no-op
5+
// in Node.js, so the test is mostly a smoke test that Node
6+
// doesn't crash.
7+
8+
import '../common/index.mjs';
9+
import * as assert from 'assert';
10+
11+
import defer * as imported_json
12+
from '../fixtures/json-with-directory-name-module/module-stub.json'
13+
with { type: 'json' };
14+
15+
// Check that the imported object has the expected key/value.
16+
assert.strictEqual(imported_json.default.rocko, 'artischocko');
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Flags: --js-defer-import-eval --experimental-import-text
2+
3+
// Test that uses import.defer for a text module. Currently
4+
// defer importing of a synthetic module should be a no-op
5+
// in Node.js, so the test is mostly a smoke test that Node
6+
// doesn't crash.
7+
8+
import '../common/index.mjs';
9+
import * as assert from 'assert';
10+
11+
import defer * as imported_text
12+
from '../fixtures/file-to-read-without-bom.txt'
13+
with { type: 'text' };
14+
15+
const expected_text = 'abc\ndef\nghi\n';
16+
17+
// Check that the imported text has the expected value.
18+
assert.strictEqual(imported_text.default, expected_text);

0 commit comments

Comments
 (0)