This repository was archived by the owner on Sep 21, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed
Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff 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 = / ^ d a t a : a p p l i c a t i o n \ /j s o n ; (?: c h a r s e t = u t f - 8 ; ) ? b a s e 6 4 , / ;
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 }
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments