Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
51eedbc
Add `includePolyfill` to removed babel options.
rwjblue Jun 30, 2016
237ca96
Merge pull request #19 from kategengler/rwjblue-patch-1
rwjblue Jun 30, 2016
62b73ab
Released v0.2.2
rwjblue Jun 30, 2016
dc9c95f
Use chrome, not phantom for tests
kategengler Aug 8, 2016
f2ba0e8
Avoid requiring jQuery for sending the coverage report back.
Aug 3, 2016
f02b445
Merge pull request #24 from rwjblue/avoid-jquery
kategengler Aug 8, 2016
7927ba6
Update README.md
kategengler Aug 11, 2016
9b6bf34
Update README.md
kategengler Aug 11, 2016
031b969
Cover untested files WIP
EWhite613 Aug 18, 2016
f4100fe
Split moduleName into parts and check so we don't accidently pick up …
EWhite613 Aug 18, 2016
1ebdf10
Should exclude
EWhite613 Aug 18, 2016
f3eb8c0
No app.use
EWhite613 Aug 19, 2016
9fdfb6d
jscs fixes
EWhite613 Aug 19, 2016
c283a5b
Fix test
EWhite613 Aug 19, 2016
9abc062
Flip so there is only one POST request rather than multiple.
EWhite613 Aug 22, 2016
b0e3f48
Fix tests and jscs
EWhite613 Aug 22, 2016
e5d3955
Merge pull request #31 from kategengler/addon-spike
rwjblue Sep 14, 2016
c73da3a
0.3.0
Sep 14, 2016
4e64a93
Update CHANGELOG.md
Sep 14, 2016
7981977
Remove stray console.log
Sep 14, 2016
8257142
Merge pull request #35 from arjansingh/remove-stray-logging
Sep 14, 2016
e6ed56b
Some clarifications in Readme
kategengler Sep 15, 2016
d7f0130
Update README.md
kategengler Sep 15, 2016
ade117d
Update README.md
kategengler Sep 15, 2016
a4368a7
Update README.md
kategengler Sep 15, 2016
89f6883
Update CHANGELOG for 0.3.1.
Sep 15, 2016
a65761b
0.3.1
Sep 15, 2016
880ba91
add Windows notes
Sep 15, 2016
bd9b0b5
Merge pull request #38 from kategengler/kellyselden-patch-1
rwjblue Sep 15, 2016
49cdf93
Fix hang when running in PhantomJS.
dfreeman Sep 19, 2016
d15322f
Merge pull request #43 from dfreeman/phantom-hang
rwjblue Sep 19, 2016
05ab44e
Update CHANGELOG for v0.3.2.
Sep 19, 2016
0b6ebaa
0.3.2
Sep 19, 2016
63c3b46
Handle addons with different package names.
dfreeman Sep 21, 2016
13630de
Merge pull request #46 from dfreeman/mismatched-package-names
rwjblue Oct 7, 2016
e66c4df
Use posix paths for dealing with modules.
rwjblue Oct 7, 2016
3817c85
Merge pull request #50 from kategengler/dont-mix-path-seps
rwjblue Oct 7, 2016
1afa6ed
0.3.3
Oct 7, 2016
0cdccce
Update CHANGELOG for 0.3.3.
Oct 7, 2016
ecdae6e
return actual name not function from _parentName
nfc036 Oct 10, 2016
dae3da1
parent.name is function not string
nfc036 Oct 10, 2016
6f86df5
Update index.js
nfc036 Oct 10, 2016
cf836fc
Merge pull request #52 from nfc036/master
rwjblue Oct 10, 2016
5b33adb
Update CHANGELOG.md for 0.3.4.
Oct 10, 2016
473e2d6
0.3.4
Oct 10, 2016
0fdc0b1
Cosmetics for docs, renamed function name and parameter name
nfc036 Oct 10, 2016
4a87868
removed trailing spaces (eslint)
nfc036 Oct 10, 2016
3874560
Merge pull request #54 from nfc036/master
rwjblue Oct 10, 2016
77efe39
Merge remote-tracking branch 'upstream/master' into untested-files
EWhite613 Oct 12, 2016
4344050
Fixes based on comments
EWhite613 Oct 14, 2016
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
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ node_js:
- "4.2"
- "5"

sudo: false
dist: trusty
sudo: required

addons:
apt:
sources:
- google-chrome
packages:
- google-chrome-stable

cache:
directories:
Expand All @@ -24,6 +32,8 @@ matrix:
env: NPM_SCRIPT=lint

before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- "npm config set spin false"
- "npm install -g npm@^2"

Expand Down
132 changes: 126 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,128 @@
- 0.1.2
Bugfix: Fix config to override defaults (thanks @rwjblue)
# Change Log

