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

Better ESM support #1728

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions src/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export default function exportQUnit (QUnit) {

Copy link
Member

Choose a reason for hiding this comment

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

Do you know what it is about module.exports = QUnit; that doesn't work for ESM compat layers? It seems odd to assign module.exports = QUnit; but then (seemingly redundantly) also assign module.exports.test = QUnit.test; to itself. If the transformation layers are based on static analysis, that would explain it, but I thought they were runtime based?

Copy link
Contributor Author

@NullVoxPopuli NullVoxPopuli Oct 15, 2023

Choose a reason for hiding this comment

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

maybe. as I dug in to this, I think it'd be better to have actual separate builds -- and we're already in a good spot since it seems QUnit is written in ESM -- so we'd just emit a new bundle and wire up package.json#exports so that the import/require/etc are routed correctly.

related questions:

// For consistency with CommonJS environments' exports
module.exports.QUnit = QUnit;
// For allowing ESM imports
module.exports.todo = QUnit.todo;
module.exports.skip = QUnit.skip;
module.exports.test = QUnit.test;
module.exports.module = QUnit.module;

exportedModule = true;
}
Expand Down
7 changes: 7 additions & 0 deletions test/es2018/explicit-imports.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { module, test } from 'qunit';

module('ESM test suite', () => {
test('imports worked', function (assert) {
assert.true(true, 'an assertion');
});
});