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
32 changes: 28 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {

included: function() {
if (this._isCoverageEnabled() && this.parent.isEmberCLIAddon()) {
var coveredAddon = this.project.findAddonByName(this.project.pkg.name);
var coveredAddon = this._findCoveredAddon();
var coverageAddonContext = this;

coveredAddon.processedAddonJsFiles = function (tree){
Expand Down Expand Up @@ -65,7 +65,7 @@ module.exports = {
// Instrument JavaScript for code coverage
var instrumentedNode = new CoverageInstrumenter(appFiles, {
annotation: 'Instrumenting for code coverage',
appName: this.parent.pkg.name,
appName: this._parentName(),
appRoot: this.parent.root,
babelOptions: this.app.options.babel,
useBabelInstrumenter: useBabelInstrumenter,
Expand Down Expand Up @@ -130,7 +130,7 @@ module.exports = {
* @returns {Boolean} whether or not the file exists within the current app
*/
_doesFileExistIsCurrentProjectAddonModule: function(relativePath) {
relativePath = path.join('addon', relativePath.replace(path.join('modules', this.project.pkg.name),''));
relativePath = path.join('addon', relativePath.replace(path.join('modules', this._parentName()),''));

if (this._existsSync(relativePath)) {
return true;
Expand Down Expand Up @@ -223,7 +223,7 @@ module.exports = {
*/
_getExcludes: function() {
var excludes = this._getConfig().excludes || [];
var name = this.parent.pkg.name;
var name = this._parentName();
excludes.push(this._filterOutAddonFiles.bind(this, name));

return excludes;
Expand All @@ -241,5 +241,29 @@ module.exports = {
}

return ['true', true].indexOf(value) !== -1;
},

/**
* Determine the name of the parent app or addon.
* @returns {String} the name of the parent
*/
_parentName: function() {
if (this.parent.isEmberCLIAddon()) {
return this._findCoveredAddon().name;
} else {
return this.parent.name;
}
},

/**
* Find the addon (if any) that's being covered.
* @returns {Addon} the addon under test
*/
_findCoveredAddon: function() {
if (!this._coveredAddon) {
this._coveredAddon = this.project.findAddonByName(this.project.pkg.name);
}

return this._coveredAddon;
}
};
63 changes: 60 additions & 3 deletions test/unit/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ describe('index.js', function() {
});
});

describe('_getEcludes', function() {
describe('_getExcludes', function() {
beforeEach(function() {
sandbox.stub(Index, '_filterOutAddonFiles').returns('test');

Index.parent = {
pkg: {
name: 'foo-bar'
isEmberCLIAddon: function() {
return false;
}
};
});
Expand Down Expand Up @@ -397,4 +397,61 @@ describe('index.js', function() {
});
});
});

describe('_parentName', function() {
var isAddon;

beforeEach(function() {
Index.parent = {
name: 'parent-app',
isEmberCLIAddon: function() {
return isAddon;
}
};
});

describe('when parent is an app', function() {
beforeEach(function() {
isAddon = false;
});

it('returns the app name', function() {
expect(Index._parentName()).to.equal('parent-app');
});
});

describe('when parent is an addon', function() {
beforeEach(function() {
isAddon = true;
sandbox.stub(Index, '_findCoveredAddon').returns({ name: 'some-addon' });
});

it('returns the addon name', function() {
expect(Index._parentName()).to.equal('some-addon');
});
});
});

describe('_findCoveredAddon', function() {
var result;

beforeEach(function() {
Index.project = {
findAddonByName: sinon.stub().returns({ name: 'my-addon' }),
pkg: {
name: '@scope/ember-cli-my-addon'
}
};

result = Index._findCoveredAddon();
});

it('looks up the addon by the package name', function() {
expect(Index.project.findAddonByName.calledWith('@scope/ember-cli-my-addon')).to.be.true;
});

it('returns the located addon', function() {
expect(result.name).to.equal('my-addon');
});
});
});