test: add a simple test for import defer of a CJS module#64694
Open
MayaLekova wants to merge 1 commit into
Open
test: add a simple test for import defer of a CJS module#64694MayaLekova wants to merge 1 commit into
import defer of a CJS module#64694MayaLekova wants to merge 1 commit into
Conversation
Contributor
Author
|
@nicolo-ribaudo and @joyeecheung please take a look, thanks! |
This tests imports a CommonJS modules with the `defer` modifier. It ensures that the imported module is not evaluated before accessing properties form its exports. Signed-off-by: Maya Lekova <maya@igalia.com>
MayaLekova
force-pushed
the
import-defer-04-cjs
branch
from
July 23, 2026 10:24
de9e5ac to
2d51c34
Compare
joyeecheung
reviewed
Jul 23, 2026
Comment on lines
+22
to
+23
| assert.equal(imported.default.foo, 42); | ||
| assert.equal(imported.default.identifier, 'package-type-commonjs'); |
Member
There was a problem hiding this comment.
Suggested change
| assert.equal(imported.default.foo, 42); | |
| assert.equal(imported.default.identifier, 'package-type-commonjs'); | |
| assert.equal(imported.foo, 42); | |
| assert.deepStrictEqual(['defer-1'], globalThis.eval_list); | |
| assert.equal(imported.identifier, 'package-type-commonjs'); |
The lexer should recognize these. Also we should test that it only gets evaluated once.
| assert.equal(imported.default.identifier, 'package-type-commonjs'); | ||
|
|
||
| // Check that the module has been evaluated at this point. | ||
| assert.partialDeepStrictEqual(['defer-1'], globalThis.eval_list); |
Member
There was a problem hiding this comment.
Suggested change
| assert.partialDeepStrictEqual(['defer-1'], globalThis.eval_list); | |
| assert.deepStrictEqual(['defer-1'], globalThis.eval_list); |
It shouldn't be partial, if there are anything else, it's a bug.
joyeecheung
reviewed
Jul 23, 2026
|
|
||
| // Check that the module hasn't been evaluated yet (which is noted | ||
| // by adding a property to `globalThis.eval_list`). | ||
| assert.strictEqual(globalThis.eval_list.length, 0); |
Member
There was a problem hiding this comment.
Suggested change
| assert.strictEqual(globalThis.eval_list.length, 0); | |
| assert.deepStrictEqual(globalThis.eval_list, []); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64694 +/- ##
=======================================
Coverage 90.13% 90.13%
=======================================
Files 741 741
Lines 242106 242112 +6
Branches 45551 45595 +44
=======================================
+ Hits 218211 218221 +10
+ Misses 15430 15365 -65
- Partials 8465 8526 +61 🚀 New features to boost your workflow:
|
jasnell
reviewed
Jul 23, 2026
Comment on lines
+4
to
+6
| if (!globalThis.eval_list) { | ||
| globalThis.eval_list = []; | ||
| } |
Member
There was a problem hiding this comment.
tiniest optional nit...
globalThis.eval_list ??= ['defer-1'];
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
test: add a simple test for
import deferof a CJS moduleThis tests imports a CommonJS modules with the
defermodifier.It ensures that the imported module is not evaluated before
accessing properties form its exports.