@@ -2,13 +2,14 @@ const assert = require('assert');
22const fs = require ( 'fs' ) ;
33const path = require ( 'path' ) ;
44const mapValidator = require ( 'sourcemap-validator' ) ;
5- const { bundle, run, assertBundleTree} = require ( './utils' ) ;
5+ const { bundler , bundle, run, assertBundleTree} = require ( './utils' ) ;
66
77describe ( 'sourcemaps' , function ( ) {
88 it ( 'should create a valid sourcemap as a child of a JS bundle' , async function ( ) {
9- let b = await bundle ( __dirname + '/integration/sourcemap/index.js' ) ;
9+ let b = bundler ( __dirname + '/integration/sourcemap/index.js' ) ;
10+ let bu = await b . bundle ( ) ;
1011
11- assertBundleTree ( b , {
12+ assertBundleTree ( bu , {
1213 name : 'index.js' ,
1314 assets : [ 'index.js' ] ,
1415 childBundles : [
@@ -26,8 +27,24 @@ describe('sourcemaps', function() {
2627 . readFileSync ( path . join ( __dirname , '/dist/index.map' ) )
2728 . toString ( ) ;
2829 mapValidator ( raw , map ) ;
30+ let mapObject = JSON . parse ( map ) ;
31+ assert (
32+ mapObject . sourceRoot ===
33+ path . relative ( b . options . outDir , b . options . rootDir ) ,
34+ 'sourceRoot should be the root of the source files, relative to the output directory.'
35+ ) ;
36+ assert (
37+ fs . existsSync (
38+ path . resolve (
39+ b . options . outDir ,
40+ mapObject . sourceRoot ,
41+ mapObject . sources [ 0 ]
42+ )
43+ ) ,
44+ 'combining sourceRoot and sources object should resolve to the original file'
45+ ) ;
2946
30- let output = run ( b ) ;
47+ let output = run ( bu ) ;
3148 assert . equal ( typeof output , 'function' ) ;
3249 assert . equal ( output ( ) , 'hello world' ) ;
3350 } ) ;
0 commit comments