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
65 changes: 56 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ module.exports = {

// Ember Methods

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

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

/**
* Get content for type
* @param {String} type - type to get content for
Expand All @@ -39,7 +53,7 @@ module.exports = {
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') {
if (!this._isCoverageEnabled() || (type !== 'js' && type !=='addon-js')) {
return tree;
}

Expand Down Expand Up @@ -82,11 +96,11 @@ module.exports = {
// Custom Methods

/**
* Check if a file exists within the current app/addon
* @param {String} relativePath - path to file within current app/addon
* @returns {Boolean} whether or not the file exists within the current app/addon
* Check if a file exists within the current app directory
* @param {String} relativePath - path to file within current app
* @returns {Boolean} whether or not the file exists within the current app
*/
_doesFileExistInCurrentProject: function(relativePath) {
_doesFileExistInCurrentProjectApp: function(relativePath) {
relativePath = path.join('app', relativePath);

if (this._existsSync(relativePath)) {
Expand All @@ -96,6 +110,34 @@ module.exports = {
return this._doesTemplateFileExist(relativePath);
},

/**
* Check if a file exists within the current addon directory
* @param {String} relativePath - path to file within current app
* @returns {Boolean} whether or not the file exists within the current app
*/
_doesFileExistInCurrentProjectAddon: function(relativePath) {
relativePath = path.join('addon', relativePath);

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

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 @@ -138,7 +180,7 @@ module.exports = {
* @param {String} path - path to check existence of
* @returns {Boolean} whether or not path exists
*/
_existsSync: function (path) {
_existsSync: function(path) {
return existsSync(path);
},

Expand All @@ -149,8 +191,8 @@ module.exports = {
* @returns {Boolean} whether or not to filter out file
*/
_filterOutAddonFiles: function(name, relativePath) {
if(relativePath.indexOf(name + '/') === 0) {
relativePath = relativePath.replace(name + '/', '')
if (relativePath.indexOf(name + '/') === 0) {
relativePath = relativePath.replace(name + '/', '');
}

if (relativePath.indexOf('dummy/') === 0) {
Expand All @@ -159,9 +201,13 @@ module.exports = {

var fileExists = (
this._doesFileExistInDummyApp(relativePath) ||
this._doesFileExistInCurrentProject(relativePath)
this._doesFileExistInCurrentProjectApp(relativePath) ||
this._doesFileExistInCurrentProjectAddon(relativePath) ||
this._doesFileExistIsCurrentProjectAddonModule(relativePath)
);

console.log(!fileExists, name, relativePath);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to leave this in?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, good catch!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is still in here; I'm seeing a bunch of console logging right now trying to run things on ember-ajax that match this pattern


return !fileExists;
},

Expand All @@ -181,6 +227,7 @@ module.exports = {
var excludes = this._getConfig().excludes || [];
var name = this.parent.pkg.name;
excludes.push(this._filterOutAddonFiles.bind(this, name));

return excludes;
},

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition!

}
};

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