test: add smoke tests for defer importing synthetic modules · nodejs/node@19d8d19 · GitHub
Skip to content

Commit 19d8d19

Browse files
MayaLekovaaduh95
authored andcommitted
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> PR-URL: #65537 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 99a78b0 commit 19d8d19

4 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
// eslint-disable-next-line no-duplicate-imports
16+
import * as imported_json_eager
17+
from '../fixtures/json-with-directory-name-module/module-stub.json'
18+
with { type: 'json' };
19+
20+
// Check that the imported object has the expected key/value.
21+
assert.strictEqual(imported_json.default.rocko, 'artischocko');
22+
assert.deepStrictEqual(imported_json_eager.default, imported_json.default);
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);
Lines changed: 8 additions & 0 deletions

0 commit comments

Comments
 (0)