205

I'm using ember-cli-code-coverage with ember-cli-mocha.
When I run COVERAGE=true ember test I'm getting 0% coverage for statements, functions, and lines.
Yet, I have tests that are covering those sections. Any I missing something in my setup?

enter image description here

unit test file:

beforeEach(function() {
    controller = this.subject();
});

it('sets selectedImage to null', function() {
    expect(controller.get('selectedImage')).to.eql(null);
});

describe('setCoverageTest', function() {
    it('sets selectedImage to true', function() {
        expect(controller.get('selectedImage')).to.eql(null);
        controller.setCoverageTest();
        expect(controller.get('selectedImage')).to.be.true;
    });
});

config/coverage.js:

module.exports = {
  excludes: ['*/templates/**/*'],
  useBabelInstrumenter: true
};
Laaouatni Anas
  • 4,199
  • 2
  • 7
  • 26
wwwuser
  • 6,282
  • 8
  • 52
  • 64
  • We use ember-cli-code-coverage@0.4.1 and ember-cli-mocha@0.14.4 with a wide variety of should and chai/expect style assertions. Our `config/coverage.js` only sets 'parallel' to true. What version are you running? Do you have a public link? I wonder if the excludes is interfering. Are you using pretender or any XHR stubbing by any chance? If so, be sure to exempt Another gotcha: ensure to exempt the '/write-coverage' path. –  Sep 05 '17 at 23:24
  • Did you use `this.passthrough('/write-coverage');` in your setup? https://github.com/kategengler/ember-cli-code-coverage#create-a-passthrough-when-intercepting-all-ajax-requests-in-tests – Alex Strizhak Aug 29 '21 at 13:44
  • We are also using the following properties in our coverage.js: {parallel:false, coverageFolder : ‘pathtofolder’, reporters: [‘lcov’, ‘html’, ‘cobertura’]}. It has been a while since I set this up but try adding these. – Omeri Sep 15 '21 at 18:59
  • Are you using `ember-cli-content-security-policy >= 1.1.1`? – gmanjon Nov 10 '21 at 17:32

1 Answers1

2

Few well integrated tools to establish accurate code coverage for ember-cli apps exist. (something like Istanbul for everything in app/) We ended up avoiding ember-cli-blanket and writing a rudimentary istanbul 78 integration with testem. Basically, it calls the istanbul cli against the single JS file output by ember build. Imprecise but consistent. We've used in on iDealeCasinos multiple times and it worked like a charm. Might be wise to give it a shot!