Skip to content

Commit 7d99254

Browse files
author
Robert Jackson
authored
Merge pull request #652 from thoov/embroider-test-setup
Use @embroider/test-setup and get embroider passing
2 parents 005bba7 + 512ad87 commit 7d99254

22 files changed

Lines changed: 2160 additions & 1599 deletions

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,18 @@ jobs:
4343
- ember-default-with-jquery
4444
- ember-default-with-mocha
4545
- ember-classic
46-
- embroider
47-
- embroider-with-mocha
46+
- embroider-safe
47+
- embroider-safe-with-mocha
4848
- embroider-optimized
4949
- embroider-optimized-with-mocha
50+
- ember-lts-3.24
5051
- ember-lts-3.20
5152
- ember-lts-3.16
5253
- ember-lts-3.12
5354
- ember-release
5455
- ember-beta
5556
- ember-canary
57+
- ember-qunit-4
5658

5759
steps:
5860
- uses: actions/checkout@v2

config/ember-try.js

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
'use strict';
22

33
const getChannelURL = require('ember-source-channel-url');
4+
const { embroiderSafe, embroiderOptimized } = require('@embroider/test-setup');
5+
const mergeWith = require('lodash.mergewith');
6+
7+
function mochaScenario(scenario = {}) {
8+
return mergeWith({}, scenario, {
9+
devDependencies: {
10+
'chai-dom': '*',
11+
'ember-cli-chai': '*',
12+
'ember-mocha': '*',
13+
'ember-qunit': null
14+
}
15+
});
16+
}
417

518
const command = [
619
'ember',
@@ -34,6 +47,22 @@ module.exports = async function() {
3447
}
3548
}
3649
},
50+
{
51+
name: 'ember-lts-3.20',
52+
npm: {
53+
devDependencies: {
54+
'ember-source': '~3.20.0'
55+
}
56+
}
57+
},
58+
{
59+
name: 'ember-lts-3.24',
60+
npm: {
61+
devDependencies: {
62+
'ember-source': '~3.24.0'
63+
}
64+
}
65+
},
3766
{
3867
name: 'ember-release',
3968
npm: {
@@ -71,14 +100,9 @@ module.exports = async function() {
71100
}
72101
}
73102
},
74-
{
75-
name: 'ember-default-with-mocha',
76-
npm: {
77-
devDependencies: {
78-
'ember-mocha': '*'
79-
}
80-
}
81-
},
103+
mochaScenario({
104+
name: 'ember-default-with-mocha'
105+
}),
82106
{
83107
name: 'ember-classic',
84108
env: {
@@ -94,48 +118,26 @@ module.exports = async function() {
94118
}
95119
}
96120
},
121+
embroiderSafe(),
122+
embroiderSafe(
123+
mochaScenario({
124+
name: 'embroider-safe-with-mocha'
125+
})
126+
),
127+
embroiderOptimized(),
128+
embroiderOptimized(
129+
mochaScenario({
130+
name: 'embroider-optimized-with-mocha'
131+
})
132+
),
97133
{
98-
name: 'embroider',
134+
name: 'ember-qunit-4',
99135
npm: {
100136
devDependencies: {
101-
'@embroider/core': '*',
102-
'@embroider/webpack': '*',
103-
'@embroider/compat': '*',
104-
},
105-
},
106-
},
107-
{
108-
name: 'embroider-with-mocha',
109-
npm: {
110-
devDependencies: {
111-
'@embroider/core': '*',
112-
'@embroider/webpack': '*',
113-
'@embroider/compat': '*',
114-
'ember-mocha': '*',
115-
},
116-
},
117-
},
118-
{
119-
name: 'embroider-optimized',
120-
npm: {
121-
devDependencies: {
122-
'@embroider/core': '*',
123-
'@embroider/webpack': '*',
124-
'@embroider/compat': '*',
125-
},
137+
'ember-qunit': '^4.6.0'
138+
}
126139
}
127140
},
128-
{
129-
name: 'embroider-optimized-with-mocha',
130-
npm: {
131-
devDependencies: {
132-
'@embroider/core': '*',
133-
'@embroider/webpack': '*',
134-
'@embroider/compat': '*',
135-
'ember-mocha': '*',
136-
},
137-
}
138-
}
139141
]
140142
};
141143
};

ember-cli-build.js

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,20 @@
33
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
44

