Skip to content

Commit 4c156b3

Browse files
committed
feat: support for test-support and addon-test-support
1 parent 5c468af commit 4c156b3

File tree

6 files changed

+72
-12
lines changed

6 files changed

+72
-12
lines changed

blueprints/ember-cli-typescript/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ module.exports = {
3333
let hasMirage = 'ember-cli-mirage' in (this.project.pkg.devDependencies || {});
3434
let isAddon = this.project.isEmberCLIAddon();
3535
let isMU = this._detectMU();
36-
let includes = isMU ? ['src'] : ['app', isAddon && 'addon'].filter(Boolean);
37-
38-
includes = includes.concat(['tests', 'types']).concat(inRepoAddons);
36+
let includes = isMU ? ['src'] : ['app', 'tests', 'types'].filter(Boolean);
3937

38+
if (isAddon) {
39+
includes.push('addon', 'test-support', 'addon-test-support');
40+
}
4041
// Mirage is already covered for addons because it's under `tests/`
4142
if (hasMirage && !isAddon) {
4243
includes.push('mirage');
@@ -71,6 +72,8 @@ module.exports = {
7172
if (isAddon) {
7273
paths[dasherizedName] = ['addon'];
7374
paths[`${dasherizedName}/*`] = ['addon/*'];
75+
paths[`${dasherizedName}/test-support`] = ['addon-test-support'];
76+
paths[`${dasherizedName}/test-support/*`] = ['addon-test-support/*'];
7477
}
7578
}
7679

index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,32 @@ module.exports = {
5757
return this._super.treeForApp.call(this, tree);
5858
}
5959
},
60-
60+
// We manually invoke Babel for treeForAddon, treeForTestSupport and treeForAddonTestSupport
61+
// rather than calling _super because we're returning content on behalf of addons that aren't
62+
// ember-cli-typescript, and the _super impl would namespace all the files under our own name.
6163
treeForAddon() {
6264
if (this.compiler) {
63-
// We manually invoke Babel here rather than calling _super because we're returning
64-
// content on behalf of addons that aren't ember-cli-typescript, and the _super impl
65-
// would namespace all the files under our own name.
6665
let babel = this.project.addons.find(addon => addon.name === 'ember-cli-babel');
6766
let tree = this.compiler.treeForAddons();
6867
return babel.transpileTree(tree);
6968
}
7069
},
7170

7271
treeForTestSupport() {
72+
let trees = [this.compiler.treeForTests()];
73+
if (this.compiler) {
74+
let babel = this.project.addons.find(addon => addon.name === 'ember-cli-babel');
75+
let tree = this.compiler.treeForTestSupport();
76+
trees.push(babel.transpileTree(tree));
77+
}
78+
return this._super.treeForTestSupport.call(this, new MergeTrees(trees));
79+
},
80+
81+
treeForAddonTestSupport() {
7382
if (this.compiler) {
74-
let tree = this.compiler.treeForTests();
75-
return this._super.treeForTestSupport.call(this, tree);
83+
let babel = this.project.addons.find(addon => addon.name === 'ember-cli-babel');
84+
let tree = this.compiler.treeForAddonTestSupport();
85+
return babel.transpileTree(tree);
7686
}
7787
},
7888
};

lib/incremental-typescript-compiler/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ module.exports = class IncrementalTypescriptCompiler {
8989
return new TypescriptOutput(this, paths);
9090
}
9191

