Skip to content

Commit

Permalink
fix: es6 module import (#3858)
Browse files Browse the repository at this point in the history
  • Loading branch information
ert78gb authored Aug 9, 2023
1 parent e33361c commit 46e6e12
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/src/utils/__data__/meaning-of-life.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 42;
1 change: 1 addition & 0 deletions test/src/utils/__data__/meaning-of-life.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 42;
21 changes: 21 additions & 0 deletions test/src/utils/testRequireModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const {strict: assert} = require('node:assert');
const path = require('node:path');

const common = require('../../common.js');
const requireModule = common.require('utils/requireModule.js');

describe('test requireModule', function () {
it('should load commonjs file', function () {
const modulePath = path.join(__dirname, './__data__/meaning-of-life.js');
const meaningOfLife = requireModule(modulePath);

assert.equal(meaningOfLife, 42);
});

it('should load es6 module', async function () {
const modulePath = path.join(__dirname, './__data__/meaning-of-life.mjs');
const meaningOfLife = await requireModule(modulePath);

assert.equal(meaningOfLife, 42);
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */

/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"module": "node16", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
Expand Down

0 comments on commit 46e6e12

Please sign in to comment.