-
-
Notifications
You must be signed in to change notification settings - Fork 38k
test: add smoke tests for defer importing synthetic modules #65537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MayaLekova
wants to merge
1
commit into
nodejs:main
Choose a base branch
from
MayaLekova:import-defer-05-synthetic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+77
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,29 @@ | ||
| // Flags: --js-defer-import-eval --expose-internals | ||
|
|
||
| // Test that uses import.defer for a builtin module. Currently | ||
| // defer importing of a synthetic module should be a no-op | ||
| // in Node.js as they are born pre-evaluated, so the test | ||
| // is mostly a smoke test that Node doesn't crash. | ||
|
|
||
| // TODO: after deferring the evaluation of builtin modules | ||
| // is implemented, accessing any property from it will | ||
| // trigger the evaluation. | ||
|
|
||
| import '../common/index.mjs'; | ||
| import * as assert from 'assert'; | ||
|
|
||
| // Check that there are no modules with 'http' in their name loaded yet. | ||
| let modules = process.moduleLoadList.filter((item) => item.endsWith('http')); | ||
| assert.strictEqual(modules.length, 0); | ||
|
|
||
| const intermediate = await import('../fixtures/es-modules/import-builtin-module-intermediate.mjs'); | ||
|
|
||
| // Check that after dynamically importing the module with imports 'http' | ||
| // itself, the builtin module is already present in the module list. | ||
| modules = process.moduleLoadList.filter((item) => item.endsWith('http')); | ||
| assert.partialDeepStrictEqual(modules, ['NativeModule http']); | ||
|
|
||
| // Check that the imported module contains some known properties. | ||
| assert.notStrictEqual(intermediate.http.STATUS_CODES, undefined); | ||
| assert.notStrictEqual(intermediate.http.createServer, undefined); | ||
| assert.strictEqual(typeof intermediate.http.createServer, 'function'); | ||
This file contains hidden or 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,22 @@ | ||
| // 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' }; | ||
|
|
||
| // eslint-disable-next-line no-duplicate-imports | ||
| import * as imported_json_eager | ||
| 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'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also test that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, added such check. |
||
| assert.deepStrictEqual(imported_json_eager.default, imported_json.default); | ||
This file contains hidden or 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 @@ | ||
| // 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); |
8 changes: 8 additions & 0 deletions
8
test/fixtures/es-modules/import-builtin-module-intermediate.mjs
This file contains hidden or 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,8 @@ | ||
| // This module uses import.defer to import the http builtin module. | ||
| // It's dynamically imported by a test module, to ensure the HTTP | ||
| // module is actually present in the module list after importing | ||
| // this middle module. | ||
|
|
||
| // Import the http builtin module and export all its properties. | ||
| import defer * as http from 'node:http'; | ||
| export { http }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.