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
4 changes: 0 additions & 4 deletions .bowerrc

This file was deleted.

6 changes: 2 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 6
ecmaVersion: 2017,
sourceType: 'module'
},
extends: 'eslint:recommended',
env: {
Expand All @@ -19,9 +20,6 @@ module.exports = {
// JSHint "proto", disabled due to warnings
'no-proto': 0,

// JSHint "strict"
'strict': [2, 'global'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this necessary to remove now that the use strict issue is resolved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So if I add that, then I get:

> ember-cli-code-coverage@0.3.12 lint /Users/paulw/Work/stuff/ember-cli-code-coverage
> eslint config lib test tests *.js


/Users/paulw/.../ember-cli-code-coverage/config/environment.js
  2:1  error  'use strict' is unnecessary inside of modules  strict

/Users/paulw/.../ember-cli-code-coverage/config/release.js
  1:1  error  'use strict' is unnecessary inside of modules  strict

/Users/paulw/.../ember-cli-code-coverage/lib/attach-middleware.js
  1:1  error  'use strict' is unnecessary inside of modules  strict

....

So which do you want, do you want the eslint rule or do you want the "use stricts"? Personally I'd rather have it hue closer to the default ember-cli blueprint, but that's just my opinion.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the way you have it now is good


// JSHint "indent", disabled due to warnings
'indent': [2, 2, {
'SwitchCase': 1,
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.
# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
Expand All @@ -12,6 +12,7 @@
/.sass-cache
/connect.lock
/coverage/*
/coverage_*
/libpeerconnection.log
npm-debug.log
npm-debug.log*
testem.log
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.editorconfig
.ember-cli
.gitignore
.jshintrc
.eslintrc.js
.watchmanconfig
.travis.yml
bower.json
Expand Down
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
---
language: node_js
node_js:
- "0.12"
- "4.2"
- "4"
- "6"

dist: trusty
Expand Down Expand Up @@ -35,9 +34,7 @@ before_install:
- npm install -g npm@^2

install:
- npm install -g bower
- npm install
- bower install

script:
- npm run-script $NPM_SCRIPT
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Configuration is optional. It should be put in a file at `config/coverage.js` (`

- `useBabelInstrumenter`: Defaults to `false`. Whether or not to use Babel instrumenter instead of default instrumenter. The Babel instrumenter is useful when you are using features of ESNext as it uses your Babel configuration defined in `ember-cli-build.js`.

- `babelPlugins`: Defaults to `['babel-plugin-transform-async-to-generator']`. When using the Babel instrumenter, this specifies a set of additional plugins to pass to the parser. Use this to parse specific ESNext features you may be using in your app (decorators, for instance).

- `parallel`: Defaults to `false`. Should be set to true if parallel testing is being used, for example when using [ember-exam](https://github.com/trentmwillis/ember-exam) with the `--parallel` flag. This will generate the coverage reports in directories suffixed with `_<random_string>` to avoid overwriting other threads reports. These reports can be joined by using the `ember coverage-merge` command.

#### Example
Expand Down
9 changes: 0 additions & 9 deletions bower.json

This file was deleted.

1 change: 1 addition & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-env node */
'use strict';

module.exports = function(/* environment, appConfig */) {
Expand Down
8 changes: 6 additions & 2 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/* eslint-env node */
'use strict';
/* global require, module */

var EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
var app = new EmberAddon(defaults, {
// Add options here
'ember-cli-babel': {
// Used by the dummy app, doesn't affect the host app
includePolyfill: true
}
});

/*
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = {

preprocessTree: function(type, tree) {
var useBabelInstrumenter = this._getConfig().useBabelInstrumenter === true;
var babelPlugins = this._getConfig().babelPlugins;

if (!this._isCoverageEnabled() || (type !== 'js' && type !=='addon-js')) {
return tree;
Expand All @@ -55,6 +56,7 @@ module.exports = {
babelOptions: this.app.options.babel,
isAddon: this.project.isEmberCLIAddon(),
useBabelInstrumenter: useBabelInstrumenter,
babelPlugins: babelPlugins,
templateExtensions: this.registry.extensionsForType('template')
});

Expand Down
8 changes: 8 additions & 0 deletions lib/babel-istanbul-instrumenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function Instrumenter(options) {
this.babelOptions = extend({
sourceMap: true
}, options && options.babel || {});
this.plugins = options.plugins;

return this;
}
Expand All @@ -33,6 +34,13 @@ Instrumenter.prototype = Object.create(istanbul.Instrumenter.prototype);
Instrumenter.prototype.constructor = Instrumenter;

Instrumenter.prototype.instrumentSync = function(code, fileName) {
var plugins = this.babelOptions.plugins;
// If we're running in coverage, we're assuming that this is running in CI or in some
// form of test scenario and not being built for production. So it's fine to always
// force this plugin to work.
for (var plugin of this.plugins) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you need to protect against prototype members here? (hasOwnProperty)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is normally going to be a simple array, but I can do it just to be absolutely safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we are safe here, because this is using "for...of" rather than "for...in". "for...of" only iterates over the elements of the collection:

Object.prototype.objCustom = function() {}; 
Array.prototype.arrCustom = function() {};

let iterable = [3, 5, 7];
iterable.foo = 'hello';

for (let i in iterable) {
  console.log(i); // logs 0, 1, 2, "foo", "arrCustom", "objCustom"
}

for (let i of iterable) {
  console.log(i); // logs 3, 5, 7
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

I missed that, Looks good.

plugins.push(plugin);
}
var result = this._r = (0, babelTransform)(code, extend({}, this.babelOptions, { filename: fileName }));
this._babelMap = new SourceMapConsumer(result.map);

Expand Down
5 changes: 5 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ function getDefaultConfig() {
'*/mirage/**/*'
],
useBabelInstrumenter: false,
// The reasoning behind this default is to match the default language version
// supported by Ember CLI. As of Ember CLI 2.13, it supports ES2017.
babelPlugins: [
'babel-plugin-transform-async-to-generator'
],
reporters: [
'html',
'lcov'
Expand Down
7 changes: 3 additions & 4 deletions lib/coverage-instrumenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require('string.prototype.startswith');
var existsSync = require('exists-sync');
var extend = require('extend');
var Filter = require('broccoli-filter');
var BabelInstrumenter = require('./babel-istanbul-instrumenter');
var Instrumenter = require('istanbul').Instrumenter;
Expand Down Expand Up @@ -65,10 +64,9 @@ function CoverageInstrumenter(inputNode, options) {
this._appRoot = options.appRoot;
this._isAddon = options.isAddon;
this._useBabelInstrumenter = options.useBabelInstrumenter;
this._babelPlugins = options.babelPlugins;

this._babelOptions = extend({
blacklist: ['es6.modules'] // Without this tests fail
}, options.babelOptions || {});
this._babelOptions = options.babelOptions || {};

// The presence of the following babel options cause tests to fail so let's
// simply remove them from the babel config
Expand Down Expand Up @@ -96,6 +94,7 @@ CoverageInstrumenter.prototype.processString = function(content, relativePath) {
if (this._useBabelInstrumenter) {
instrumenter = new BabelInstrumenter({
babel: this._babelOptions,
plugins: this._babelPlugins,
embedSource: true,
noAutoWrap: true
});
Expand Down
38 changes: 20 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"repository": "kategengler/ember-cli-code-coverage",
"engines": {
"node": ">= 0.10.0"
"node": ">= 4"
},
"author": "Katie Gengler",
"contributors": [
Expand All @@ -24,44 +24,46 @@
],
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.4.2",
"broccoli-asset-rev": "^2.4.5",
"chai": "^3.5.0",
"chai-files": "^1.2.0",
"ember-cli": "2.5.0",
"ember-cli": "^2.13.1",
"ember-cli-app-version": "^1.0.0",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-eslint": "^2.0.0",
"ember-cli-htmlbars": "^1.0.3",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-inject-live-reload": "^1.4.0",
"ember-cli-qunit": "^1.4.0",
"ember-cli-dependency-checker": "^1.3.0",
"ember-cli-eslint": "^3.0.0",
"ember-cli-htmlbars": "^1.1.1",
"ember-cli-htmlbars-inline-precompile": "^0.4.0",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-qunit": "^4.0.0",
"ember-cli-release": "^1.0.0-beta.1",
"ember-cli-shims": "^1.1.0",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^1.2.0",
"ember-disable-prototype-extensions": "^1.1.0",
"ember-exam": "0.6.0",
"ember-export-application-global": "^1.0.5",
"ember-load-initializers": "^0.5.1",
"ember-resolver": "^2.0.3",
"ember-try": "^0.2.2",
"ember-exam": "0.7.0",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.0.0",
"ember-resolver": "^4.0.0",
"ember-source": "~2.13.0",
"eslint": "^2.10.2",
"glob": "^7.0.3",
"loader.js": "^4.0.1",
"loader.js": "^4.2.3",
"mocha": "^2.4.5",
"sinon": "^1.17.4"
},
"keywords": [
"ember-addon"
],
"dependencies": {
"babel-core": "^5.8.38",
"babel-core": "^6.24.1",
"babel-plugin-transform-async-to-generator": "^6.24.1",
"body-parser": "^1.15.0",
"broccoli-filter": "^1.2.3",
"broccoli-funnel": "^1.0.1",
"broccoli-merge-trees": "^1.1.1",
"ember-cli-babel": "^5.1.6",
"ember-cli-babel": "^6.0.0",
"escodegen": "^1.8.0",
"esprima": "^2.7.2",
"esprima": "^3.1.3",
"exists-sync": "0.0.3",
"extend": "^3.0.0",
"fs-extra": "^0.26.7",
Expand Down
36 changes: 35 additions & 1 deletion test/integration/coverage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ describe('`ember test`', function() {
});

afterEach(function() {
return remove('tests/dummy/config/coverage.js');
return RSVP.all([
remove('tests/dummy/config/coverage.js'),
remove('tests/dummy/app/routes/index.js')
]);
});

it('runs coverage when env var is set', function() {
Expand All @@ -40,6 +43,37 @@ describe('`ember test`', function() {
});
});

it('uses the babel instrumenter when the configuration is set', function() {
this.timeout(100000);
fs.copySync('tests/dummy/config/coverage-babel.js', 'tests/dummy/config/coverage.js');
return runCommand('ember', ['test'], {env: {COVERAGE: true}}).then(function() {
expect(file('coverage/lcov-report/index.html')).to.not.be.empty;
expect(file('coverage/index.html')).to.not.be.empty;
var summary = fs.readJSONSync('coverage/coverage-summary.json');
expect(summary.total.lines.pct).to.equal(100);
});
});

it('works with the babel instrumenter and ES2017 async functions', function() {
this.timeout(100000);
fs.copySync('tests/dummy/config/coverage-babel.js', 'tests/dummy/config/coverage.js');
// We want something that will always be evaluated whenever the app starts.
fs.writeFileSync('tests/dummy/app/routes/index.js', `
import Ember from 'ember';
export default Ember.Route.extend({
async model() {
return {};
}
});
`);
return runCommand('ember', ['test'], {env: {COVERAGE: true}}).then(function() {
expect(file('coverage/lcov-report/index.html')).to.not.be.empty;
expect(file('coverage/index.html')).to.not.be.empty;
var summary = fs.readJSONSync('coverage/coverage-summary.json');
expect(summary.total.lines.pct).to.equal(100);
});
});

it('uses parallel configuration and merges coverage when merge-coverage command is issued', function() {
this.timeout(100000);
expect(dir('coverage')).to.not.exist;
Expand Down
6 changes: 1 addition & 5 deletions tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module.exports = {
env: {
'embertest': true
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module'
embertest: true
}
};
8 changes: 4 additions & 4 deletions tests/dummy/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

{{content-for "head"}}

<link rel="stylesheet" href="assets/vendor.css">
<link rel="stylesheet" href="assets/dummy.css">
<link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link rel="stylesheet" href="{{rootURL}}assets/dummy.css">

{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}

<script src="assets/vendor.js"></script>
<script src="assets/dummy.js"></script>
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/dummy.js"></script>

{{content-for "body-footer"}}
</body>
Expand Down
3 changes: 2 additions & 1 deletion tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Ember from 'ember';
import config from './config/environment';

const Router = Ember.Router.extend({
location: config.locationType
location: config.locationType,
rootURL: config.rootURL
});

Router.map(function() {
Expand Down
5 changes: 5 additions & 0 deletions tests/dummy/config/coverage-babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* eslint-env node */

module.exports = {
useBabelInstrumenter: true
};
2 changes: 1 addition & 1 deletion tests/dummy/config/coverage-parallel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*jshint node:true*/
/* eslint-env node */

module.exports = {
parallel: true
Expand Down
Loading