Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
karma-sourcemap-writer
Advanced tools
Sourcemap writer for karma-webpack to work with istanbul.
Testing webpack project with karma-webpack is cool, until you want to use istanbul to do code coverage.
The codes were transpiled by webpack loaders so the coverage is not accurate.
Use karma-sourcemap-writer to write source map file into right place and let remap-istanbul remap Istanbul code coverage information to its original source positions.
npm install --save-dev karma-sourcemap-writer
tests.webpack.js
.const context = require.context('./test', true, /.spec\.js$/);
context.keys().forEach(context);
sourceMappingURL
to tests.webpack.js
.const context = require.context('./test', true, /.spec\.js$/);
context.keys().forEach(context);
//# sourceMappingURL=tests.webpack.js.map
devtool
to inline-source-map
webpack: {
// ...
devtool: 'inline-source-map'
}
karma-sourcemap-writer
and karma-coverage
const webpackConfig = require('./webpack/config.test.js');
module.exports = function set(config) {
config.set({
browsers: ['Chrome'],
singleRun: true,
frameworks: ['mocha'],
files: [
'tests.webpack.js'
],
preprocessors: {
'tests.webpack.js': [
'webpack',
'sourcemap',
'sourcemap-writer', // important!
'coverage' // important!
]
},
reporters: [
'mocha',
'coverage' // important!
],
webpack: webpackConfig,
webpackServer: {
noInfo: true
},
coverageReporter: { // important!
type: 'json',
subdir: '.',
file: 'coverage-final.json'
},
plugins: [
'karma-chrome-launcher',
'karma-webpack',
'karma-mocha',
'karma-mocha-reporter',
'karma-sourcemap-loader',
'karma-sourcemap-writer', // important!
'karma-coverage' // important!
]
});
};
coverage/coverage-final.json
and tests.webpack.js.map
beside tests.webpack.js
karma start
remap-istanbul
to generate mapped reportremap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.json -t json
At this stage this report contains lots of unrelated coverage information, we have to run a script to remove them. Thanks to @otbe for the solution.
Create a node script and execute it.
const istanbul = require('istanbul');
const collector = new istanbul.Collector();
const reporter = new istanbul.Reporter();
const remappedJson = require('./coverage/coverage-remapped.json');
const coverage = Object.keys(remappedJson).reduce((result, source) => {
// only keep js files under src/
if (source.match(/^src\/.*\.js$/)) {
result[source] = remappedJson[source];
}
return result;
}, {});
collector.add(coverage);
reporter.add('html');
reporter.write(
collector,
true,
() => console.log('open coverage/index.html to see the coverage report.')
);
Done.
FAQs
Sourcemap writer for karma-webpack to work with istanbul.
The npm package karma-sourcemap-writer receives a total of 1,557 weekly downloads. As such, karma-sourcemap-writer popularity was classified as popular.
We found that karma-sourcemap-writer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.