Skip to content

Commit 6f01c6f

Browse files
authored
Merge pull request #240 from mike-north/addon-test-support
Support for building test-support & addon-test-support
2 parents dbadfb5 + d84d314 commit 6f01c6f

File tree

11 files changed

+109
-14
lines changed

11 files changed

+109
-14
lines changed

blueprints/ember-cli-typescript/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ module.exports = {
3737

3838
includes = includes.concat(['tests', 'types']).concat(inRepoAddons);
3939

40+
if (isAddon && !isMU) {
41+
includes.push('test-support', 'addon-test-support');
42+
}
4043
// Mirage is already covered for addons because it's under `tests/`
4144
if (hasMirage && !isAddon) {
4245
includes.push('mirage');
@@ -71,6 +74,8 @@ module.exports = {
7174
if (isAddon) {
7275
paths[dasherizedName] = ['addon'];
7376
paths[`${dasherizedName}/*`] = ['addon/*'];
77+
paths[`${dasherizedName}/test-support`] = ['addon-test-support'];
78+
paths[`${dasherizedName}/test-support/*`] = ['addon-test-support/*'];
7479
}
7580
}
7681

index.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const IncrementalTypescriptCompiler = require('./lib/incremental-typescript-compiler');
55
const Funnel = require('broccoli-funnel');
66
const MergeTrees = require('broccoli-merge-trees');
7+
const stew = require('broccoli-stew');
78

89
module.exports = {
910
name: 'ember-cli-typescript',
@@ -58,21 +59,33 @@ module.exports = {
5859
}
5960
},
6061

62+
// We manually invoke Babel for treeForAddon and treeForAddonTestSupport
63+
// rather than calling _super because we're returning content on behalf of addons that aren't
64+
// ember-cli-typescript, and the _super impl would namespace all the files under our own name.
6165
treeForAddon() {
6266
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.
6667
let babel = this.project.addons.find(addon => addon.name === 'ember-cli-babel');
6768
let tree = this.compiler.treeForAddons();
6869
return babel.transpileTree(tree);
6970
}
7071
},
7172

7273
treeForTestSupport() {
74+
let trees = [];
7375
if (this.compiler) {
74-
let tree = this.compiler.treeForTests();
75-
return this._super.treeForTestSupport.call(this, tree);
76+
trees.push(this.compiler.treeForTests());
77+
trees.push(this.compiler.treeForTestSupport());
78+
}
79+
return this._super.treeForTestSupport.call(this,
80+
stew.mv(new MergeTrees(trees), 'test-support/*', '/')
81+
);
82+
},
83+
84+
treeForAddonTestSupport() {
85+
if (this.compiler) {
86+
let babel = this.project.addons.find(addon => addon.name === 'ember-cli-babel');
87+
let tree = this.compiler.treeForAddonTestSupport();
88+
return babel.transpileTree(tree);
7689
}
7790
},
7891
};

