Skip to content

Commit d8f07ea

Browse files
committed
Use embroider macros to support staticAddonTestSupportTrees
1 parent d493bdc commit d8f07ea

13 files changed

+2121
-927
lines changed

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ jobs:
4646
- env: EMBER_TRY_SCENARIO=ember-canary TEST_FRAMEWORK=ember-mocha
4747
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery TEST_FRAMEWORK=ember-qunit
4848
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery TEST_FRAMEWORK=ember-mocha
49+
- env: EMBER_TRY_SCENARIO=embroider TEST_FRAMEWORK=ember-qunit
50+
- env: EMBER_TRY_SCENARIO=embroider TEST_FRAMEWORK=ember-mocha
51+
- env: EMBER_TRY_SCENARIO=embroider-optimized TEST_FRAMEWORK=ember-qunit
52+
- env: EMBER_TRY_SCENARIO=embroider-optimized TEST_FRAMEWORK=ember-mocha
4953

5054
before_install:
5155
- curl -o- -L https://yarnpkg.com/install.sh | bash

addon-test-support/-private/get-test-loader.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* globals require, requirejs */
1+
import { dependencySatisfies, macroCondition, importSync } from '@embroider/macros';
22

33
/**
44
* Returns ember-exam-qunit-test-loader or ember-exam-mocha-test-loader
@@ -8,11 +8,11 @@
88
* @return {Object}
99
*/
1010
export default function getTestLoader() {
11-
if (requirejs.entries['ember-qunit/test-loader']) {
12-
const EmberExamQUnitTestLoader = require('./ember-exam-qunit-test-loader');
11+
if (macroCondition(dependencySatisfies('ember-qunit', '*'))){
12+
const EmberExamQUnitTestLoader = importSync('./ember-exam-qunit-test-loader');
1313
return EmberExamQUnitTestLoader['default'];
14-
} else if (requirejs.entries['ember-mocha/test-loader']) {
15-
const EmberExamMochaTestLoader = require('./ember-exam-mocha-test-loader');
14+
} else if (macroCondition(dependencySatisfies('ember-mocha', '*'))){
15+
const EmberExamMochaTestLoader = importSync('./ember-exam-mocha-test-loader');
1616
return EmberExamMochaTestLoader['default'];
1717
}
1818

addon-test-support/start.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/* globals require */
2-
31
import loadEmberExam from 'ember-exam/test-support/load';
2+
import { dependencySatisfies, macroCondition, importSync } from '@embroider/macros';
43

54
/**
65
* Equivalent to ember-qunit or ember-mocha's loadTest() except this does not create a new TestLoader instance
@@ -26,14 +25,18 @@ function loadTests(testLoader) {
2625
* @param {*} qunitOptions
2726
*/
2827
export default function start(qunitOptions) {
29-
const framework = require.has('ember-qunit') ? 'qunit' : 'mocha';
3028
const modifiedOptions = qunitOptions || Object.create(null);
3129
modifiedOptions.loadTests = false;
3230

3331
const testLoader = loadEmberExam();
3432
loadTests(testLoader);
3533

36-
const emberTestFramework = require(`ember-${framework}`);
34+
let emberTestFramework;
35+
if (macroCondition(dependencySatisfies('ember-qunit', '*'))){
36+
emberTestFramework = importSync('ember-qunit');
37+
} else if (macroCondition(dependencySatisfies('ember-mocha', '*'))) {
38+
emberTestFramework = importSync('ember-mocha');
39+
}
3740

3841
if (emberTestFramework.start) {
3942
emberTestFramework.start(modifiedOptions);

config/ember-try.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,27 @@ module.exports = function() {
8989
'@ember/jquery': '^0.5.1'
9090
}
9191
}
92-
}
92+
},
93+
{
94+
name: 'embroider',
95+
npm: {
96+
devDependencies: {
97+
'@embroider/core': '*',
98+
'@embroider/webpack': '*',
99+
'@embroider/compat': '*',
100+
},
101+
},
102+
},
103+
{
104+
name: 'embroider-optimized',
105+
npm: {
106+
devDependencies: {
107+
'@embroider/core': '*',
108+
'@embroider/webpack': '*',
109+
'@embroider/compat': '*',
110+
},
111+
}
112+
},
93113
]
94114
};
95115
});

ember-cli-build.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,23 @@ module.exports = function(defaults) {
1414
behave. You most likely want to be modifying `./index.js` or app's build file
1515
*/
1616

17-
return app.toTree();
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,
30+
}
31+
}
32+
return compatBuild(app, Webpack, config);
33+
} else {
34+
return app.toTree();
35+
}
1836
};

