From 88adbbd86c508df1220b4b0075c85fab643fe495 Mon Sep 17 00:00:00 2001 From: Eric White Date: Fri, 29 Jul 2016 11:11:15 -0400 Subject: [PATCH 1/5] Try catch around instrumenter. So it spits out a clearer error --- lib/coverage-instrumenter.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/coverage-instrumenter.js b/lib/coverage-instrumenter.js index 873c26a3..1a6b4f17 100644 --- a/lib/coverage-instrumenter.js +++ b/lib/coverage-instrumenter.js @@ -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; From d7fb5d12742d41f562030189dc7614813e5921c0 Mon Sep 17 00:00:00 2001 From: Eric White Date: Fri, 29 Jul 2016 11:49:49 -0400 Subject: [PATCH 2/5] Fix test _doesFileExistInCurrentProject -> _doesFileExistInCurrentProjectApp --- test/unit/index-test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit/index-test.js b/test/unit/index-test.js index dcdbb0f2..455caa98 100644 --- a/test/unit/index-test.js +++ b/test/unit/index-test.js @@ -3,7 +3,7 @@ var expect = require('chai').expect; var sinon = require('sinon'); var Index = require('../../index.js'); - +console.log(Index) describe('index.js', function() { var sandbox @@ -96,13 +96,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() { @@ -124,7 +124,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() { @@ -141,7 +141,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() { From 1e26426bd5588d2497b4e9afaca49be6b5bf02d0 Mon Sep 17 00:00:00 2001 From: Eric White Date: Wed, 3 Aug 2016 10:59:41 -0400 Subject: [PATCH 3/5] Remove console.log --- test/unit/index-test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/index-test.js b/test/unit/index-test.js index 455caa98..e81319fa 100644 --- a/test/unit/index-test.js +++ b/test/unit/index-test.js @@ -3,7 +3,6 @@ var expect = require('chai').expect; var sinon = require('sinon'); var Index = require('../../index.js'); -console.log(Index) describe('index.js', function() { var sandbox From 5ea334d8114abfae7fa88bc19d3c0665db9ba3bc Mon Sep 17 00:00:00 2001 From: Eric White Date: Wed, 24 Aug 2016 16:51:31 -0400 Subject: [PATCH 4/5] use processedAddonJsFiles --- index.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 698661f1..5d450f29 100644 --- a/index.js +++ b/index.js @@ -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.instrumentJs(this.addonJsFiles(tree)) + return this.preprocessJs(instrumentedTree, '/', this.name, { + registry: this.registry + }) + } } }, @@ -49,13 +49,12 @@ module.exports = { * @param {Tree} tree - tree to process * @returns {[type]} processed tree */ - preprocessTree: function(type, tree) { + instrumentJs: function(tree) { // 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()) { return tree; } - - // Make sure we exclude files defined in the configuration as well as files from addons + // // Make sure we exclude files defined in the configuration as well as files from addons var appFiles = new Funnel(tree, { exclude: this._getExcludes() }); @@ -124,7 +123,20 @@ module.exports = { return this._doesTemplateFileExist(relativePath); }, + /** + * Check if a file exists within the current addon directory. Removing `module/` 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 @@ -189,7 +201,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); From 53bf3c2eef5c1869b49713c07b4833419bb4a33e Mon Sep 17 00:00:00 2001 From: Eric White Date: Wed, 24 Aug 2016 17:13:56 -0400 Subject: [PATCH 5/5] Get rid of InstrumentJs put back preprocessTree --- index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 5d450f29..d14ffa6d 100644 --- a/index.js +++ b/index.js @@ -21,10 +21,10 @@ module.exports = { var coverageAddonContext = this; coveredAddon.processedAddonJsFiles = function (tree){ - var instrumentedTree = coverageAddonContext.instrumentJs(this.addonJsFiles(tree)) + var instrumentedTree = coverageAddonContext.preprocessTree('addon-js', this.addonJsFiles(tree)); return this.preprocessJs(instrumentedTree, '/', this.name, { registry: this.registry - }) + }); } } }, @@ -49,18 +49,19 @@ module.exports = { * @param {Tree} tree - tree to process * @returns {[type]} processed tree */ - instrumentJs: function(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()) { + if (!this._isCoverageEnabled() || (type !== 'js' && type !=='addon-js')) { return tree; } - // // Make sure we exclude files defined in the configuration as well as files from addons + + // Make sure we exclude files defined in the configuration as well as files from addons var appFiles = new Funnel(tree, { exclude: this._getExcludes() }); - var useBabelInstrumenter = this._getConfig().useBabelInstrumenter === true; - // Instrument JavaScript for code coverage var instrumentedNode = new CoverageInstrumenter(appFiles, { annotation: 'Instrumenting for code coverage',