I'm tired of trying to get the node libraries to work together correctly ... but this is part of the work, so here it goes ...
I have an ES6 application designed for a browser. I have a set of unit tests for my files that I use when my application was written in ES5. I use a browser to handle import / export of modules and combine my distribution. This works great when running the application in a browser. I can successfully browse the source and specification files and run the tests and the tests pass. I am very, very close to making this work.
The only problem is coverage. The closest I came shows the coverage of files created by karma that seem like this:
require('/absolute/path/to/the/corresponding/file.js');
and the coverage is obviously displayed as 100% for all files, because each of them is only one line.
This is my karma.conf.js:
import babelify from 'babelify'; import isparta from 'isparta'; import paths from './paths'; var normalizeBrowserName = (browser) => browser.toLowerCase().split(/[ /-]/)[0]; export default function(config) { config.set({ basePath: '..', browsers: ['PhantomJS'], frameworks: ['browserify', 'jasmine'], files: paths.test.files, preprocessors: { 'app/**/*.js': ['browserify', 'sourcemap', 'coverage'], [paths.test.testFiles]: ['babel'], }, plugins: [ 'karma-babel-preprocessor', 'karma-browserify', 'karma-coverage', 'karma-jasmine', 'karma-junit-reporter', 'karma-phantomjs-launcher', 'karma-sourcemap-loader', ], autoWatch: false, colors: false, loggers: [{ type: 'console' }], port: 9876, reporters: ['progress', 'dots', 'junit', 'coverage'], junitReporter: { outputFile: paths.test.resultsOut, suite: '', }, browserify: { debug: true, noParse: paths.js.noparse(), configure: (bundle) => { bundle.once('prebundle', () => bundle.transform(babelify.configure({ ignore: 'lib/!**!/!*' }))); }, }, coverageReporter: { instrumenters: { isparta }, instrumenter: { [paths.test.cover]: 'isparta', }, reporters: [ { type: 'text', }, { type: 'html', dir: paths.test.coverageOut, subdir: normalizeBrowserName }, { type: 'cobertura', dir: paths.test.coverageOut, subdir: '.', file: 'coverage.xml' }, ], }, logLevel: config.LOG_DEBUG, }); };
I really don't know how any of these libraries work, so I don't know where to start this debugging. I understand that arranging preprocessors matters, so the browser looks at the source files, transfers the resulting link files to the source map generator, and then the source map generator feeds any resulting coverage into karma. But there is some loss of connection between the browser and what the coverage handles. isparta (which uses istanbul behind the scenes) does not know that the browser is working, and I do not know what it sees.
I am incoherent right now because I seriously donβt know how this material works.
If anyone has experience testing modular ES6 with proper code coverage, please let me know if I'm on the right track or should I try something else.