Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ module.exports = {
const include = this._getIncludes();

concat(
this.app,
this._findCoveredAddon(),
this._findInRepoAddons()
)
this.app,
this._findCoveredAddon(),
this._findInRepoAddons()
)
.filter(Boolean)
.map(getPlugins)
.forEach((plugins) => plugins.push([IstanbulPlugin, { exclude, include }]));
Expand All @@ -85,7 +85,7 @@ module.exports = {
return undefined;
},

includedCommands: function () {
includedCommands: function() {
return {
'coverage-merge': require('./lib/coverage-merge')
};
Expand All @@ -100,7 +100,9 @@ module.exports = {
},

testemMiddleware: function(app) {
if (!this._isCoverageEnabled()) { return; }
if (!this._isCoverageEnabled()) {
return;
}
attachMiddleware(app, {
configPath: this.project.configPath(),
root: this.project.root,
Expand Down Expand Up @@ -156,8 +158,12 @@ module.exports = {
_getIncludesForAddonDirectory: function() {
let addon = this._findCoveredAddon();
if (addon) {
const dir = path.join(this.project.root, 'addon');
return this._getIncludesForDir(dir, addon.name);
const addonDir = path.join(this.project.root, 'addon');
const addonTestSupportDir = path.join(this.project.root, 'addon-test-support');
return concat(
this._getIncludesForDir(addonDir, addon.name),
this._getIncludesForDir(addonTestSupportDir, `${addon.name}/test-support`)
);
}
},

Expand All @@ -170,10 +176,12 @@ module.exports = {
let addonDir = path.join(this.project.root, 'lib', addon.name);
let addonAppDir = path.join(addonDir, 'app');
let addonAddonDir = path.join(addonDir, 'addon');
const addonAddonTestSupportDir = path.join(addonDir, 'addon-test-support');
return concat(
acc,
this._getIncludesForDir(addonAppDir, this.parent.name()),
this._getIncludesForDir(addonAddonDir, addon.name)
this._getIncludesForDir(addonAddonDir, addon.name),
this._getIncludesForDir(addonAddonTestSupportDir, `${addon.name}/test-support`)
);
}, []);
},
Expand All @@ -185,14 +193,18 @@ module.exports = {
* @returns {Array<String>} include paths
*/
_getIncludesForDir: function(dir, prefix) {
let dirname = path.relative(this.project.root, dir);
let globs = this.registry.extensionsForType('js').map((extension) => `**/*.${extension}`);

return walkSync(dir, { directories: false, globs }).map(file => {
let module = prefix + '/' + file.replace(EXT_RE, '.js');
this.fileLookup[module] = path.join(dirname, file);
return module;
});
if (fs.existsSync(dir)) {
let dirname = path.relative(this.project.root, dir);
let globs = this.registry.extensionsForType('js').map((extension) => `**/*.${extension}`);

return walkSync(dir, { directories: false, globs }).map(file => {
let module = prefix + '/' + file.replace(EXT_RE, '.js');
this.fileLookup[module] = path.join(dirname, file);
return module;
});
} else {
return [];
}
},

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Just a test function to show that addon-test-support coverage is counted
*/
export function uncoveredFunction(condition) {
if (condition) {
return 'Was true';
} else {
return 'Was false';
}
}

export function anotherUncoveredFunction() {
return 'Not covered';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Just a test function to show that addon-test-support coverage is counted
*/
export function uncoveredFunction(condition) {
if (condition) {
return 'Was true';
} else {
return 'Was false';
}
}

export function anotherUncoveredFunction() {
return 'Not covered';
}
16 changes: 14 additions & 2 deletions test/integration/in-repo-addon-coverage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,22 @@ describe('in-repo addon coverage generation', function() {
return app.run('ember', 'test').then(function() {
expect(file(`${app.path}/coverage/lcov-report/index.html`)).to.not.be.empty;
expect(file(`${app.path}/coverage/index.html`)).to.not.be.empty;
var summary = fs.readJSONSync(`${app.path}/coverage/coverage-summary.json`);
expect(summary.total.lines.pct).to.equal(75);

const summary = fs.readJSONSync(`${app.path}/coverage/coverage-summary.json`);
expect(summary.total.lines.pct).to.equal(50);
expect(summary['app/utils/my-covered-util-app.js'].lines.total).to.equal(1);

// Check that lib/my-in-repo-addon/utils/my-covered-utill is 1 line and that 1 line is covered
expect(summary['lib/my-in-repo-addon/addon/utils/my-covered-util.js'].lines.total).to.equal(1);
expect(summary['lib/my-in-repo-addon/addon/utils/my-covered-util.js'].lines.covered).to.equal(1);

// Check that lib/my-in-repo-addon/utils/my-uncovered-utill is 1 line and that 0 lines are covered
expect(summary['lib/my-in-repo-addon/addon/utils/my-uncovered-util.js'].lines.total).to.equal(1);
expect(summary['lib/my-in-repo-addon/addon/utils/my-uncovered-util.js'].lines.covered).to.equal(0);

// Check that lib/my-in-repo-addon/addon-test-support/uncovered-test-support is 4 lines and that 0 lines are covered
expect(summary['lib/my-in-repo-addon/addon-test-support/uncovered-test-support.js'].lines.total).to.equal(4);
expect(summary['lib/my-in-repo-addon/addon-test-support/uncovered-test-support.js'].lines.covered).to.equal(0);
});
}));
});
8 changes: 6 additions & 2 deletions test/unit/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,11 @@ describe('index.js', function() {
const includes = Index._getIncludesForAddonDirectory();
expect(includes).to.deep.equal([
'my-addon/utils/my-covered-util.js',
'my-addon/utils/my-uncovered-util.js'
'my-addon/utils/my-uncovered-util.js',
'my-addon/test-support/uncovered-test-support.js'
]);
expect(Index.fileLookup).to.deep.equal({
'my-addon/test-support/uncovered-test-support.js': 'addon-test-support/uncovered-test-support.js',
'my-addon/utils/my-covered-util.js': 'addon/utils/my-covered-util.js',
'my-addon/utils/my-uncovered-util.js': 'addon/utils/my-uncovered-util.js'
});
Expand Down Expand Up @@ -473,13 +475,15 @@ describe('index.js', function() {
'my-app/utils/my-covered-util.js',
'my-app/utils/my-uncovered-util.js',
'my-in-repo-addon/utils/my-covered-util.js',
'my-in-repo-addon/utils/my-uncovered-util.js'
'my-in-repo-addon/utils/my-uncovered-util.js',
'my-in-repo-addon/test-support/uncovered-test-support.js'
]);
expect(Index.fileLookup).to.deep.equal({
'my-app/utils/my-covered-util.js': 'lib/my-in-repo-addon/app/utils/my-covered-util.js',
'my-app/utils/my-uncovered-util.js': 'lib/my-in-repo-addon/app/utils/my-uncovered-util.js',
'my-in-repo-addon/utils/my-covered-util.js': 'lib/my-in-repo-addon/addon/utils/my-covered-util.js',
'my-in-repo-addon/utils/my-uncovered-util.js': 'lib/my-in-repo-addon/addon/utils/my-uncovered-util.js',
'my-in-repo-addon/test-support/uncovered-test-support.js': 'lib/my-in-repo-addon/addon-test-support/uncovered-test-support.js'
});
});
});
Expand Down