11const { directoryArgs} = require ( 'npm_bazel_terser/index' )
2+ const fs = require ( 'fs' ) ;
3+ const path = require ( 'path' ) ;
4+ const tmp = require ( 'tmp' ) ;
25
36describe ( 'directoryArgs' , ( ) => {
47 it ( 'return a new array ref' , ( ) => {
5- const args = [ '--source-map' , '' ] ;
8+ const args = [ '--source-map' , '' , '' ] ;
69 expect ( directoryArgs ( args , '' ) ) . not . toBe ( args ) ;
710 } ) ;
811
@@ -11,18 +14,32 @@ describe('directoryArgs', () => {
1114 expect ( directoryArgs ( args ) ) . toBe ( args ) ;
1215 } ) ;
1316
14- it ( 'should replace the directory url with the file url' , ( ) => {
17+ it ( 'should set the correct file url and souremap content' , ( ) => {
18+ const out = tmp . dirSync ( ) . name ;
19+ const input = path . join ( out , 'file.js' ) ;
20+ const output = '/test/file.js' ;
1521 const args = [
1622 '--ie8' ,
1723 '--source-map' ,
18- `root='http://foo.com/src',url='some_wrong_name'` ,
24+ `root='http://foo.com/src',url='some_wrong_name',content=inline ` ,
1925 '--keep-fnames' ,
2026 ] ;
21- const output = '/test/file.js' ;
22- expect ( directoryArgs ( args , output ) ) . toEqual ( [
27+ // if no corresponding map file exists then sourcemap content should
28+ // be left as inline
29+ expect ( directoryArgs ( args , input , output ) ) . toEqual ( [
30+ '--ie8' ,
31+ '--source-map' ,
32+ `root='http://foo.com/src',url='${ path . basename ( output ) } .map',content=inline` ,
33+ '--keep-fnames' ,
34+ ] ) ;
35+ // if a corresponding map file exists then sourcemap content should be set
36+ // to the map file
37+ fs . writeFileSync ( `${ input } .map` , '' ) ;
38+ expect ( directoryArgs ( args , input , output ) ) . toEqual ( [
2339 '--ie8' ,
2440 '--source-map' ,
25- `root='http://foo.com/src',url='file.js.map'` ,
41+ `root='http://foo.com/src',url='${ path . basename ( output ) } .map',content='${
42+ input . replace ( / \\ / g, '/' ) } .map'`,
2643 '--keep-fnames' ,
2744 ] ) ;
2845 } ) ;
0 commit comments