forked from qunitjs/qunit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP] Build: Adopt ESM export between core.js and qunit.js
Ref qunitjs#1551
- Loading branch information
Showing
3 changed files
with
60 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,31 @@ | ||
import QUnit from './core.js'; | ||
import * as QUnitCore from './core.js'; | ||
import { initBrowser } from './browser/browser-runner.js'; | ||
import { window, document } from './globals.js'; | ||
import { setQUnitObject } from './start.js'; | ||
import exportQUnit from './export.js'; | ||
|
||
// The imported object from core.js, per ESM/Rollup, is frozen. | ||
// We support adding and replacing QUnit methods, so wrap the exported | ||
// object in Object.create() to create writable version. The caveat is | ||
// that a monkey-patched method like QUnit.test() will be reflected in | ||
// `import QUnit from qunit.js; QUnit.test()` | ||
// the change is not visible to | ||
// `import { test } from qunit.js` | ||
// | ||
// CJS usage is unaffected since there we assign the writeable QUnit | ||
// object to module.exports. The read-only QUnitCore will only | ||
// be exposed to ESM via `export * from './core.js';` below. | ||
const QUnit = Object.create(QUnitCore); | ||
|
||
setQUnitObject(QUnit); | ||
|
||
exportQUnit(QUnit); | ||
|
||
if (window && document) { | ||
initBrowser(QUnit, window, document); | ||
} | ||
|
||
// TODO: Decide how to format the CJS and ESM distribution | ||
// in Rollup config. | ||
// export * from './core.js'; | ||
// export default QUnit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// Expose the current QUnit version | ||
// Replaced by /rollup.config.js using /build/dist-replace.js | ||
export default '@VERSION'; |