package.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"coverage": "nyc report --reporter=text-lcov | codeclimate-test-reporter"
2727
},
2828
"dependencies": {
29+
"@embroider/macros": "^0.25.0",
2930
"chalk": "^4.1.0",
3031
"cli-table3": "^0.6.0",
3132
"debug": "^4.1.0",
@@ -42,7 +43,7 @@
4243
"@ember/optional-features": "^1.1.0",
4344
"codeclimate-test-reporter": "^0.5.0",
4445
"ember-cli": "^3.19.0",
45-
"ember-cli-addon-docs": "^0.6.15",
46+
"ember-cli-addon-docs": "^0.10.0",
4647
"ember-cli-addon-docs-yuidoc": "^0.2.4",
4748
"ember-cli-dependency-checker": "^3.0.0",
4849
"ember-cli-deploy": "^1.0.2",
@@ -74,6 +75,18 @@
7475
"sinon": "^9.0.3",
7576
"testdouble": "^3.16.1"
7677
},
78+
"peerDependencies": {
79+
"ember-mocha": "*",
80+
"ember-qunit": "*"
81+
},
82+
"peerDependenciesMeta": {
83+
"ember-qunit": {
84+
"optional": true
85+
},
86+
"ember-mocha": {
87+
"optional": true
88+
}
89+
},
7790
"engines": {
7891
"node": ">= 10.*"
7992
},

tests/test-helper.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
import { setResolver } from '@ember/test-helpers';
44
import resolver from './helpers/resolver';
55
import start from 'ember-exam/test-support/start';
6+
import { macroCondition, dependencySatisfies } from '@embroider/macros';
67

7-
const oppositeFramework = !require.has('ember-qunit') ? 'qunit' : 'mocha';
8+
const oppositeFramework = macroCondition(dependencySatisfies('ember-qunit', '*')) ? 'mocha': 'qunit';
89