- 0.1.1
Bugfix: For QUnit users: support for `/tests` and older ember-cli (`< 2.4.3`) versions
## [v0.3.4](https://github.com/kategengler/ember-cli-code-coverage/tree/v0.3.4) (2016-10-10)
[Full Changelog](https://github.com/kategengler/ember-cli-code-coverage/compare/v0.3.3...v0.3.4)

- 0.1.0
Initial release.
**Closed issues:**

- Missing coverage information in top-level addons in 0.3.3. [\#53](https://github.com/kategengler/ember-cli-code-coverage/issues/53)

**Merged pull requests:**

- return actual name not function from \_parentName [\#52](https://github.com/kategengler/ember-cli-code-coverage/pull/52) ([nfc036](https://github.com/nfc036))

## [v0.3.3](https://github.com/kategengler/ember-cli-code-coverage/tree/v0.3.3) (2016-10-07)
[Full Changelog](https://github.com/kategengler/ember-cli-code-coverage/compare/v0.3.2...v0.3.3)

**Closed issues:**

- Addon support: no coverage for addon files on Windows [\#48](https://github.com/kategengler/ember-cli-code-coverage/issues/48)
- No coverage when addon and package name don't match [\#45](https://github.com/kategengler/ember-cli-code-coverage/issues/45)
- Mocha phantom addon coverage issue in master causing a global error. [\#32](https://github.com/kategengler/ember-cli-code-coverage/issues/32)

**Merged pull requests:**

- Use posix paths for dealing with modules. [\#50](https://github.com/kategengler/ember-cli-code-coverage/pull/50) ([rwjblue](https://github.com/rwjblue))
- Handle addons with different package names [\#46](https://github.com/kategengler/ember-cli-code-coverage/pull/46) ([dfreeman](https://github.com/dfreeman))

## [v0.3.2](https://github.com/kategengler/ember-cli-code-coverage/tree/v0.3.2) (2016-09-19)
[Full Changelog](https://github.com/kategengler/ember-cli-code-coverage/compare/v0.3.1...v0.3.2)

**Closed issues:**

- Integration components support [\#40](https://github.com/kategengler/ember-cli-code-coverage/issues/40)
- Addon tests never exit [\#37](https://github.com/kategengler/ember-cli-code-coverage/issues/37)

**Merged pull requests:**

- Fix hang when running in PhantomJS. [\#43](https://github.com/kategengler/ember-cli-code-coverage/pull/43) ([dfreeman](https://github.com/dfreeman))
- add Windows notes [\#38](https://github.com/kategengler/ember-cli-code-coverage/pull/38) ([kellyselden](https://github.com/kellyselden))

## [v0.3.1](https://github.com/kategengler/ember-cli-code-coverage/tree/v0.3.1) (2016-09-15)
[Full Changelog](https://github.com/kategengler/ember-cli-code-coverage/compare/v0.3.0...v0.3.1)

**Closed issues:**

- Add code coverage [\#34](https://github.com/kategengler/ember-cli-code-coverage/issues/34)

**Merged pull requests:**

- Remove stray console.log [\#35](https://github.com/kategengler/ember-cli-code-coverage/pull/35) ([arjansingh](https://github.com/arjansingh))

## [v0.3.0](https://github.com/kategengler/ember-cli-code-coverage/tree/v0.3.0) (2016-09-14)
[Full Changelog](https://github.com/kategengler/ember-cli-code-coverage/compare/v0.2.2...v0.3.0)

**Closed issues:**

- does not work with addons [\#26](https://github.com/kategengler/ember-cli-code-coverage/issues/26)
- Does not appear to work with decorators [\#25](https://github.com/kategengler/ember-cli-code-coverage/issues/25)
- No Coverage generated got following error [\#21](https://github.com/kategengler/ember-cli-code-coverage/issues/21)
- Support Addon Coverage [\#14](https://github.com/kategengler/ember-cli-code-coverage/issues/14)

**Merged pull requests:**

- Support Addon Coverage [\#31](https://github.com/kategengler/ember-cli-code-coverage/pull/31) ([rwjblue](https://github.com/rwjblue))
- Processed addon js files [\#30](https://github.com/kategengler/ember-cli-code-coverage/pull/30) ([EWhite613](https://github.com/EWhite613))
- Avoid requiring jQuery for sending the coverage report back. [\#24](https://github.com/kategengler/ember-cli-code-coverage/pull/24) ([rwjblue](https://github.com/rwjblue))
- Try catch around instrumenter. So it spits out a clearer error [\#22](https://github.com/kategengler/ember-cli-code-coverage/pull/22) ([EWhite613](https://github.com/EWhite613))

## [v0.2.2](https://github.com/kategengler/ember-cli-code-coverage/tree/v0.2.2) (2016-06-30)
[Full Changelog](https://github.com/kategengler/ember-cli-code-coverage/compare/v0.2.1...v0.2.2)

**Closed issues:**

- Enabling useBabelInstrumenter results in "Unknown option: direct.includePolyfill" error [\#18](https://github.com/kategengler/ember-cli-code-coverage/issues/18)
- Should .hbs files be taken into account? [\#17](https://github.com/kategengler/ember-cli-code-coverage/issues/17)

**Merged pull requests:**

- Add `includePolyfill` to removed babel options. [\#19](https://github.com/kategengler/ember-cli-code-coverage/pull/19) ([rwjblue](https://github.com/rwjblue))

## [v0.2.1](https://github.com/kategengler/ember-cli-code-coverage/tree/v0.2.1) (2016-06-22)
[Full Changelog](https://github.com/kategengler/ember-cli-code-coverage/compare/v0.2.0...v0.2.1)

**Closed issues:**

- Coverage is against transpiled ES5 Code [\#12](https://github.com/kategengler/ember-cli-code-coverage/issues/12)

**Merged pull requests:**

- Update ember-cli-release to allow easier releasing. [\#16](https://github.com/kategengler/ember-cli-code-coverage/pull/16) ([rwjblue](https://github.com/rwjblue))
- Report Correct Line Numbers for esnext [\#15](https://github.com/kategengler/ember-cli-code-coverage/pull/15) ([sandersky](https://github.com/sandersky))

## [v0.2.0](https://github.com/kategengler/ember-cli-code-coverage/tree/v0.2.0) (2016-06-21)
[Full Changelog](https://github.com/kategengler/ember-cli-code-coverage/compare/v0.1.2...v0.2.0)

**Closed issues:**

- paths in "lcov.info" don't relate to project setup [\#8](https://github.com/kategengler/ember-cli-code-coverage/issues/8)
- files from addons bleed into coverage results [\#7](https://github.com/kategengler/ember-cli-code-coverage/issues/7)
- Change config file name? [\#4](https://github.com/kategengler/ember-cli-code-coverage/issues/4)

**Merged pull requests:**

- Filter out files from addons, fix file paths, and rename config file [\#11](https://github.com/kategengler/ember-cli-code-coverage/pull/11) ([sandersky](https://github.com/sandersky))
- Add ember-cli-mirage min version to README.md [\#3](https://github.com/kategengler/ember-cli-code-coverage/pull/3) ([benoror](https://github.com/benoror))

## [v0.1.2](https://github.com/kategengler/ember-cli-code-coverage/tree/v0.1.2) (2016-05-15)
[Full Changelog](https://github.com/kategengler/ember-cli-code-coverage/compare/v0.1.1...v0.1.2)

**Closed issues:**

- Take over the 'ember-cli-istanbul' package? [\#6](https://github.com/kategengler/ember-cli-code-coverage/issues/6)
- Testem global not found [\#1](https://github.com/kategengler/ember-cli-code-coverage/issues/1)

**Merged pull requests:**

- Allow users config to override the default config. [\#5](https://github.com/kategengler/ember-cli-code-coverage/pull/5) ([rwjblue](https://github.com/rwjblue))

## [v0.1.1](https://github.com/kategengler/ember-cli-code-coverage/tree/v0.1.1) (2016-05-05)
[Full Changelog](https://github.com/kategengler/ember-cli-code-coverage/compare/v0.1.0...v0.1.1)

## [v0.1.0](https://github.com/kategengler/ember-cli-code-coverage/tree/v0.1.0) (2016-05-03)
[Full Changelog](https://github.com/kategengler/ember-cli-code-coverage/compare/v0.0.1...v0.1.0)

## [v0.0.1](https://github.com/kategengler/ember-cli-code-coverage/tree/v0.0.1) (2016-05-03)


\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Code coverage using [Istanbul](https://github.com/gotwarlost/istanbul) for Ember
## Requirements
* If using Mocha, Testem `>= 1.6.0` for which you need ember-cli `> 2.4.3`
* If using Mirage you need `ember-cli-mirage >= 0.1.13`
* If using Pretender you need `pretender >= 0.11.0`
* If using Pretender (even as a dependency of Mirage) you need `pretender >= 0.11.0`
* If using Mirage or Pretender, you need to [set up a passthrough for coverage to be written](#create-a-passthrough-when-intercepting-all-ajax-requests-in-tests).


## Installation
Expand All @@ -14,15 +15,23 @@ Code coverage using [Istanbul](https://github.com/gotwarlost/istanbul) for Ember

## Usage

Coverage will only be generated when an environment variable is true (by default `COVERAGE`) and running your test command like normal.
Coverage will only be generated when an [environment variable](https://en.wikipedia.org/wiki/Environment_variable) is true (by default `COVERAGE`) and running your test command like normal.

For example:

`COVERAGE=true ember test`

If you want your coverage to work on both Unix and Windows, you can do this:

`npm install cross-env --save-dev`

and then:

`cross-env COVERAGE=true ember test`

## Configuration

Configuration is optional. It should be put in a file at `config/coverage.js`.
Configuration is optional. It should be put in a file at `config/coverage.js`.

#### Options

Expand All @@ -36,9 +45,16 @@ 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`.

## Using when intercepting all ajax requests in tests
#### Example
```js
module.exports = {
coverageEnvVar: 'COV'
}
```

## Create a passthrough when intercepting all ajax requests in tests

Aka when using ember-cli-mirage or Pretender. You may require a version of Pretender that includes [this fix](https://github.com/pretenderjs/pretender/pull/130).
(When using ember-cli-mirage or Pretender.)

To work, this addon has to post coverage results back to a middleware at `/write-coverage`.

Expand Down
54 changes: 42 additions & 12 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 All @@ -90,7 +90,12 @@ module.exports = {
*/
testemMiddleware: function(app) {
if (!this._isCoverageEnabled()) { return; }
attachMiddleware(app, { root: this.project.root, ui: this.ui });
attachMiddleware(app,
{
root: this.project.root,
ui: this.ui,
appName: this.parent.pkg.name,
excludes: this._getConfig().excludes || [] });
},

// Custom Methods
Expand Down Expand Up @@ -124,20 +129,23 @@ 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),''));
_doesFileExistInCurrentProjectAddonModule: function(relativePath) {
var relativePathWithoutProjectNamePrefix = relativePath.replace('modules' + '/' + this._parentName(), '');
var _relativePath = 'addon/' + relativePathWithoutProjectNamePrefix;

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

return this._doesTemplateFileExist(relativePath);
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 @@ -203,11 +211,9 @@ module.exports = {
this._doesFileExistInDummyApp(relativePath) ||
this._doesFileExistInCurrentProjectApp(relativePath) ||
this._doesFileExistInCurrentProjectAddon(relativePath) ||
this._doesFileExistIsCurrentProjectAddonModule(relativePath)
this._doesFileExistInCurrentProjectAddonModule(relativePath)
);

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

return !fileExists;
},

Expand All @@ -225,7 +231,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 @@ -243,5 +249,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;
}
};
38 changes: 37 additions & 1 deletion lib/attach-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var Istanbul = require('istanbul');
var config = require('./config');
var path = require('path');
var fs = require('fs-extra');

var minimatch = require('minimatch')

@sglanzer-fire sglanzer-fire Oct 12, 2016 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we re-use the ember-cli glob dependency for this? It's using minimatch under the covers

function logError(err, req, res, next) {
console.error(err.stack);
next(err);
Expand Down Expand Up @@ -34,4 +34,40 @@ module.exports = function(app, options) {
});
},
logError);

function shouldExclude(moduleName, excludes) {
for (var i = 0; i < excludes.length; i++) {
if (minimatch(moduleName, excludes[i])) {
return true
}
}
return false
}
app.post('/filter-entries',bodyParser.urlencoded({

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why post?

limit: options.root.coveragePostLimit ||'50mb',
extended: false,
parameterLimit: options.root.coveragePostParameterLimit ||10000
}),bodyParser.json({
limit: options.root.coveragePostLimit || '50mb'
}),
function(req, res) {
var entries = req.body['entries[]'] || req.body.entries

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you comment on the need for this?

var seen = {}
var appName = options.appName
var filteredEntries = entries.filter(function(entry) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can the filter be handled in the middleware so that we only get a list of entries that weren't loaded?

var result = false
if (typeof (seen[entry]) === 'undefined') {
var parts = entry.split('/')
if (parts.length >= 1 && parts[0] === appName || parts.length >= 2 && parts[0] === 'dummy' && parts[1] === appName) {

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'm wary of this - @rwjblue is this a predictable/consistent format that can be relied on?

if (!shouldExclude(entry, options.excludes)) {
result = true
}
}
seen[entry] = true;
return result
}
return result
})
res.send({entries: filteredEntries})
})
};
3 changes: 2 additions & 1 deletion lib/coverage-instrumenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ function CoverageInstrumenter(inputNode, options) {
// simply remove them from the babel config
[
'compileModules',
'resolveModuleSource'
'resolveModuleSource',
'includePolyfill'
].forEach(function(key) {
delete this._babelOptions[key];
}.bind(this));
Expand Down
Loading