92+
treeForAddonTestSupport() {
93+
let paths = {};
94+
for (let addon of this.addons) {
95+
paths[`${this._relativeAddonRoot(addon)}/addon-test-support`] = `${addon.name}/test-support`;
96+
}
97+
return new TypescriptOutput(this, paths);
98+
}
99+
100+
treeForTestSupport() {
101+
let paths = {};
102+
for (let addon of this.addons) {
103+
paths[`${this._relativeAddonRoot(addon)}/test-support`] = `tests`;
104+
}
105+
return new TypescriptOutput(this, paths);
106+
}
107+
92108
treeForTests() {
93109
let tree = new TypescriptOutput(this, { tests: 'tests' });
94110
return new Funnel(tree, { srcDir: 'tests' });

lib/utilities/update-paths-for-addon.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ module.exports = function(paths, addonName, appName, options) {
77
const addonAddonPath = [addonPath, 'addon'].join('/');
88
const addonAppPath = [addonPath, 'app'].join('/');
99
const appNameStar = [appName, '*'].join('/');
10+
const addonTestSupportPath = [addonName, 'test-support'].join('/');
11+
const addonTestSupportStarPath = `${addonTestSupportPath}/*`;
1012
let appStarPaths;
1113
paths = paths || {};
1214
appStarPaths = paths[appNameStar] = paths[appNameStar] || [];
13-
1415
if (options.removePaths) {
1516
if (paths.hasOwnProperty(addonName)) {
1617
delete paths[addonName];
@@ -30,6 +31,12 @@ module.exports = function(paths, addonName, appName, options) {
3031
if (!paths.hasOwnProperty(addonNameStar)) {
3132
paths[addonNameStar] = [ [addonAddonPath, '*'].join('/') ];
3233
}
34+
if (!paths.hasOwnProperty(addonTestSupportPath)) {
35+
paths[addonTestSupportPath] = [ [addonPath, 'addon-test-support'].join('/') ];
36+
}
37+
if (!paths.hasOwnProperty(addonTestSupportStarPath)) {
38+
paths[addonTestSupportStarPath] = [ [addonPath, 'addon-test-support', '*'].join('/') ];
39+
}
3340
if (appStarPaths.indexOf(addonAppPath) === -1) {
3441
appStarPaths.push([addonAppPath, '*'].join('/'));
3542
paths[appNameStar] = appStarPaths;

node-tests/blueprints/ember-cli-typescript-test.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,19 @@ describe('Acceptance: ember-cli-typescript generator', function() {
114114
'dummy/*': ['tests/dummy/app/*', 'app/*'],
115115
'my-addon': ['addon'],
116116
'my-addon/*': ['addon/*'],
117+
'my-addon/test-support': ['addon-test-support'],
118+
'my-addon/test-support/*': ['addon-test-support/*'],
117119
'*': ['types/*'],
118120
});
119121

120-
expect(tsconfigJson.include).to.deep.equal(['app/**/*', 'addon/**/*', 'tests/**/*', 'types/**/*']);
122+
expect(tsconfigJson.include).to.deep.equal([
123+
'app/**/*',
124+
'tests/**/*',
125+
'types/**/*',
126+
'addon/**/*',
127+
'test-support/**/*',
128+
'addon-test-support/**/*'
129+
]);
121130

122131
const projectTypes = file('types/dummy/index.d.ts');
123132
expect(projectTypes).to.exist;
@@ -257,8 +266,12 @@ describe('Acceptance: ember-cli-typescript generator', function() {
257266
'my-app/*': ['app/*', 'lib/my-addon-1/app/*', 'lib/my-addon-2/app/*'],
258267
'my-addon-1': ['lib/my-addon-1/addon'],
259268
'my-addon-1/*': ['lib/my-addon-1/addon/*'],
269+
'my-addon-1/test-support': ['lib/my-addon-1/addon-test-support'],
270+
'my-addon-1/test-support/*': ['lib/my-addon-1/addon-test-support/*'],
260271
'my-addon-2': ['lib/my-addon-2/addon'],
261272
'my-addon-2/*': ['lib/my-addon-2/addon/*'],
273+
'my-addon-2/test-support': ['lib/my-addon-2/addon-test-support'],
274+
'my-addon-2/test-support/*': ['lib/my-addon-2/addon-test-support/*'],
262275
'*': ['types/*'],
263276
});
264277

@@ -324,10 +337,19 @@ describe('Acceptance: ember-cli-typescript generator', function() {
324337
'dummy/*': ['tests/dummy/app/*', 'app/*'],
325338
'my-addon': ['addon'],
326339
'my-addon/*': ['addon/*'],
340+
'my-addon/test-support': ['addon-test-support'],
341+
'my-addon/test-support/*': ['addon-test-support/*'],
327342
'*': ['types/*'],
328343
});
329344

330-
expect(json.include).to.deep.equal(['app/**/*', 'addon/**/*', 'tests/**/*', 'types/**/*']);
345+
expect(json.include).to.deep.equal([
346+
'app/**/*',
347+
'tests/**/*',
348+
'types/**/*',
349+
'addon/**/*',
350+
'test-support/**/*',
351+
'addon-test-support/**/*'
352+
]);
331353
});
332354
});
333355

node-tests/blueprints/in-repo-addon-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ describe('Acceptance: ember generate and destroy in-repo-addon', function() {
5656
const tsconfigJson = fs.readJsonSync('tsconfig.json');
5757
expect(tsconfigJson['compilerOptions']['paths']['foo-bar']).to.have.all.members(['lib/foo-bar/addon']);
5858
expect(tsconfigJson['compilerOptions']['paths']['foo-bar/*']).to.have.all.members(['lib/foo-bar/addon/*']);
59+
expect(tsconfigJson['compilerOptions']['paths']['foo-bar/test-support']).to.have.all.members(['lib/foo-bar/addon-test-support']);
60+
expect(tsconfigJson['compilerOptions']['paths']['foo-bar/test-support/*']).to.have.all.members(['lib/foo-bar/addon-test-support/*']);
5961
expect(tsconfigJson['compilerOptions']['paths'][nameStar]).to.include.members(['lib/foo-bar/app/*']);
6062
expect(tsconfigJson['include']).to.include.members(['lib/foo-bar']);
6163
})

0 commit comments

Comments
 (0)