55
module.exports = function(defaults) {
6+
const self = defaults.project.findAddonByName('ember-exam');
7+
const autoImport = self.options.autoImport;
68
let app = new EmberAddon(defaults, {
7-
// Add options here
9+
autoImport
810
});
911

10-
/*
11-
This build file specifies the options for the dummy test app of this
12-
addon, located in `/tests/dummy`
13-
This build file does *not* influence how the addon or the app using it
14-
behave. You most likely want to be modifying `./index.js` or app's build file
15-
*/
16-
17-
// Use embroider if it's present (it can get added by ember-try)
18-
if ('@embroider/core' in app.dependencies()) {
19-
/* eslint-disable node/no-missing-require, node/no-extraneous-require */
20-
const { Webpack } = require('@embroider/webpack');
21-
const { compatBuild } = require('@embroider/compat');
22-
/* eslint-enable node/no-missing-require, node/no-extraneous-require */
23-
let config = {};
24-
if (process.env.EMBER_TRY_SCENARIO === 'embroider-optimized') {
25-
config = {
26-
staticAddonTrees: true,
27-
staticAddonTestSupportTrees: true,
28-
staticHelpers: true,
29-
staticComponents: true,
12+
const { maybeEmbroider } = require('@embroider/test-setup');
13+
return maybeEmbroider(app, {
14+
packagerOptions: {
15+
webpackConfig: {
16+
externals: {
17+
mocha: 'mocha'
18+
}
3019
}
3120
}
32-
return compatBuild(app, Webpack, config);
33-
} else {
34-
return app.toTree();
35-
}
21+
});
3622
};

index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,41 @@
22

33
'use strict';
44

5+
const VersionChecker = require('ember-cli-version-checker');
6+
57
module.exports = {
68
name: require('./package').name,
79

810
includedCommands() {
911
return require('./lib/commands');
12+
},
13+
14+
init() {
15+
this._super.init.apply(this, arguments);
16+
let versionChecker = new VersionChecker(this.project);
17+
18+
const hasMagicallyProvidedQUnit = versionChecker
19+
.for('ember-qunit')
20+
.lt('5.0.0-beta.1');
21+
22+
let options = {
23+
exclude: ['ember-mocha', 'mocha']
24+
};
25+
26+
// Ember-qunit < 5 provides an AMD shim for qunit but newer versions now use
27+
// ember-auto-import to include qunit. This means that qunit is no
28+
// longer available for addons (if the parent app is using ember-qunit > 5) to
29+
// directly import under embroider unless they are using ember-auto-import
30+
// themselves. This condidionally falls back to not using ember-auto-import
31+
// when the parent app is providing qunit because without this we would double
32+
// include qunit resulting in a runtime error (qunit detects if it as
33+
// already be added to the window object and errors if so).
34+
if (hasMagicallyProvidedQUnit) {
35+
this.options = this.options || {};
36+
options.exclude.push('qunit');
37+
this.options.autoImport = options;
38+
} else {
39+
this.options.autoImport = options;
40+
}
1041
}
1142
};

package.json

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@
3838
]
3939
},
4040
"dependencies": {
41-
"@embroider/macros": "^0.29.0",
41+
"@embroider/macros": "^0.36.0",
4242
"chalk": "^4.1.0",
4343
"cli-table3": "^0.6.0",
4444
"debug": "^4.2.0",
45+
"ember-auto-import": "^1.10.1",
4546
"ember-cli-babel": "^7.21.0",
47+
"ember-cli-version-checker": "^5.1.2",
4648
"execa": "^4.0.3",
4749
"fs-extra": "^9.0.1",
4850
"js-yaml": "^3.14.0",
@@ -53,6 +55,8 @@
5355
},
5456
"devDependencies": {
5557
"@ember/optional-features": "^2.0.0",
58+
"@ember/test-helpers": "^2.2.0",
59+
"@embroider/test-setup": "^0.36.0",
5660
"babel-eslint": "^10.1.0",
5761
"codeclimate-test-reporter": "^0.5.0",
5862
"ember-cli": "^3.21.2",
@@ -70,7 +74,7 @@
7074
"ember-disable-prototype-extensions": "^1.1.2",
7175
"ember-export-application-global": "^2.0.1",
7276
"ember-load-initializers": "^2.1.1",
73-
"ember-qunit": "^4.6.0",
77+
"ember-qunit": "^5.1.2",
7478
"ember-resolver": "^8.0.2",
7579
"ember-source": "~3.21.3",
7680
"ember-source-channel-url": "^1.1.0",
@@ -82,10 +86,12 @@
8286
"fixturify": "^1.2.0",
8387
"istanbul": "^0.4.3",
8488
"loader.js": "^4.7.0",
89+
"lodash.mergewith": "^4.6.2",
8590
"mocha": "^8.1.0",
8691
"mocha-eslint": "^6.0.0",
8792
"npm-run-all": "^4.1.5",
8893
"nyc": "^15.1.0",
94+
"qunit": "^2.14.0",
8995
"release-it": "^14.0.2",
9096
"release-it-lerna-changelog": "^2.4.0",
9197
"rsvp": "^4.8.5",
@@ -94,14 +100,18 @@
94100
},
95101
"peerDependencies": {
96102
"ember-mocha": "*",
97-
"ember-qunit": "*"
103+
"ember-qunit": "*",
104+
"qunit": "*"
98105
},
99106
"peerDependenciesMeta": {
100107
"ember-mocha": {
101108
"optional": true
102109
},
103110
"ember-qunit": {
104111
"optional": true
112+
},
113+
"qunit": {
114+
"optional": true
105115
}
106116
},
107117
"engines": {
@@ -132,4 +142,4 @@
132142
"node": "10.23.0",
133143
"yarn": "1.22.10"
134144
}
135-
}
145+
}

tests/dummy/config/targets.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ const browsers = [
66
'last 1 Safari versions'
77
];
88

9-
const isCI = !!process.env.CI;
10-
const isProduction = process.env.EMBER_ENV === 'production';
11-
12-
if (isCI || isProduction) {
13-
browsers.push('ie 11');
14-
}
15-
169
module.exports = {
1710
browsers
1811
};

0 commit comments

Comments
 (0)