Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ const Coverage = module.exports = inherit({
return;
}

var base64Prefix = 'data:application/json;base64,';
if (_.includes(sourceMapUrl, base64Prefix)) {
var base64Str = sourceMapUrl.split(base64Prefix)[1],
var base64Prefix = /^data:application\/json;(?:charset=utf-8;)?base64,/;
if (base64Prefix.test(sourceMapUrl)) {
var base64Str = sourceMapUrl.replace(base64Prefix, ''),
sourceMapStr = new Buffer(base64Str, 'base64').toString('utf8');
return new SourceMapConsumer(JSON.parse(sourceMapStr));
}
Expand Down
38 changes: 38 additions & 0 deletions test/unit/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,42 @@ describe('coverage', () => {
assert.deepEqual(coverage.byURL['http://some/url'].coverage, {'.some-selector': 'full'});
});
});

describe('getSourceMap', () => {
it('parse source map', () => {
const config = createConfig();
const coverage = new Coverage(config);

const ast = {
stylesheet: {
rules: [{
type: 'comment',
comment: '# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJzdHlsZXMuY3NzIiwic291cmNlUm9vdCI6IiJ9'
}]
}
};

const map = coverage.getSourceMap(ast, '', '');

assert.equal(map.file, 'styles.css');
});

it('parse webpack source map', () => {
const config = createConfig();
const coverage = new Coverage(config);

const ast = {
stylesheet: {
rules: [{
type: 'comment',
comment: '# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsImZpbGUiOiJzdHlsZXMuY3NzIiwic291cmNlUm9vdCI6IiJ9'
}]
}
};

const map = coverage.getSourceMap(ast, '', '');

assert.equal(map.file, 'styles.css');
});
});
});