diff --git a/index.js b/index.js index 3ffe9f8f..bd99eb08 100644 --- a/index.js +++ b/index.js @@ -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 }])); @@ -85,7 +85,7 @@ module.exports = { return undefined; }, - includedCommands: function () { + includedCommands: function() { return { 'coverage-merge': require('./lib/coverage-merge') }; @@ -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, @@ -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`) + ); } }, @@ -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`) ); }, []); }, @@ -185,14 +193,18 @@ module.exports = { * @returns {Array} 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 []; + } }, /** diff --git a/test/fixtures/my-addon/addon-test-support/uncovered-test-support.js b/test/fixtures/my-addon/addon-test-support/uncovered-test-support.js new file mode 100644 index 00000000..21a3f3f7 --- /dev/null +++ b/test/fixtures/my-addon/addon-test-support/uncovered-test-support.js @@ -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'; +} diff --git a/test/fixtures/my-app-with-in-repo-addon/lib/my-in-repo-addon/addon-test-support/uncovered-test-support.js b/test/fixtures/my-app-with-in-repo-addon/lib/my-in-repo-addon/addon-test-support/uncovered-test-support.js new file mode 100644 index 00000000..21a3f3f7 --- /dev/null +++ b/test/fixtures/my-app-with-in-repo-addon/lib/my-in-repo-addon/addon-test-support/uncovered-test-support.js @@ -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'; +} diff --git a/test/integration/in-repo-addon-coverage-test.js b/test/integration/in-repo-addon-coverage-test.js index 90e15cd4..eac01d5f 100644 --- a/test/integration/in-repo-addon-coverage-test.js +++ b/test/integration/in-repo-addon-coverage-test.js @@ -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); }); })); }); diff --git a/test/unit/index-test.js b/test/unit/index-test.js index e6a3ca43..3266fe62 100644 --- a/test/unit/index-test.js +++ b/test/unit/index-test.js @@ -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' }); @@ -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' }); }); });