question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coverage for test execution

See original GitHub issue

I’m submitting a bug report

  • Library Version: 0.19

Please tell us about your environment:

  • Operating System: Windows7
  • Node Version: 6.3.1
  • NPM Version: 3.10.5
  • Browser: Chrome | PhantomJs
  • Language: TypeScript

Current behavior: Perform the command au new --here , create the new project, and try to execute the test included, it ran with out issues, but then I feel keen to know the coverage of that test, I configure karma to generate coverage:

"use strict";
const path = require('path');
const project = require('./aurelia_project/aurelia.json');
const tsconfig = require('./tsconfig.json');

let testSrc = [
  { pattern: project.unitTestRunner.source, included: false },
  'test/unit/setup.js',
  'test/aurelia-karma.js'
];

let output = project.platform.output;
let appSrc = project.build.bundles.map(x => path.join(output, x.name));
let entryIndex = appSrc.indexOf(path.join(output, project.build.loader.configTarget));
let entryBundle = appSrc.splice(entryIndex, 1)[0];
let files = [entryBundle].concat(testSrc).concat(appSrc);
console.log(files);

module.exports = function(config) {
  config.set({
    basePath: './',
    frameworks: [project.testFramework.id],
    files: files,
    exclude: [],
    preprocessors: {
      [project.unitTestRunner.source]: [project.transpiler.id],
        'src/**/*.js':['coverage']
    },
    typescriptPreprocessor: {
      typescript: require('typescript'),
      options: tsconfig.compilerOptions
    },

    reporters: ['progress','coverage'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['PhantomJS'],
    singleRun: false,

    coverageReporter: {
        reporters: [
            { type: 'json', subdir: '.', file: 'coverage-final.json', dir: 'coverage/' },
            {
                type: 'lcov', subdir: '.', dir: 'coverage/'
            }
        ]
    },

    plugins: [
                'karma-jasmine',
                'karma-coverage',
                'karma-phantomjs-launcher',
    ],   

  });
};

Neither running the test from Karma Start command nor au test, the run successfully. I got:

C:\T\Unity_Plot\Main\XXXX\XXXX.UnityPlot.Web>karma start
[ 'wwwroot\\scripts\\vendor-bundle.js',
  { pattern: 'test\\unit\\**\\*.ts', included: false },
  'test/unit/setup.js',
  'test/aurelia-karma.js',
  'wwwroot\\scripts\\app-bundle.js' ]
14 09 2016 17:44:25.965:WARN [preprocess]: Can not load "typescript", it is not registered!
  Perhaps you are missing some plugin?
14 09 2016 17:44:26.029:WARN [karma]: No captured browser, open http://localhost:9876/
14 09 2016 17:44:26.037:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
14 09 2016 17:44:26.045:INFO [launcher]: Starting browser PhantomJS
14 09 2016 17:44:27.661:INFO [PhantomJS 2.1.1 (Windows 7 0.0.0)]: Connected on socket /#Zba6VI3viR0nvlnSAAAA with id 614176
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR
  Error: Mismatched anonymous define() module: function (require, exports, aurelia_pal_browser_1) {
      "use strict";
      aurelia_pal_browser_1.initialize();
  }
  http://requirejs.org/docs/errors.html#mismatch
  at C:/T/Unity_Plot/Main/XXXX/XXXX.UnityPlot.Web/wwwroot/scripts/vendor-bundle.js:3763


Terminate batch job (Y/N)? y

C:\T\Unity_Plot\Main\XXXX\XXXX.UnityPlot.Web>au test
Starting 'unit'...
[ 'wwwroot\\scripts\\vendor-bundle.js',
  { pattern: 'test\\unit\\**\\*.ts', included: false },
  'test/unit/setup.js',
  'test/aurelia-karma.js',
  'wwwroot\\scripts\\app-bundle.js' ]
14 09 2016 17:44:57.610:WARN [preprocess]: Can not load "typescript", it is not registered!
  Perhaps you are missing some plugin?
14 09 2016 17:44:57.673:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
14 09 2016 17:44:57.681:INFO [launcher]: Starting browser PhantomJS
14 09 2016 17:44:59.357:INFO [PhantomJS 2.1.1 (Windows 7 0.0.0)]: Connected on socket /#4xXwG6IuSex1s-vqAAAA with id 75393093
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR
  Error: Mismatched anonymous define() module: function (require, exports, aurelia_pal_browser_1) {
      "use strict";
      aurelia_pal_browser_1.initialize();
  }
  http://requirejs.org/docs/errors.html#mismatch
  at C:/T/Unity_Plot/Main/XXXX/XXXX.UnityPlot.Web/wwwroot/scripts/vendor-bundle.js:3763


{ uid: 0,
  name: 'unit',
  error: 1,
  duration: [ 5, 343706445 ],
  time: 1473893102523 }
1

Expected/desired behavior:

  • What is the expected behavior?

the tests run and generates the coverage info

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Jenselmecommented, Sep 18, 2016

It looks like you are missing a plugin like this one to make it work.

Using ES6, I am able to get coverage on the generated files in dist with this karma file. It is not optimum, I’d prefer to have the coverage of the source code instead.

I also managed to get coverage on the source with karma-remap-istanbul which uses source maps to generate the report on the sources. However, I don’t have colors and I get the reports per file in the source folder which is annoying in my opinion. You can view the associated karma file here.

I tried to configure karma to use requirejs and babel to use directly the source files without success so far. You can look at my non working karma conf here.

I think it would be a huge plus to be able to configure code coverage for the source (and not the transpiled files) with the cli.

0reactions
steviescommented, Aug 14, 2017

Thanks. I was seeing that happen, and wasn’t sure I was missing something. I worked around it by using a different configuration when running coverage and when building for the final output.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test Coverage in Software Testing - Guru99
Test coverage is defined as a metric in Software Testing that measures the amount of testing performed by a set of test. It...
Read more >
Test Coverage in Software Testing (Tips to Maximize Testing ...
When only 80 of the created tests are executed and target only 6 of the requirements. We say that 4 requirements are not...
Read more >
Why test coverage is important in software testing? - Simform
Test coverage is defined as a technique which determines whether our test cases are actually covering the application code and how much code...
Read more >
Test coverage overview - SonarQube Documentation
Test coverage reports and test execution reports are important metrics in assessing the quality of your code. Test coverage reports tell you what...
Read more >
Test Coverage Techniques: The Top Ones You Need - Testim.io
Code coverage is a metric related to unit testing. The idea is to measure the percentage of lines and execution paths in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found