Not getting code coverage information

399 Views Asked by At

I'm running a Unit test experiment on our existing Webapp folder structure. When I run the tests on an AMD and non-AMD js file, the unit tests run but I don't get code coverage for each test. I'm assuming it's because the directory structure (see below); moved 'node_modules' and 'intern_tests' one level down ('internjs'). It all works (run + coverage) if I move 'node_modules' and 'intern_tests' folder under the Webapp folder. I'm running version 2.1.1. Does code coverage work with this type of directory structure?

Folder structure:

WebApp (top)
   |- example_apps (example AMD and non-AMD apps)

   |- internjs ( run tests from here )
        |- node_modules

        |- intern_tests
               |- unit (test js apps under example_apps)

Non-AMD unit test:

define([
    'intern!object',
    'intern/chai!assert',
    // made a package under intern.js
    'intern/order!exampleApps/calc.js'
], function (registerSuite, assert) {
    registerSuite({ ....

AMD unit test:

define([
    'intern!object',
    'intern/chai!assert',
    'intern/chai!config',
    'exampleApps/hello'
], function (registerSuite, assert, config, hello) {
    registerSuite({ ...

intern_unit.js:

loader: {
    // Packages that should be registered with the loader in each testing environment
    packages: [ { name: 'exampleApps', location: '../example_apps' } ]
},

// Non-functional test suite(s) to run in each browser
suites: [
    'intern_tests/unit/unit_hello',
    'intern_tests/unit/unit_calc2'

],

Output:

./node_modules/.bin/intern-client config=intern_tests/intern_unit
PASS: main - hello - greet (1ms)
0/1 tests failed
PASS: main - test_calc - sum (0ms)
0/1 tests failed
0/2 tests failed

Note, it runs but no code coverage on the two js files under 'example_apps' directory one level up.

1

There are 1 best solutions below

0
On

I figured it out. I had to run the scripts from WebApp (top). Below is the new configuration.

Command line:

user:~/WebApp$ ./intenjs/node_modules/.bin/intern-client config=internjs/intern_tests/intern_unit

intern_unit.js

loader: {
    // Packages that should be registered with the loader in each testing environment
    packages: [ { name: 'exampleApps', location: 'example_apps' },
                { name: 'internTests', location: 'internjs/intern_tests' } ]
},

// Non-functional test suite(s) to run in each browser
suites: [
    // AMD
    'internTests/unit/unit_hello',
    // non-AMD
    'internjs/intern_tests/unit/unit_calc2'

],

// A regular expression matching URLs to files that should not be included in code coverage analysis
excludeInstrumentation: /^(?:internjs)\//

Non-AMD test script:

define([
    'intern!object',
    'intern/chai!assert',
    // non-AMD, saw this in tutorial
    'intern/order!../../../example_apps/calc.js'
    // this also works
//    '../../../example_apps/calc.js'
], function (registerSuite, assert) {

AMD test script:

define([
    'intern!object',
    'intern/chai!assert',
    'intern/chai!config',
    'exampleApps/hello'
], function (registerSuite, assert, config, hello) {