Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions test/es-module/test-defer-import-eval-with-tla.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Flags: --js-defer-import-eval

// Tests that defer import of a module with top-level await
// eagerly evaluates the imported module.

import '../common/index.mjs';
import * as assert from 'assert';

// The importing module will only execute once its dependency containing
// top-level await has its promises resolved, as per
// https://github.com/tc39/proposal-top-level-await#what-exactly-is-blocked-by-a-top-level-await
if (!globalThis.eval_list) {

Check failure on line 12 in test/es-module/test-defer-import-eval-with-tla.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'if' statement can be replaced with a logical operator assignment with operator ||=
globalThis.eval_list = [];
}

import defer * as ns from '../fixtures/es-modules/dep-module-top-level-await.mjs';

// Check that the module has already been evaluated.
assert.strictEqual(globalThis.eval_list.length, 1);
assert.strictEqual(ns.foo, 42);
assert.partialDeepStrictEqual(['defer-tla-1'], globalThis.eval_list);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also assert the length after the ns.foo access.


// Clean-up
delete globalThis.eval_list;
23 changes: 23 additions & 0 deletions test/es-module/test-defer-import-with-regular-import.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Flags: --js-defer-import-eval

// Tests that defer import of a module that is also eagerly imported
// from another dependency gets executed synchronously, and gets
// executed exactly once.

import '../common/index.mjs';
import * as assert from 'assert';

if (!globalThis.eval_list) {

Check failure on line 10 in test/es-module/test-defer-import-with-regular-import.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'if' statement can be replaced with a logical operator assignment with operator ||=
globalThis.eval_list = [];
}

import * as non_deferred from '../fixtures/es-modules/module-with-module-tree.mjs';

Check failure on line 14 in test/es-module/test-defer-import-with-regular-import.mjs

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'non_deferred' is defined but never used
import defer * as deferred from '../fixtures/es-modules/module-deferred-eval.mjs';

// Check that the module has been evaluated exactly once.
assert.strictEqual(globalThis.eval_list.length, 1);
assert.strictEqual(deferred.foo, 42);
assert.partialDeepStrictEqual(['defer-1'], globalThis.eval_list);

// Clean-up
delete globalThis.eval_list;
11 changes: 11 additions & 0 deletions test/fixtures/es-modules/dep-module-top-level-await.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { setTimeout } from 'node:timers/promises';

if (!globalThis.eval_list) {
globalThis.eval_list = [];
}
globalThis.eval_list.push('defer-tla-1');

export const foo = 42;

await setTimeout(1);
console.log('executed');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also push to eval_list rather than logging?

Loading