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
25 changes: 25 additions & 0 deletions test/es-module/test-cjs-defer-static-import-eval.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Flags: --js-defer-import-eval

// Test that uses import.defer for a CJS module. It ensures that:
// 1. the module is imported successfully
// 2. it's evaluated synchronously, regardless of the `defer` modifier.

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

// Import the CJS module with the `defer` modifier.
import defer * as imported from '../fixtures/es-modules/module-cjs-deferred-eval.js';

globalThis.eval_list = [];

// Check that the exported properties are accessible and have the
// expected values.
assert.strictEqual(imported.foo, 42);
assert.strictEqual(imported.identifier, 'package-type-commonjs');

// Check that the module has been evaluated at this point,
// also that it's not evaluated more than once.
assert.deepStrictEqual(['defer-1'], globalThis.eval_list);

// Clean-up
delete globalThis.eval_list;
6 changes: 6 additions & 0 deletions test/fixtures/es-modules/module-cjs-deferred-eval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const identifier = 'package-type-commonjs';

module.exports.foo = 42;
module.exports.identifier = identifier;

globalThis.eval_list.push('defer-1');
Loading