910
Object.keys(require.entries).forEach((entry) => {
1011
if (entry.indexOf(oppositeFramework) !== -1) {

tests/unit/mocha/filter-test-modules-test.js

+20-17
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ describe('Unit | filter-test-modules', () => {
2424
});
2525

2626
describe('modulePath', function() {
27+
let modules = []
28+
2729
beforeEach(function() {
28-
this.modules = [
30+
modules = [
2931
'foo-test',
3032
'foo-test.jshint',
3133
'bar-test',
@@ -34,38 +36,38 @@ describe('Unit | filter-test-modules', () => {
3436
});
3537

3638
afterEach(function() {
37-
this.modules = [];
39+
modules = [];
3840
});
3941

4042
it('should return a list of jshint tests', () => {
41-
expect(filterTestModules(this.modules, 'jshint')).to.deep.equal([
43+
expect(filterTestModules(modules, 'jshint')).to.deep.equal([
4244
'foo-test.jshint',
4345
'bar-test.jshint'
4446
]);
4547
});
4648

4749
it('should return an empty list when there is no match', () => {
4850
expect(() => {
49-
filterTestModules(this.modules, 'no-match');
51+
filterTestModules(modules, 'no-match');
5052
}).to.throw(/No tests matched with the filter:/);
5153
});
5254

5355
it('should return a list of tests matched with a regular expression', () => {
54-
expect(filterTestModules(this.modules, '/jshint/')).to.deep.equal([
56+
expect(filterTestModules(modules, '/jshint/')).to.deep.equal([
5557
'foo-test.jshint',
5658
'bar-test.jshint'
5759
]);
5860
});
5961

6062
it('should return a list of tests matched with a regular expression that excluses jshint', () => {
61-
expect(filterTestModules(this.modules, '!/jshint/')).to.deep.equal([
63+
expect(filterTestModules(modules, '!/jshint/')).to.deep.equal([
6264
'foo-test',
6365
'bar-test'
6466
]);
6567
});
6668

6769
it('should return a list of tests matches with a list of string options', () => {
68-
expect(filterTestModules(this.modules, 'foo, bar')).to.deep.equal([
70+
expect(filterTestModules(modules, 'foo, bar')).to.deep.equal([
6971
'foo-test',
7072
'foo-test.jshint',
7173
'bar-test',
@@ -74,67 +76,68 @@ describe('Unit | filter-test-modules', () => {
7476
});
7577

7678
it('should return a list of unique tests matches when options are repeated', () => {
77-
expect(filterTestModules(this.modules, 'foo, foo')).to.deep.equal([
79+
expect(filterTestModules(modules, 'foo, foo')).to.deep.equal([
7880
'foo-test',
7981
'foo-test.jshint'
8082
]);
8183
});
8284
});
8385

8486
describe('filePath', function() {
87+
let modules = [];
8588
beforeEach(function() {
86-
this.modules = [
89+
modules = [
8790
'dummy/tests/integration/foo-test',
8891
'dummy/tests/unit/foo-test',
8992
'dummy/tests/unit/bar-test'
9093
];
9194
});
9295

9396
afterEach(function() {
94-
this.modules = [];
97+
modules = [];
9598
});
9699

97100
it('should return a test module matches with full test file path', () => {
98-
expect(filterTestModules(this.modules, null, 'app/tests/integration/foo-test.js')).to.deep.equal([
101+
expect(filterTestModules(modules, null, 'app/tests/integration/foo-test.js')).to.deep.equal([
99102
'dummy/tests/integration/foo-test'
100103
]);
101104
});
102105

103106
it('should return a test module matches with relative test file path', () => {
104-
expect(filterTestModules(this.modules, null, '/tests/unit/foo-test')).to.deep.equal([
107+
expect(filterTestModules(modules, null, '/tests/unit/foo-test')).to.deep.equal([
105108
'dummy/tests/unit/foo-test'
106109
]);
107110
});
108111

109112
it('should return a test module matched with test file path with wildcard', () => {
110-
expect(filterTestModules(this.modules, null, '/unit/*')).to.deep.equal([
113+
expect(filterTestModules(modules, null, '/unit/*')).to.deep.equal([
111114
'dummy/tests/unit/foo-test',
112115
'dummy/tests/unit/bar-test'
113116
]);
114117
});
115118

116119
it('should return a test module matched with test file path with wildcard', () => {
117-
expect(filterTestModules(this.modules, null, '/tests/*/foo*')).to.deep.equal([
120+
expect(filterTestModules(modules, null, '/tests/*/foo*')).to.deep.equal([
118121
'dummy/tests/integration/foo-test',
119122
'dummy/tests/unit/foo-test'
120123
]);
121124
});
122125

123126
it('should return a list of tests matched with a regular expression', () => {
124127
expect(() => {
125-
filterTestModules(this.modules, null, 'no-match');
128+
filterTestModules(modules, null, 'no-match');
126129
}).to.throw(/No tests matched with the filter:/);
127130
});
128131

129132
it('should return a list of tests matches with a list of string options', () => {
130-
expect(filterTestModules(this.modules, null, '/tests/integration/*, dummy/tests/unit/foo-test')).to.deep.equal([
133+
expect(filterTestModules(modules, null, '/tests/integration/*, dummy/tests/unit/foo-test')).to.deep.equal([
131134
'dummy/tests/integration/foo-test',
132135
'dummy/tests/unit/foo-test'
133136
]);
134137
});
135138

136139
it('should return a list of unique tests matches when options are repeated', () => {
137-
expect(filterTestModules(this.modules, null, 'app/tests/unit/bar-test.js, /tests/unit/*')).to.deep.equal([
140+
expect(filterTestModules(modules, null, 'app/tests/unit/bar-test.js, /tests/unit/*')).to.deep.equal([
138141
'dummy/tests/unit/bar-test',
139142
'dummy/tests/unit/foo-test'
140143
]);
+25-34
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
1-
import { describeModule, it } from 'ember-mocha';
21
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import { setupTest } from 'ember-mocha';
34

4-
describeModule(
5-
'component:herp-derp',
6-
'#1: Module-For With Multiple Tests',
7-
function() {
8-
it('#1', function() {
9-
expect(true).to.be.ok;
10-
});
11-
it('#2', function() {
12-
expect(true).to.be.ok;
13-
});
14-
it('#3', function() {
15-
expect(true).to.be.ok;
16-
});
17-
it('#4', function() {
18-
expect(true).to.be.ok;
19-
});
20-
it('#5', function() {
21-
expect(true).to.be.ok;
22-
});
23-
it('#6', function() {
24-
expect(true).to.be.ok;
25-
});
26-
it('#7', function() {
27-
expect(true).to.be.ok;
28-
});
29-
it('#8', function() {
30-
expect(true).to.be.ok;
31-
});
32-
it('#9', function() {
33-
expect(true).to.be.ok;
34-
});
35-
}
36-
);
5+
describe('#1: Multiple Ember Tests', function() {
6+
setupTest();
7+
8+
it('#1', function() {
9+
expect(true).to.be.ok;
10+
});
11+
12+
it('#2', function() {
13+
expect(true).to.be.ok;
14+
});
15+
16+
it('#3', function() {
17+
expect(true).to.be.ok;
18+
});
19+
20+
it('#4', function() {
21+
expect(true).to.be.ok;
22+
});
23+
24+
it('#5', function() {
25+
expect(true).to.be.ok;
26+
});
27+
});

0 commit comments

Comments
 (0)