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
34 changes: 24 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ module.exports = {
if (this._isCoverageEnabled() && this.parent.isEmberCLIAddon()) {
var coveredAddon = this.project.findAddonByName(this.project.pkg.name);
var coverageAddonContext = this;
var original = coveredAddon.addonJsFiles;

coveredAddon.addonJsFiles = function(tree) {
tree = coverageAddonContext.preprocessTree('addon-js', tree);

return original.call(this, tree);
};
coveredAddon.processedAddonJsFiles = function (tree){
var instrumentedTree = coverageAddonContext.preprocessTree('addon-js', this.addonJsFiles(tree));
return this.preprocessJs(instrumentedTree, '/', this.name, {
registry: this.registry
});
}
}
},

Expand All @@ -50,8 +50,10 @@ module.exports = {
* @returns {[type]} processed tree
*/
preprocessTree: function(type, tree) {
var useBabelInstrumenter = this._getConfig().useBabelInstrumenter === true;

// If coverage isn't enabled or tree is not JavaScript tree then we don't need to alter the tree
if (!this._isCoverageEnabled() || (type !== 'js' && type !== 'addon-js')) {
if (!this._isCoverageEnabled() || (type !== 'js' && type !=='addon-js')) {
return tree;
}

Expand All @@ -60,8 +62,6 @@ module.exports = {
exclude: this._getExcludes()
});

var useBabelInstrumenter = this._getConfig().useBabelInstrumenter === true;

// Instrument JavaScript for code coverage
var instrumentedNode = new CoverageInstrumenter(appFiles, {
annotation: 'Instrumenting for code coverage',
Expand Down Expand Up @@ -124,7 +124,20 @@ module.exports = {

return this._doesTemplateFileExist(relativePath);
},
/**
* Check if a file exists within the current addon directory. Removing `module/<app-name>` from the path.
* @param {String} relativePath - path to file within current app
* @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),''));

if (this._existsSync(relativePath)) {
return true;
}

return this._doesTemplateFileExist(relativePath);
},
/**
* Check if a file exists within the dummy app
* @param {String} relativePath - path to file within dummy app
Expand Down Expand Up @@ -189,7 +202,8 @@ module.exports = {
var fileExists = (
this._doesFileExistInDummyApp(relativePath) ||
this._doesFileExistInCurrentProjectApp(relativePath) ||
this._doesFileExistInCurrentProjectAddon(relativePath)
this._doesFileExistInCurrentProjectAddon(relativePath) ||
this._doesFileExistIsCurrentProjectAddonModule(relativePath)
);

console.log(!fileExists, name, relativePath);
Expand Down
6 changes: 5 additions & 1 deletion lib/coverage-instrumenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ CoverageInstrumenter.prototype.processString = function(content, relativePath) {

relativePath = fixPath(relativePath, this._appName, this._appRoot, this._templateExtensions);

return instrumenter.instrumentSync(content, relativePath);
try {
return instrumenter.instrumentSync(content, relativePath);
} catch (e) {
console.error('Unable to cover:', relativePath, '. Try setting useBabelInstrumenter to true. \n', e.stack);
}
};

module.exports = CoverageInstrumenter;
9 changes: 4 additions & 5 deletions test/unit/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var expect = require('chai').expect;
var sinon = require('sinon');
var Index = require('../../index.js');

describe('index.js', function() {
var sandbox

Expand Down Expand Up @@ -96,13 +95,13 @@ describe('index.js', function() {
});
});

describe('_doesFileExistInCurrentProject', function() {
describe('_doesFileExistInCurrentProjectApp', function() {
describe('when file exists', function() {
var result;

beforeEach(function() {
sandbox.stub(Index, '_existsSync').returns(true);
result = Index._doesFileExistInCurrentProject('adapters/application.js');
result = Index._doesFileExistInCurrentProjectApp('adapters/application.js');
});

it('uses path to file in app', function() {
Expand All @@ -124,7 +123,7 @@ describe('index.js', function() {

beforeEach(function() {
sandbox.stub(Index, '_doesTemplateFileExist').returns(true);
result = Index._doesFileExistInCurrentProject('templates/application.js');
result = Index._doesFileExistInCurrentProjectApp('templates/application.js');
});

it('uses path to file in app', function() {
Expand All @@ -141,7 +140,7 @@ describe('index.js', function() {

beforeEach(function() {
sandbox.stub(Index, '_doesTemplateFileExist').returns(false);
result = Index._doesFileExistInCurrentProject('templates/application.js');
result = Index._doesFileExistInCurrentProjectApp('templates/application.js');
});

it('uses path to file in app', function() {
Expand Down