Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Commit 1794e13

Browse files
committed
fix(coverage): support webpack sourcemaps format
1 parent 42d900b commit 1794e13

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

lib/coverage.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ const Coverage = module.exports = inherit({
133133
return;
134134
}
135135

136-
var base64Prefix = 'data:application/json;base64,';
137-
if (_.includes(sourceMapUrl, base64Prefix)) {
138-
var base64Str = sourceMapUrl.split(base64Prefix)[1],
136+
var base64Prefix = /^data:application\/json;(?:charset=utf-8;)?base64,/;
137+
if (base64Prefix.test(sourceMapUrl)) {
138+
var base64Str = sourceMapUrl.replace(base64Prefix, ''),
139139
sourceMapStr = new Buffer(base64Str, 'base64').toString('utf8');
140140
return new SourceMapConsumer(JSON.parse(sourceMapStr));
141141
}

test/unit/coverage.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,42 @@ describe('coverage', () => {
4949
assert.deepEqual(coverage.byURL['http://some/url'].coverage, {'.some-selector': 'full'});
5050
});
5151
});
52+
53+
describe('getSourceMap', () => {
54+
it('parse source map', () => {
55+
const config = createConfig();
56+
const coverage = new Coverage(config);
57+
58+
const ast = {
59+
stylesheet: {
60+
rules: [{
61+
type: 'comment',
62+
comment: '# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJzdHlsZXMuY3NzIiwic291cmNlUm9vdCI6IiJ9'
63+
}]
64+
}
65+
};
66+
67+
const map = coverage.getSourceMap(ast, '', '');
68+
69+
assert.equal(map.file, 'styles.css');
70+
});
71+
72+
it('parse webpack source map', () => {
73+
const config = createConfig();
74+
const coverage = new Coverage(config);
75+
76+
const ast = {
77+
stylesheet: {
78+
rules: [{
79+
type: 'comment',
80+
comment: '# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJzdHlsZXMuY3NzIiwic291cmNlUm9vdCI6IiJ9'
81+
}]
82+
}
83+
};
84+
85+
const map = coverage.getSourceMap(ast, '', '');
86+
87+
assert.equal(map.file, 'styles.css');
88+
});
89+
});
5290
});

0 commit comments

Comments
 (0)