diff --git a/test/es-module/test-defer-import-builtin-module.mjs b/test/es-module/test-defer-import-builtin-module.mjs new file mode 100644 index 000000000000..8e0800bb9dd8 --- /dev/null +++ b/test/es-module/test-defer-import-builtin-module.mjs @@ -0,0 +1,22 @@ +// Flags: --js-defer-import-eval --experimental-import-text + +// Test that uses import.defer for a builtin module. Currently +// defer importing of a synthetic module should be a no-op +// in Node.js, so the test is mostly a smoke test that Node +// doesn't crash. + +import '../common/index.mjs'; +import * as assert from 'assert'; + +// Import the file system builtin module. +import defer * as fs from 'node:fs'; + +// Check that the imported module contains some known properties. +assert.notStrictEqual(fs.constants, undefined); +assert.notStrictEqual(fs.access, undefined); +assert.strictEqual(typeof fs.access, 'function'); + +// Check that the builtin module also exports some +// usable contructor functions. +assert.strictEqual(typeof fs.Stats, 'function'); +assert.strictEqual(typeof new fs.Stats(), 'object'); diff --git a/test/es-module/test-defer-import-json-module.mjs b/test/es-module/test-defer-import-json-module.mjs new file mode 100644 index 000000000000..7bd5c44deb87 --- /dev/null +++ b/test/es-module/test-defer-import-json-module.mjs @@ -0,0 +1,16 @@ +// Flags: --js-defer-import-eval + +// Test that uses import.defer for a JSON module. Currently +// defer importing of a synthetic module should be a no-op +// in Node.js, so the test is mostly a smoke test that Node +// doesn't crash. + +import '../common/index.mjs'; +import * as assert from 'assert'; + +import defer * as imported_json + from '../fixtures/json-with-directory-name-module/module-stub.json' + with { type: 'json' }; + +// Check that the imported object has the expected key/value. +assert.strictEqual(imported_json.default.rocko, 'artischocko'); diff --git a/test/es-module/test-defer-import-text-module.mjs b/test/es-module/test-defer-import-text-module.mjs new file mode 100644 index 000000000000..e6710d72fd73 --- /dev/null +++ b/test/es-module/test-defer-import-text-module.mjs @@ -0,0 +1,18 @@ +// Flags: --js-defer-import-eval --experimental-import-text + +// Test that uses import.defer for a text module. Currently +// defer importing of a synthetic module should be a no-op +// in Node.js, so the test is mostly a smoke test that Node +// doesn't crash. + +import '../common/index.mjs'; +import * as assert from 'assert'; + +import defer * as imported_text + from '../fixtures/file-to-read-without-bom.txt' + with { type: 'text' }; + +const expected_text = 'abc\ndef\nghi\n'; + +// Check that the imported text has the expected value. +assert.strictEqual(imported_text.default, expected_text);