Giter Site home page Giter Site logo

ember-cli-code-coverage's Introduction

ember-cli-code-coverage

npm version CI

Code coverage using Istanbul for Ember apps.

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 (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.
  • ember-cli-babel >= 6.0.0

Installation

  • ember install ember-cli-code-coverage

Setup

In order to gather code coverage information, you must first install the Babel plugins in each project that you'd like to have instrumented.

For classic apps (ember-cli-build.js):

let app = new EmberApp(defaults, {
  babel: {
    plugins: [...require('ember-cli-code-coverage').buildBabelPlugin()],
  },
});

For embroider apps (ember-cli-build.js):

let app = new EmberApp(defaults, {
  babel: {
    plugins: [...require('ember-cli-code-coverage').buildBabelPlugin({ embroider: true })],
  },
});

For in-repo and standalone addons (index.js):

module.exports = {
  name: require('./package').name,

  options: {
    babel: {
      plugins: [...require('ember-cli-code-coverage').buildBabelPlugin()],
    },
  },
};

For in-repo engines (index.js):

module.exports = EngineAddon.extend({
  // ...
  included() {
    this._super.included.apply(this, arguments);
    this.options.babel.plugins.push(...require('ember-cli-code-coverage').buildBabelPlugin());
  },
});

For app files in standalone addons (ember-cli-build.js):

let app = new EmberAddon(defaults, {
  babel: {
    plugins: [...require('ember-cli-code-coverage').buildBabelPlugin()]
  },
});

tests/test-helpers.js:

import { forceModulesToBeLoaded, sendCoverage } from 'ember-cli-code-coverage/test-support';
import Qunit from 'qunit';

QUnit.done(async function() {
  forceModulesToBeLoaded();
  await sendCoverage();
});

Usage

Coverage will only be generated when an 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

When running with parallel set to true, the final reports can be merged by using ember coverage-merge. The final merged output will be stored in the coverageFolder.

If you intend to use ember test with the --path flag, you should generate the build with coverageEnvVar set as true. This is because the code is instrumented for coverage during the build.

For example:

COVERAGE=true ember build --environment=test --output-path=dist

followed by

COVERAGE=true ember test --path=dist

TypeScript integration

Steps:

  • in tsconfig.json
  {
    "compilerOptions": {
      "inlineSourceMap": true,
      "inlineSources": true
    }
  }
  • in ember-cli-build.js
  const app = new EmberApp(defaults, {
    babel: {
      sourceMaps: 'inline'
    },
    sourcemaps: {
      enabled: true,
      extensions: ['js']
    }
  });
  • in package.json specify latest available version
  {
    devDependencies: {
      "ember-cli-code-coverage": "^2.1.0",
    }
  }

ember-template-imports integration

  • in `ember-cli-build.js
  const app = new EmberApp(defaults, {
    'ember-template-imports': {
      inline_source_map: true,
    },
  });

Configuration

Configuration is optional. It should be put in a file at config/coverage.js (configPath configuration in package.json is honored). In addition to this you can configure Istanbul by adding a .istanbul.yml file to the root directory of your app (See https://github.com/gotwarlost/istanbul#configuring)

Options

  • coverageEnvVar: Defaults to COVERAGE. This is the environment variable that when set will cause coverage metrics to be generated.

  • reporters: Defaults to ['lcov', 'html']. The json-summary reporter will be added to anything set here, it is required. This can be any reporters supported by Istanbul.

  • excludes: Defaults to ['*/mirage/**/*']. An array of globs to exclude from instrumentation. Useful to exclude files from coverage statistics.

  • extension: Defaults to ['.gjs', '.gts', '.js', '.ts', '.cjs', '.mjs', '.mts', '.cts']. Tell Istanbul to instrument only files with the provided extensions.

  • coverageFolder: Defaults to coverage. A folder relative to the root of your project to store coverage results.

  • parallel: Defaults to false. Should be set to true if parallel testing is being used for separate test runs, for example when using ember-exam with the --partition 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 (potentially as part of the posttest hook in your package.json).

  • modifyAssetLocation: Optional function that will allow you to override where a file actually lives inside of your project. See Advanced customization on how to use this function in practice.

Example

  module.exports = {
    coverageEnvVar: 'COV'
  }

Create a passthrough when intercepting all ajax requests in tests

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

If you are using ember-cli-mirage you should add the following:

// in mirage/config.js

  this.passthrough('/write-coverage');
  this.namespace = 'api';  // It's important that the passthrough for coverage is before the namespace, otherwise it will be prefixed.

If you are using ember-cli-pretender you should add the following:

// where ever you set up the Pretender Server

  var server = new Pretender(function () {
    this.post('/write-coverage', this.passthrough);
  });

Advanced customization

forceModulesToBeLoaded

The forceModulesToBeLoaded function can potentially cause unintended side effects when executed. You can pass custom filter fuctions that allow you to specify which modules will be force loaded or not:

QUnit.done(async () => {
  // type will be either webpack and/or require
  forceModulesToBeLoaded((type, moduleName) => { return true; });
  await sendCoverage();
});

modifyAssetLocation

Under the hood, ember-cli-code-coverage attempts to "de-namespacify" paths into their real on disk location inside of project.root (ie give a namespaced path like lib/inrepo/components/foo.js would live in lib/inrepo/addon/components/foo.js). It makes some assumptions (where files live in in-repo addons vs app code for example) and sometimes those assumptions might not hold. Passing a function modifyAssetLocation in your configuration file will allow you to override where a file actually lives inside of your project. The returned string should be relative to your project root.

module.exports = {
  modifyAssetLocation(root, relativePath) {
    let appPath = relativePath.replace('my-project-name', 'app');

    // here is an example of saying that `app/components/foo.js` actually
    // lives in `lib/inrepo/app/components/foo.js` on disk.
    if (fs.existsSync(path.join(root, 'lib', 'inrepo', appPath))) {
      return path.join('lib', 'inrepo', appPath);
    }

    return false;
  },
};

Inspiration

This addon was inspired by ember-cli-blanket. The primary differences are that this addon uses Istanbul rather than Blanket for coverage and it instruments your application code as part of the build, when enabled.

ember-cli-code-coverage's People

Contributors

abishek-srinivasan avatar adamjmcgrath avatar amauryd avatar astronomersiva avatar dependabot[bot] avatar designblooz avatar dfreeman avatar dingoeatingfuzz avatar ember-tomster avatar ewhite613 avatar jdenly avatar kategengler avatar lifeart avatar luketheobscure avatar mgmarcum avatar ming-codes avatar nfc036 avatar paulcwatts avatar rajasegar avatar rmachielse avatar robbiethewagner avatar robinborst95 avatar rwjblue avatar sandersky avatar selvaa89 avatar thoov avatar tomichal avatar turbo87 avatar vstefanovic97 avatar wagenet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-cli-code-coverage's Issues

Does not work with CoffeeScript

It looks like files compiled from CoffeeScript (using ember-cli-coffeescript) are not included when calculating code coverage. They don't show up on any of the reports.

paths in "lcov.info" don't relate to project setup

After I resolve #7, I saw that the paths in "lcov.info" are not right. I was getting in my coveralls logs Error: ENOENT: no such file or directory, open '/home/travis/build/kellyselden/package-hint-historic-resolver/package-hint-historic-resolver/adapters/application.js'. It seems the second "app name" needs to be either "app" or "addon" for the path to be correct for coveralls and maybe other reporters.

Coverage is against transpiled ES5 Code

When using ES6 in my project (also using ES7 decorators via ember-computed-decorators), the code coverage being reported is against the transpiled ES5 code. In order to make the coverage report more useful when using services such as Coveralls or editor plugins such as lcov-info for Atom, the coverage should report against line numbers in the original source code.

new error in 0.3.7

I'm testing out the difference between 0.3.5 and 0.3.7 in my app. 0.3.5 generates the coverage folder. 0.3.6 threw on requiring invalid files. 0.3.7 doesn't generate the coverage folder, and shows this at the end of the console:

1..1258
# tests 1258
# pass  1237
# skip  21
# fail  0

# ok
Error
    at IncomingMessage.onAborted (/my-project/node_modules/raw-body/index.js:269:10)
    at emitNone (events.js:86:13)
    at IncomingMessage.emit (events.js:185:7)
    at abortIncoming (_http_server.js:284:11)
    at Socket.serverSocketCloseListener (_http_server.js:297:5)
    at emitOne (events.js:101:20)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:501:12)

The coverage summary json is missing a '}' in the end

Hi

After running COVERAGE=true ember test and opening coverage_summary.json file, the file shows that json is not totally formatted. And adding '}' in the end takes care of the issue. Just wanted to report the issue.

No Coverage generated got following error

After ember-cli-code-coverage used following command "COVERAGE=true ember test" to run the test
getting following error:

{ type: 'error',
text: 'Error: Pretender intercepted POST /write-coverage but no handler was defined for this type of request at http://localhost:7357/assets/vendor.js, line 68809\n' }

Do I need to do any configuration on my end?

//env:
Package.json
"devDependencies": {
"broccoli-asset-rev": "^2.2.0",
"ember-ajax": "0.7.1",
"ember-cli": "2.5.0",
"ember-cli-app-version": "^1.0.0",
"ember-cli-babel": "^5.1.5",
"ember-cli-code-coverage": "0.2.2",
"ember-cli-dependency-checker": "^1.2.0",
"ember-cli-htmlbars": "^1.0.1",
"ember-cli-htmlbars-inline-precompile": "^0.3.1",
"ember-cli-inject-live-reload": "^1.3.1",
"ember-cli-pretender": "0.6.0",
"ember-cli-qunit": "^1.1.0",
"ember-cli-release": "0.2.8",
"ember-cli-sri": "^2.0.0",
"ember-cli-uglify": "^1.2.0",
"ember-disable-proxy-controllers": "^1.0.1",
"ember-export-application-global": "^1.0.4",
"ember-load-initializers": "0.5.1",
"ember-resolver": "^2.0.3",
"loader.js": "4.0.10"
}
Bower.json:
"dependencies": {
"ember": "2.5.0",
"ember-cli-shims": "0.1.0",
"ember-cli-test-loader": "0.2.2",
"ember-load-initializers": "0.1.7",
"ember-qunit-notifications": "0.1.0",
"jquery": "1.11.3",
"loader.js": "^3.5.0",
"qunit": "~1.20.0",
"pretender": "^0.12.0",
"bootstrap": "3.1.1",
"moment": "~2.11.1",
"markdown": "~0.5.0",
"bootstrap-tokenfield": "~0.12.1"
},

Does not include untested files

Is there an option to include files that are part of the app/ folder but haven't been executed when running tests?

Not doing so results in a wrong, overstated coverage score.

conflict with yadda require()

I am running tests with code-coverage on and using ember-cli-yadda and yadda. Yadda is setting ember's global require() to its own function. This makes the coverage reporting fail in the script inserted into tests/index.html at this line of code. Since global require() is no longer ember's function, require.entries is undefined.

requirejs and requireModule are both still set to ember's function.

Other than asking yadda to not clobber require(), do you have any suggestions on a good way to have ember-cli-code-coverage work around this?

I am using v0.3.6, ember-cli/ember v2.9.1.

Support in-repo engine coverage

Ember-engines allow use in-repo style of engine location, in this case testing results of main app includes testing results of engine. But code coverage output, unlike tap file, not includes coverage results for engine.

Steps to reproduce:

Addon Support: Properly name files in `lcov.info`

Currently lcov.info namespaces addon code as: SF:modules/addon-name/models/ab.js

It should be: SF:addon/models/ab.js so that code coverage tools like Coveralls can properly parse the file.

I solved this using sed s/SF:modules\\/addon-name/SF:addon/ in my build jobs, but we probably should work on properly renaming it and save everyone the trouble. If someone could point me to some lines or functions to look at for context, I'll take it on.

Clearer documentation

I'm trying to set-up coverage on my Ember testing, but I can't seem to get this to work.

I've run ember install ember-cli-code-coverage. It is now in my node_modules folder.

I've tried adding coverage and COVERAGE parameters to the test_page property in testem.js e.g.

module.exports = {
  "framework": "qunit",
  "test_page": "tests/index.html?hidepassed&coverage",
  "disable_watching": true,
  "launch_in_ci": [
    "PhantomJS"
  ],
  "launch_in_dev": [
    "PhantomJS",
    "Chrome"
  ]
}

But when I run ember test or ember test --server, I'm not seeing any coverage files/folders generated. The tests are running without any issues or errors.

I'm assuming there's something obvious I'm not doing, based on seeing a few folk on Stack Overflow successfully using this module.

I'm running:

  • ember-cli 2.8.0
  • node 4.5.0
  • ubuntu 14.04

Work with ember test --server, not with ember test

Works fine with ember test --server (testem, qunit)

testem.js

/*jshint node:true*/
module.exports = {
  "framework": "qunit",
  "test_page": "tests/index.html?hidepassed",
  "disable_watching": true,
  "launch_in_ci": [
    "PhantomJS"
  ],
  "launch_in_dev": [
    "PhantomJS",
    "Chrome"
  ]
};

With ember test

# tests 1272
# pass  1272
# skip  0
# fail  0

# ok
Error: request aborted
    at IncomingMessage.onAborted (/home/office/myapp/frontend/node_modules/ember-cli-code-coverage/node_modules/body-parser/node_modules/raw-body/index.js:269:10)
    at emitNone (events.js:86:13)
    at IncomingMessage.emit (events.js:185:7)
    at abortIncoming (_http_server.js:283:11)
    at Socket.serverSocketCloseListener (_http_server.js:296:5)
    at emitOne (events.js:101:20)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:493:12)

Is this expected?

    "ember-cli": "2.8.0",
    "ember-cli-app-version": "^1.0.0",
    "ember-cli-babel": "^5.1.6",
    "ember-cli-chart": "3.1.0",
    "ember-cli-code-coverage": "0.3.4",
    "ember-cli-dependency-checker": "^1.2.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-jshint": "^1.0.0",
    "ember-cli-moment-shim": "2.2.1",
    "ember-cli-qunit": "^2.1.0"

"Error: request aborted" on >= v0.3.0

I've been toggling between v0.2.2 and v0.3.0 (or v0.3.1) and I'm getting a cryptic error in the new one.

1..1163
# tests 1163
# pass  1141
# skip  22
# fail  0

# ok
Error: request aborted
    at IncomingMessage.onAborted (/my-project-path/node_modules/raw-body/index.js:269:10)
    at emitNone (events.js:86:13)
    at IncomingMessage.emit (events.js:185:7)
    at abortIncoming (_http_server.js:280:11)
    at Socket.serverSocketCloseListener (_http_server.js:293:5)
    at emitOne (events.js:101:20)
    at Socket.emit (events.js:188:7)
    at TCP._handle.close [as _onclose] (net.js:493:12)

And it doesn't create the coverage folder. It worked fine in the older version. I'm not using mirage or pretender.

Issue with ember-page-object

I'm getting a strange error that I can't debug when I turn code-coverage on.

not ok 439 PhantomJS 2.1 - Global error: error requiring file for coverage: acl/blueprints/page-object-component at http://localhost:4201/assets/acl/vendor.js, line 228
    ---
        Log: |
            { type: 'error',
              text: 'error requiring file for coverage: acl/blueprints/page-object-component at http://localhost:4201/assets/acl/vendor.js, line 228\n' }
    ...

Weird thing is that I'm not using page-object-component anywhere so I'm not sure why its getting tested or pulled in. Also my project only has 438 tests so I'm guessing test 439 is one added by code-coverage? I'm running ember-lts (2.8), "ember-cli-code-coverage": "0.3.6", "ember-cli-mocha": "^0.10.4", "ember-cli-page-object": "1.3.0", and also using the babel instrumentor.

Even weirder, when I load up tests in a browser I can actually see acl/blueprints/page-object-component in my devtools.

No coverage when addon and package name don't match

We have an npm scope associated with our private registry, so our internal addons all have scoped package names like @scope/foo-bar. They use the unscoped version (foo-bar) for the name in their index.js, which unfortunately causes ember-cli-code-coverage to filter out all our actual addon files.

Locally, I've had success replacing instances of project.pkg.name with project.name(), which returns the package's "base name" (everything after the last /). It works for our use case, and I started to open a PR with that change, but it doesn't seem like it solves the underlying problem — the name in package.json and the name in index.js aren't necessarily related.

Given that the covered addon is looked up by name here, it seems like kind of a catch-22 unless there's another way to track down the Addon instance without knowing its name. Any guidance on this? Are mismatched package and addon names even something this addon needs to handle, or is it enough of an antipattern that it should just be discouraged?

config/coverage options for excludes don't seem to work

I have this version of ember-cli-code-coverage in my package.json "ember-cli-code-coverage": "0.3.8". Also I have a coverage file in this root path in my ember app.

config/coverage.js

module.exports = {
     // This is default value
    coverageEnvVar: 'COVERAGE',
     // More reporters found here https://github.com/gotwarlost/istanbul/tree/master/lib/report
    reporters: ['lcov', 'json', 'json-summary', 'text', 'text-summary'],
    // Defaults to ['*/mirage/**/*']
    excludes: [
        "/blueprints",
        "/config",
        "/public", 
        "/tmp", 
        "/tests/dummy/**",
        "/vendor"
    ],
    // Defaults to coverage. A folder relative to the root of your project to store coverage results.
    // Set to true or false if you are using ESNext features.
    useBabelInstrumenter: true
}

I have the following folder structure
➜ ember-webrtc-devices git:(master) tree -d -L 3 -I 'node_modules|bower_components'
.
├── addon
│   ├── components
│   │   └── device-selection
│   └── mixins
├── app
│   ├── components
│   │   └── device-selection
│   ├── mixins
│   └── translations
│   └── webrtc-devices
├── blueprints
│   └── ember-webrtc-devices
├── config
├── coverage
│   └── lcov-report
│   ├── addon
│   ├── app
│   └── tests
├── public
│   └── assets
│   └── sounds
├── scripts
├── tests
│   ├── dummy
│   │   ├── app
│   │   ├── config
│   │   └── public
│   ├── helpers
│   ├── integration
│   │   └── components
│   └── unit
│   └── mixins
├── tmp
├── typings
│   └── ember
└── vendor

36 directories

When I run npm run coverage which runs "coverage": "COVERAGE=true ember test"

I got the following code coverage report.

------------------------------------|----------|----------|----------|----------|----------------|

File % Stmts % Branch % Funcs % Lines Uncovered Lines
addon/components/device-selection/ 62.5 53.85 62.5 57.14
component.js 62.5 53.85 62.5 57.14 ... ,97,115,126
addon/mixins/ 29.82 19.74 33.33 25.23
device-enumeration.js 29.82 19.74 33.33 25.23 ... 267,268,270
app/components/device-selection/ 100 100 100 100
component.js 100 100 100 100
tests/dummy/app/ 100 100 0 100
app.js 100 100 100 100
resolver.js 100 100 100 100
router.js 100 100 0 100
tests/dummy/app/initializers/ 100 100 100 100
webrtc-service.js 100 100 100 100
tests/dummy/app/services/ 0 100 0 0
webrtc.js 0 100 0 0 13,14,18,19
------------------------------------ ---------- ---------- ---------- ---------- ----------------
All files 41.04 28.43 43.18 36.25
------------------------------------ ---------- ---------- ---------- ---------- ----------------

=============================== Coverage summary ===============================
Statements : 41.04% ( 71/173 ), 2 ignored
Branches : 28.43% ( 29/102 )
Functions : 43.18% ( 19/44 )
Lines : 36.25% ( 58/160 )

Since I specifically excluded tests/dummy why is code coverage reporting it is touched

Not generating coverage reports

[When running tests with COVERAGE=true, not generating results.

config/coverage.js has:
module.exports = {
reporters: ['lcov', 'html']
}

mirage/config.js has:
this.passthrough('/write-coverage');
(NOTE: When this was wrong, I got errors about ember not being able to POST to /write-coverage. Those errors are gone now)

I am running the tests like:
COVERAGE=true ember test

The tests run, but no results output. How can I triage this? Not sure where to go, because no errors are getting reported. (except a "Building(node) warning: possible EventEmitter memory leak detected. 11 exit listeners added." warning)

Support Addon Coverage

As of currently (v0.2.0) addon support for test coverage is not present. After testing it with my addon, Im only getting coverage for app/resolver.js which is pretty meaningless. Im opening up this issue to track the progress for this. Once this lands, ill go ahead and replace blanketjs with this in ember-addon-genie.

Addon tests never exit

Been trying to get code coverage working for ember-ajax but am running into an issue. When running

$ COVERAGE=true ember test

the tests start, run fine, and generate the coverage directory. However, the process never exists. Some configuration options that might be relevant:

  • Test are run through Mocha
  • ember-cli v2.8.0
  • ember-cli-pretender v0.7.0
  • pretender v1.2.0

If you want to try it out, I've pushed a branch here with ember-cli-code-coverage installed and an old version of Pretender that I thought might be causing trouble removed (although it didn't help).

I dug into the Testem middleware a bit, thinking that might be the cause of the problem. Everything seems to be working fine there; that code exists and all. Not really sure where to look from there.

Mocha phantom addon coverage issue in master causing a global error.

Hi guys, while trying out #31 using:

ember-cli: 2.7.0
node: 0.12.6
os: darwin x64
phantomjs: 1.9.8

I (accidentally) tried out the current master and started having a problem with a global error. After a bit of digging it seems that f2ba0e8 causes a broken test on a fresh addon, with just ember-cli-mocha installed when running Coverage=true ember test

ok 1 PhantomJS 1.9 - JSHint | app.js should pass jshint
ok 2 PhantomJS 1.9 - JSHint | helpers/destroy-app.js should pass jshint
ok 3 PhantomJS 1.9 - JSHint | helpers/module-for-acceptance.js should pass jshint
ok 4 PhantomJS 1.9 - JSHint | helpers/resolver.js should pass jshint
ok 5 PhantomJS 1.9 - JSHint | helpers/start-app.js should pass jshint
ok 6 PhantomJS 1.9 - JSHint | resolver.js should pass jshint
ok 7 PhantomJS 1.9 - JSHint | router.js should pass jshint
ok 8 PhantomJS 1.9 - JSHint | test-helper.js should pass jshint
not ok 9 PhantomJS 1.9 - Global error: INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable. at http://localhost:7357/8472/tests/index.html?hidepassed, line 48
    ---
        Log: |
            { type: 'error',
              text: 'INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable. at http://localhost:7357/8472/tests/index.html?hidepassed, line 48\n' }

After a quick look at the changes in the commit mentioned above, I found that by removing:

request.send(data);
request.responseType = 'json';

... and moving callback() out of the onload handler, it ran without error, but I'm not sure how a proper fix should look.

The tests run fine in Chrome, and are also fine without specifying COVERAGE=true.

[EDIT] Phantomjs 2.1 seems to have the same issue, but doesn't log the error - it just hangs after test 8.

Testem global not found

Hey @kategengler, I'm glad you finally released this addon 🎉, and also glad to be the first to fill an issue 😄

When I run the tests I get the following error:

$ COVERAGE=true ember test
version: 1.13.13
Built project successfully. Stored in "/Users/benoror/workspace/nimbox/tmp/class-tests_dist-aYKI4ECy.tmp".
not ok 1 PhantomJS 2.1 - global failure
    ---
        actual: >
            null
        message: >
            TypeError: undefined is not a constructor (evaluating 'Testem.afterTests(function(config, data, callback) {
                sendCoverage(callback);
              })')
        Log: |
    ...
...

I think it's due to global variable Testem not being loaded: 65821e5#diff-94eab975fb48e219fc130d82e21457acR32

Maybe related to my build script not injecting Testem during tests? Or maybe because of the Ember or Testem version I'm using?

Thanks in advance and kudos for this!

Take over the 'ember-cli-istanbul' package?

Hey there, I happen to have parked the ember-cli-istanbul package in npm (having fully planned to implement it, but priorities shifted at work 😦 ) Would you like to take over ownership of that?

Ensure `app/` files are required for addon coverage.

The current code that kicks off a require for each module will only require addon files in addon/ directory. It does not include app/ files (since they would be under dummy not my-addon-name).

In conjunction with #71, we should also kick off require's for dummy when in an addon.

Does not appear to work with decorators

I'm getting an error using decorators:

The Broccoli Plugin: [CoverageInstrumenter] failed with:
Error: Line 23: Unexpected token ILLEGAL

The line in question:

@equal('model.statusSort', IncidentConstants.incStatus.CLOSED) incidentIsClosed: null,

Coverage failing with version 0.3.6 and up

I seem to have an issue with v 0.3.6+ of ember-cli-code-coverage.
Running COVERAGE=true ember test kept failing after the last test was run ie when coverage would normally start. Its not repo specific. Doesnt matter what the tests are, this error always shows up at the end

not ok 29 Chrome 54.0 - FrostNavigationService "after each" hook
    ---
        message: >
            Uncaught TypeError: Cannot convert undefined or null to object (http://localhost:7357/5392/tests/index.html?hidepassed:43)
        stack: >
            Error: Uncaught TypeError: Cannot convert undefined or null to object (index.html?hidepassed:43)
                at global.onerror (http://localhost:7357/assets/test-support.js:8732:10)
        Log: |

I have pin pointed this to version 0.3.6 of ember-cli-code-coverage. Up to 0.3.5 everything works great. If you pin to v 0.3.5, coverage is reported properly. Could be related to this PR https://github.com/kategengler/ember-cli-code-coverage/pull/62/files
@rwjblue @rwwagner90

How to view coverage files?

Forgive me if this is a dumb question, but is there a way of viewing the generated coverage files from within Ember itself, or do I have to manually open those files on my computer from my web browser? As reference, I was using ember-cli-blanket previously, and I had the option of viewing coverage details when navigating to http://localhost/tests?coverage, which would run the tests and show coverage at the bottom. Does ember-cli-code-coverage have a similar option?

Change config file name?

config/coverage-config.js seems redundant, what do you think about changing the file to config/coverage.js or config/code-coverage.js?

What is the best way to wdio or selenium test on the instrumented code and the coveragae result

Scenario : We are trying to deploy a instrumented ember App on a internal server and run test using wdio test runner or any other test framework(Pytest). At the end of the test we will download the coverage result.

Our observation: What we have noticed that Unless we instrument and deploy the code on the same server where Istanbul middleware is running, we are not able to get the coverage information correctly. This is problematic when we have to run multipple different application.

Question: Is there any suggestion how to handle this scenario in a best possible way?

Excludes not working as expected with addon

Having now set up coverage for ember-ajax, I'm trying to get it working right.

The follow are the files that are having coverage calculated:

screen shot 2016-09-17 at 6 31 24 pm

However, I've tried to ignore the whole tests/dummy directory with the configuration here. It seems like the files are not actually being ignored.

Template Files not Being Included in Coverage Report

Library Versions:

  • ember: 2.4.3
  • ember-cli: 2.4.3
  • ember-cli-code-coverage: 0.3.2

Pods? Yes

When I run tests with COVERAGE=true inside an addon, I don't see the templates included in the coverage like they are inside standard ember apps.

Integration components support

Is this addon supporting integration components? Like for instance if I have an integration component test like the following one:

test('Should display number', function(assert) {
  this.set('number', 1);
  this.render(hbs`{{my-number number=number}}`);

  assert.equal(this.$('.number-class').text(), 1, 'Number is displayed');
});

Will this addon know that the involved properties or methods of the component are involved in the test and take that into account when providing the coverage result? In that case can you shortly explain how that works?

Thanks!

ember-test never terminates with COVERAGE=true

ember-cli: 2.10.0 ( also repro in previous version )
ember: 2.10.0
ember-cli-code-coverage: 0.38.0

ember t everything is good with no errors and proper termination. COVERAGE=true ember t everything succeeds and the coverage is generated as expected, but the process never terminates. When I run it in DEBUG="*" mode it seems to hang with:

  engine:ws writing "3" +0ms
  engine:ws received "2" +25s
  engine:socket packet +0ms
  engine:socket got ping +0ms
  engine:socket sending packet "pong" (undefined) +0ms
  engine:socket flushing buffer to transport +0ms
  engine:ws writing "3" +0ms
  engine:ws received "2" +25s
  engine:socket packet +0ms
  engine:socket got ping +0ms
  engine:socket sending packet "pong" (undefined) +0ms
  engine:socket flushing buffer to transport +0ms
  engine:ws writing "3" +0ms
  engine:ws received "2" +25s
  engine:socket packet +0ms
  engine:socket got ping +0ms
  engine:socket sending packet "pong" (undefined) +0ms
  engine:socket flushing buffer to transport +0ms
  engine:ws writing "3" +0ms

Looked into debugging phantom js but found no obvious errors.

Handle app in addon case

Unsure what we may need to handle here, as I think we want app included in coverage for addons, but was mentioned in talking with @rwjblue, so throwing up an issue to track.

cc @rwjblue

Excludes options for config/converage.js doesn't seem to work

Hello There

I have the following in in config/converage.js

module.exports = {
     // This is default value
    coverageEnvVar: 'COVERAGE',
     // More reporters found here https://github.com/gotwarlost/istanbul/tree/master/lib/report
    reporters: ['lcov', 'html'],
    // Defaults to ['*/mirage/**/*']
    excludes: [
        "/blueprints", 
        "/config", 
        "/public", 
        "/tmp", 
        "*/tests/dummy\/(.*)/",
        "/vendor"
    ],
    // Defaults to coverage. A folder relative to the root of your project to store coverage results.
    coverageFolder: coverage,
    // Set to true or false if you are using ESNext features.
    useBabelInstrumenter: true
}

But in the converage folder generated I see the following files
addon, app, lcov-report, test/dummy

What am I doing wrong here?

ESLint?

Should we use ESLint instead of JSHint? I see ESLint is already used, so should we swap out and do ember-cli-eslint to use all ESLint?

Addon support: no coverage for addon files on Windows

I did not get any coverage information for files within the addon subdirectory. This problem seems to be specific for windows environments. It seems, that the function here

 _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);
  },

in index.js has problems with the path separator on Windows ("/" vs. ""). Inserting relativePath = path.join(relativePath); as the first line in this function seems to solve this issue but this is most probably not the best solution. (I am not an expert on this...)

RFC: API to cover both adding and removing files from coverage

Now that we are requiring all files, issues like #65, #66, and #75 are popping up, and the problem may not be immediately clear. We also have files we want to stop covering in #71. I propose we unify any API to resolve these issues, or at least make them compatible. Maybe both a shouldInclude and a shouldExclude hook. That's about as far as I got in the thought process.

Enabling useBabelInstrumenter results in "Unknown option: direct.includePolyfill" error

ReferenceError: [BABEL] app/adapters/application.js: Unknown option: direct.includePolyfill
    at Logger.error (/home/lolmaus/Code/launchpad2/node_modules/babel-core/lib/transformation/file/logger.js:58:11)
    at OptionManager.mergeOptions (/home/lolmaus/Code/launchpad2/node_modules/babel-core/lib/transformation/file/options/option-manager.js:126:29)
    at OptionManager.init (/home/lolmaus/Code/launchpad2/node_modules/babel-core/lib/transformation/file/options/option-manager.js:216:10)
    at File.initOptions (/home/lolmaus/Code/launchpad2/node_modules/babel-core/lib/transformation/file/index.js:147:75)
    at new File (/home/lolmaus/Code/launchpad2/node_modules/babel-core/lib/transformation/file/index.js:137:22)
    at Pipeline.transform (/home/lolmaus/Code/launchpad2/node_modules/babel-core/lib/transformation/pipeline.js:164:16)
    at Instrumenter.instrumentSync (/home/lolmaus/Code/launchpad2/node_modules/ember-cli-code-coverage/lib/babel-istanbul-instrumenter.js:36:45)
    at CoverageInstrumenter.processString (/home/lolmaus/Code/launchpad2/node_modules/ember-cli-code-coverage/lib/coverage-instrumenter.js:100:23)
    at CoverageInstrumenter.processFile (/home/lolmaus/Code/launchpad2/node_modules/broccoli-filter/index.js:165:31)
    at asyncProcessFile (/home/lolmaus/Code/launchpad2/node_modules/broccoli-filter/index.js:122:21)
    at lib$rsvp$$internal$$tryCatch (/home/lolmaus/Code/launchpad2/node_modules/rsvp/dist/rsvp.js:493:16)
    at lib$rsvp$$internal$$invokeCallback (/home/lolmaus/Code/launchpad2/node_modules/rsvp/dist/rsvp.js:505:17)
    at /home/lolmaus/Code/launchpad2/node_modules/rsvp/dist/rsvp.js:1001:13
    at lib$rsvp$asap$$flush (/home/lolmaus/Code/launchpad2/node_modules/rsvp/dist/rsvp.js:1198:9)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)

The broccoli plugin was instantiated at: 
    at CoverageInstrumenter.Plugin (/home/lolmaus/Code/launchpad2/node_modules/broccoli-plugin/index.js:7:31)
    at CoverageInstrumenter.Filter [as constructor] (/home/lolmaus/Code/launchpad2/node_modules/broccoli-filter/index.js:34:10)
    at new CoverageInstrumenter (/home/lolmaus/Code/launchpad2/node_modules/ember-cli-code-coverage/lib/coverage-instrumenter.js:72:10)
    at CoreObject.module.exports.preprocessTree (/home/lolmaus/Code/launchpad2/node_modules/ember-cli-code-coverage/index.js:52:28)
    at /home/lolmaus/Code/launchpad2/node_modules/ember-cli/lib/broccoli/ember-app.js:584:41
    at Array.reduce (native)
    at EmberApp.addonPreprocessTree (/home/lolmaus/Code/launchpad2/node_modules/ember-cli/lib/broccoli/ember-app.js:583:30)
    at EmberApp.appAndDependencies (/home/lolmaus/Code/launchpad2/node_modules/ember-cli/lib/broccoli/ember-app.js:1062:18)
    at EmberApp.javascript (/home/lolmaus/Code/launchpad2/node_modules/ember-cli/lib/broccoli/ember-app.js:1199:34)
    at EmberApp.toArray (/home/lolmaus/Code/launchpad2/node_modules/ember-cli/lib/broccoli/ember-app.js:1604:10)
    at EmberApp.toTree (/home/lolmaus/Code/launchpad2/node_modules/ember-cli/lib/broccoli/ember-app.js:1626:30)
    at module.exports (/home/lolmaus/Code/launchpad2/ember-cli-build.js:35:14)
    at CoreObject.module.exports.Task.extend.setupBroccoliBuilder (/home/lolmaus/Code/launchpad2/node_modules/ember-cli/lib/models/builder.js:74:19)
    at CoreObject.module.exports.Task.extend.init (/home/lolmaus/Code/launchpad2/node_modules/ember-cli/lib/models/builder.js:54:10)
    at CoreObject.superWrapper [as init] (/home/lolmaus/Code/launchpad2/node_modules/ember-cli/node_modules/core-object/lib/assign-properties.js:32:18)
    at CoreObject.Class (/home/lolmaus/Code/launchpad2/node_modules/ember-cli/node_modules/core-object/core-object.js:32:33)
    at CoreObject.module.exports.Task.extend.run (/home/lolmaus/Code/launchpad2/node_modules/ember-cli/lib/tasks/build.js:15:19)
    at CoreObject.<anonymous> (/home/lolmaus/Code/launchpad2/node_modules/ember-cli/lib/commands/test.js:164:27)
    at lib$rsvp$$internal$$tryCatch (/home/lolmaus/Code/launchpad2/node_modules/rsvp/dist/rsvp.js:493:16)
    at lib$rsvp$$internal$$invokeCallback (/home/lolmaus/Code/launchpad2/node_modules/rsvp/dist/rsvp.js:505:17)
    at /home/lolmaus/Code/launchpad2/node_modules/rsvp/dist/rsvp.js:1001:13
    at lib$rsvp$asap$$flush (/home/lolmaus/Code/launchpad2/node_modules/rsvp/dist/rsvp.js:1198:9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.