@@ -6,19 +6,34 @@ const fs = require("fs");
66const path = require ( "path" ) ;
77
88jest . mock ( "devtools-utils/src/network-request" ) ;
9- const { getOriginalURLs } = require ( "../source-map" ) ;
9+ const { getOriginalURLs, hasMappedSource } = require ( "../source-map" ) ;
1010
1111function getMap ( _path ) {
1212 const mapPath = path . join ( __dirname , _path ) ;
1313 return fs . readFileSync ( mapPath , "utf8" ) ;
1414}
1515
16+ async function setupBundleFixture ( ) {
17+ const source = {
18+ id : "bundle.js" ,
19+ sourceMapURL : "bundle.js.map" ,
20+ url : "http:://example.com/bundle.js"
21+ } ;
22+
23+ require ( "devtools-utils/src/network-request" ) . mockImplementationOnce ( ( ) => {
24+ const content = getMap ( "fixtures/bundle.js.map" ) ;
25+ return { content } ;
26+ } ) ;
27+
28+ await getOriginalURLs ( source ) ;
29+ }
30+
1631describe ( "source maps" , ( ) => {
1732 test ( "getOriginalURLs" , async ( ) => {
1833 const source = {
1934 id : "bundle.js" ,
2035 sourceMapURL : "bundle.js.map" ,
21- url : "http:://example.com/bundle.js" ,
36+ url : "http:://example.com/bundle.js"
2237 } ;
2338
2439 require ( "devtools-utils/src/network-request" ) . mockImplementationOnce ( ( ) => {
@@ -88,4 +103,25 @@ describe("source maps", () => {
88103 "http://example.com/whatever/heart.js"
89104 ] ) ;
90105 } ) ;
106+
107+ describe ( "hasMappedSource" , async ( ) => {
108+ test ( "has original location" , async ( ) => {
109+ await setupBundleFixture ( )
110+ const location = {
111+ sourceId : "bundle.js" ,
112+ line : 49
113+ } ;
114+ const isMappaed = await hasMappedSource ( location ) ;
115+ expect ( isMappaed ) . toBe ( true ) ;
116+ } )
117+
118+ test ( "does not have original location" , async ( ) => {
119+ const location = {
120+ sourceId : "bundle.js" ,
121+ line : 94
122+ } ;
123+ const isMappaed = await hasMappedSource ( location ) ;
124+ expect ( isMappaed ) . toBe ( false ) ;
125+ } )
126+ } ) ;
91127} ) ;
0 commit comments