lib/commands/precompile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ module.exports = Command.extend({
4747

4848
// We can only do anything meaningful with declarations for files in addon/ or src/
4949
if (this._isAddonFile(declSource)) {
50-
let declDest = declSource.replace(/^addon\//, '');
50+
let declDest = declSource
51+
.replace(/^addon\//, '')
52+
.replace(/^addon-test-support/, 'test-support');
5153
this._copyFile(output, `${outDir}/${declSource}`, declDest);
5254
} else if (this._isSrcFile(declSource)) {
5355
this._copyFile(output, `${outDir}/${declSource}`, declSource);

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`] = `test-support`;
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ 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] || [];
@@ -30,6 +32,12 @@ module.exports = function(paths, addonName, appName, options) {
3032
if (!paths.hasOwnProperty(addonNameStar)) {
3133
paths[addonNameStar] = [ [addonAddonPath, '*'].join('/') ];
3234
}
35+
if (!paths.hasOwnProperty(addonTestSupportPath)) {
36+
paths[addonTestSupportPath] = [ [addonPath, 'addon-test-support'].join('/') ];
37+
}
38+
if (!paths.hasOwnProperty(addonTestSupportStarPath)) {
39+
paths[addonTestSupportStarPath] = [ [addonPath, 'addon-test-support', '*'].join('/') ];
40+
}
3341
if (appStarPaths.indexOf(addonAppPath) === -1) {
3442
appStarPaths.push([addonAppPath, '*'].join('/'));
3543
paths[appNameStar] = appStarPaths;

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

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ describe('Acceptance: ember-cli-typescript generator', function() {
2323
// Mock npm-install that only modifies package.json
2424
return {
2525
run: function(options) {
26-
let pkgJson = fs.readJsonSync('package.json')
26+
let pkgJson = fs.readJsonSync('package.json');
2727
options.packages.forEach(function(pkg) {
2828
let pkgName = pkg.match(/^(.*)@[^@]*$/);
2929
pkgJson['devDependencies'][pkgName[1]] = '*';
3030
});
3131
fs.writeJsonSync('package.json', pkgJson);
3232
}
33-
}
33+
};
3434
}
3535
return originalTaskForFn.call(this, taskName);
3636
};
@@ -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+
'addon/**/*',
125+
'tests/**/*',
126+
'types/**/*',
127+
'test-support/**/*',
128+
'addon-test-support/**/*',
129+
]);
121130

122131
const projectTypes = file('types/dummy/index.d.ts');
123132
expect(projectTypes).to.exist;
@@ -159,7 +168,10 @@ describe('Acceptance: ember-cli-typescript generator', function() {
159168
expect(pkgJson.devDependencies).to.include.all.keys('@types/ember-data');
160169
expect(pkgJson.devDependencies).to.include.all.keys('ember-cli-qunit');
161170
expect(pkgJson.devDependencies).to.include.all.keys('@types/ember-qunit', '@types/qunit');
162-
expect(pkgJson.devDependencies).to.not.have.any.keys('@types/ember-mocha', '@types/mocha');
171+
expect(pkgJson.devDependencies).to.not.have.any.keys(
172+
'@types/ember-mocha',
173+
'@types/mocha'
174+
);
163175

164176
const tsconfig = file('tsconfig.json');
165177
expect(tsconfig).to.exist;
@@ -205,7 +217,10 @@ describe('Acceptance: ember-cli-typescript generator', function() {
205217
expect(pkgJson.devDependencies).to.not.have.any.keys('@types/ember-data');
206218
expect(pkgJson.devDependencies).to.include.all.keys('ember-cli-qunit');
207219
expect(pkgJson.devDependencies).to.include.all.keys('@types/ember-qunit', '@types/qunit');
208-
expect(pkgJson.devDependencies).to.not.have.any.keys('@types/ember-mocha', '@types/mocha');
220+
expect(pkgJson.devDependencies).to.not.have.any.keys(
221+
'@types/ember-mocha',
222+
'@types/mocha'
223+
);
209224

210225
const tsconfig = file('tsconfig.json');
211226
expect(tsconfig).to.exist;
@@ -257,12 +272,22 @@ describe('Acceptance: ember-cli-typescript generator', function() {
257272
'my-app/*': ['app/*', 'lib/my-addon-1/app/*', 'lib/my-addon-2/app/*'],
258273
'my-addon-1': ['lib/my-addon-1/addon'],
259274
'my-addon-1/*': ['lib/my-addon-1/addon/*'],
275+
'my-addon-1/test-support': ['lib/my-addon-1/addon-test-support'],
276+
'my-addon-1/test-support/*': ['lib/my-addon-1/addon-test-support/*'],
260277
'my-addon-2': ['lib/my-addon-2/addon'],
261278
'my-addon-2/*': ['lib/my-addon-2/addon/*'],
279+
'my-addon-2/test-support': ['lib/my-addon-2/addon-test-support'],
280+
'my-addon-2/test-support/*': ['lib/my-addon-2/addon-test-support/*'],
262281
'*': ['types/*'],
263282
});
264283

265-
expect(json.include).to.deep.equal(['app/**/*', 'tests/**/*', 'types/**/*', 'lib/my-addon-1/**/*', 'lib/my-addon-2/**/*']);
284+
expect(json.include).to.deep.equal([
285+
'app/**/*',
286+
'tests/**/*',
287+
'types/**/*',
288+
'lib/my-addon-1/**/*',
289+
'lib/my-addon-2/**/*',
290+
]);
266291

267292
const projectTypes = file('types/my-app/index.d.ts');
268293
expect(projectTypes).to.exist;
@@ -324,10 +349,19 @@ describe('Acceptance: ember-cli-typescript generator', function() {
324349
'dummy/*': ['tests/dummy/app/*', 'app/*'],
325350
'my-addon': ['addon'],
326351
'my-addon/*': ['addon/*'],
352+
'my-addon/test-support': ['addon-test-support'],
353+
'my-addon/test-support/*': ['addon-test-support/*'],
327354
'*': ['types/*'],
328355
});
329356

330-
expect(json.include).to.deep.equal(['app/**/*', 'addon/**/*', 'tests/**/*', 'types/**/*']);
357+
expect(json.include).to.deep.equal([
358+
'app/**/*',
359+
'addon/**/*',
360+
'tests/**/*',
361+
'types/**/*',
362+
'test-support/**/*',
363+
'addon-test-support/**/*',
364+
]);
331365
});
332366
});
333367

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
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const description = "From addon-test-support";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const description = "From test-support";

tests/unit/build-test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import fileA from 'dummy/a';
77
import fileB from 'dummy/b';
88
import muFile from 'dummy/src/test-file';
99
import shadowedFile from 'dummy/shadowed-file';
10+
import { description as fromAts } from 'in-repo-a/test-support/from-ats';
11+
import { description as fromTs } from 'dummy/tests/from-ts';
1012

1113
module('Unit | Build', function() {
1214
test('in-repo addons\' addon trees wind up in the right place', function(assert) {
@@ -30,4 +32,13 @@ module('Unit | Build', function() {
3032
test('MU addon files wind up in the right place', function(assert) {
3133
assert.equal(addonFileC, 'in-repo-c/src/test-file');
3234
});
35+
36+
test('addon\'s addon-test-support files end up in <addon-name>/test-support/*', function (assert) {
37+
assert.ok(fromAts);
38+
assert.equal(fromAts, 'From addon-test-support');
39+
});
40+
test('addon\'s test-support files end up in dummy/tests/*', function (assert) {
41+
assert.ok(fromTs);
42+
assert.equal(fromTs, 'From test-support');
43+
});
3344
});

0 commit comments

Comments
 (0)