Skip to content

Commit

Permalink
fix: automatic import of ember-qunit in ember-mocha projects
Browse files Browse the repository at this point in the history
  • Loading branch information
ndekeister-us committed Dec 24, 2021
1 parent bf69ef6 commit 71dbb4e
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,35 @@ module.exports = {
this._super.init.apply(this, arguments);
let versionChecker = new VersionChecker(this.project);

const hasMagicallyProvidedQUnit = versionChecker
.for('ember-qunit')
.lt('5.0.0-beta.1');

let options = {
exclude: ['ember-mocha', 'mocha'],
};

// Ember-qunit < 5 provides an AMD shim for qunit but newer versions now use
// ember-auto-import to include qunit. This means that qunit is no
// longer available for addons (if the parent app is using ember-qunit > 5) to
// directly import under embroider unless they are using ember-auto-import
// themselves. This condidionally falls back to not using ember-auto-import
// when the parent app is providing qunit because without this we would double
// include qunit resulting in a runtime error (qunit detects if it as
// already be added to the window object and errors if so).
if (hasMagicallyProvidedQUnit) {
this.options = this.options || {};
options.exclude.push('qunit');
this.options.autoImport = options;
const hasEmberMocha = versionChecker.for('ember-mocha').exists();

if (hasEmberMocha) {
// Exclude automatic import for ember-qunit and qunit when project use ember-mocha
options.exclude.push('ember-qunit', 'qunit');
} else {
this.options.autoImport = options;
const hasMagicallyProvidedQUnit = versionChecker
.for('ember-qunit')
.lt('5.0.0-beta.1');

// Ember-qunit < 5 provides an AMD shim for qunit but newer versions now use
// ember-auto-import to include qunit. This means that qunit is no
// longer available for addons (if the parent app is using ember-qunit > 5) to
// directly import under embroider unless they are using ember-auto-import
// themselves. This condidionally falls back to not using ember-auto-import
// when the parent app is providing qunit because without this we would double
// include qunit resulting in a runtime error (qunit detects if it as
// already be added to the window object and errors if so).

if (hasMagicallyProvidedQUnit) {
options.exclude.push('qunit');
}
}

this.options = this.options || {};
this.options.autoImport = options;
},
};

0 comments on commit 71dbb4e

Please sign in to comment.