Skip to content

Commit

Permalink
esm: refactor test-esm-named-exports
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Sep 4, 2023
1 parent 47c5152 commit b9f29d0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/es-module/test-esm-named-exports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-loader ./test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs
// Flags: --import ./test/fixtures/es-module-loaders/builtin-named-exports.mjs
'use strict';

require('../common');
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-named-exports.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-loader ./test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs
// Flags: --import ./test/fixtures/es-module-loaders/builtin-named-exports.mjs
import '../common/index.mjs';
import { readFile, __fromLoader } from 'fs';
import assert from 'assert';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import module from 'module';
import module from 'node:module';
import { readFileSync } from 'node:fs';

const GET_BUILTIN = `$__get_builtin_hole_${Date.now()}`;
/** @type {string} */
let GET_BUILTIN;
export function initialize(data) {
GET_BUILTIN = data.GET_BUILTIN;
}

export function globalPreload() {
return `Object.defineProperty(globalThis, ${JSON.stringify(GET_BUILTIN)}, {
Expand Down
19 changes: 19 additions & 0 deletions test/fixtures/es-module-loaders/builtin-named-exports.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as fixtures from '../../common/fixtures.mjs';
import { createRequire, register } from 'node:module';

const require = createRequire(import.meta.url);

const GET_BUILTIN = `$__get_builtin_hole_${Date.now()}`;
Object.defineProperty(globalThis, GET_BUILTIN, {
value: (builtinName) => {
return require(builtinName);
},
enumerable: false,
configurable: false,
});

register(fixtures.fileURL('es-module-loaders/builtin-named-exports-loader.mjs'), {
data: {
GET_BUILTIN,
},
});

0 comments on commit b9f29d0

Please sign in to comment.