Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: es6 module import #3858

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
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;
20 changes: 20 additions & 0 deletions test/src/utils/testRequireModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const {strict: assert} = require('node:assert');
const path = require('node:path');

const requireModule = require('../../../dist/utils/requireModule.js');
gravityvi marked this conversation as resolved.
Show resolved Hide resolved

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