@@ -25,24 +25,6 @@ import {MockLogger} from './mock-logger';
2525const BASE_PATH = path . join ( __dirname , 'fixtures' , 'sourcemapper' ) ;
2626const QUICK_MILLISECONDS = 300 ;
2727
28- /**
29- * @param {string } tool The name of the tool that was used to generate the
30- * given sourcemap data
31- * @param {string } relativeMapFilePath The path to the sourcemap file of a
32- * transpilation to test
33- * @param {string } relativeInputFilePath The path to the input file that was
34- * transpiled to generate the specified sourcemap file
35- * @param {string } relativeOutputFilePath The path to the output file that was
36- * generated during the transpilation process that constructed the
37- * specified sourcemap file
38- * @param {Array.<Array.<number, number>> } inToOutLineNums An array of arrays
39- * where each element in the array is a pair of numbers. The first number
40- * in the pair is the line number from the input file and the second number
41- * in the pair is the expected line number in the corresponding output file
42- *
43- * Note: The line numbers are zero-based
44- */
45-
4628describe ( 'sourcemapper debug info' , ( ) => {
4729 const logger = new MockLogger ( ) ;
4830 const mapFilePath = path . join (
@@ -84,45 +66,56 @@ describe('sourcemapper debug info', () => {
8466
8567 const mapInfoInput = sourcemapper . getMapInfoInput ( inputFilePath ) ;
8668 assert . notEqual ( mapInfoInput , null ) ;
87- sourcemapper . getMapInfoOutput ( inputFilePath , 1 , 0 , mapInfoInput ! ) ;
69+ sourcemapper . getMapInfoOutput ( 1 , 0 , mapInfoInput ! ) ;
8870
8971 // Verify if the debugging information is correctly printed.
9072 // We use 'indexOf' here instead of 'match' to avoid parsing regular
9173 // expression, which will confuse the result when having '\' in the path
9274 // name on platform like Windows.
75+ const expectedDebugMessages = [
76+ `sourcemapper entry.inputFile: ${ inputFilePath } ` ,
77+ 'sourcePos: {"source":"in.ts","line":2,"column":0}' ,
78+ 'mappedPos: {"line":6,"column":0,"lastColumn":null}' ,
79+ ] . reverse ( ) ;
9380 const debugsLength = logger . debugs . length ;
94- assert . notStrictEqual (
95- logger . debugs [ debugsLength - 3 ] . args [ 0 ] . indexOf (
96- `sourcemapper inputPath: ${ inputFilePath } `
97- ) ,
98- - 1
99- ) ;
100- assert . notStrictEqual (
101- logger . debugs [ debugsLength - 2 ] . args [ 0 ] . indexOf (
102- 'sourcePos: {"source":"in.ts","line":2,"column":0}'
103- ) ,
104- - 1
105- ) ;
106- assert . notStrictEqual (
107- logger . debugs [ debugsLength - 1 ] . args [ 0 ] . indexOf (
108- 'mappedPos: {"line":6,"column":0,"lastColumn":null}'
109- ) ,
110- - 1
111- ) ;
81+ for ( let i = 0 ; i < expectedDebugMessages . length ; i ++ ) {
82+ assert . notStrictEqual (
83+ logger . debugs [ debugsLength - i - 1 ] . args [ 0 ] . indexOf (
84+ expectedDebugMessages [ i ]
85+ ) ,
86+ - 1 ,
87+ `'${ logger . debugs [ debugsLength - i - 1 ] . args [ 0 ] } ' does not match '${
88+ expectedDebugMessages [ i ]
89+ } '`
90+ ) ;
91+ }
11292 } ) ;
11393} ) ;
11494
95+ /**
96+ * @param {string } tool The name of the tool that was used to generate the
97+ * given sourcemap data
98+ * @param {string } mapFilePath The path to the sourcemap file of a
99+ * transpilation to test
100+ * @param {string } inputFilePath The path to the input file that was
101+ * transpiled to generate the specified sourcemap file
102+ * @param {string } outputFilePath The path to the output file that was
103+ * generated during the transpilation process that constructed the
104+ * specified sourcemap file
105+ * @param {Array.<Array.<number, number>> } inToOutLineNums An array of arrays
106+ * where each element in the array is a pair of numbers. The first number
107+ * in the pair is the line number from the input file and the second number
108+ * in the pair is the expected line number in the corresponding output file
109+ *
110+ * Note: The line numbers are zero-based
111+ */
115112function testTool (
116113 tool : string ,
117- relativeMapFilePath : string ,
118- relativeInputFilePath : string ,
119- relativeOutputFilePath : string ,
114+ mapFilePath : string ,
115+ inputFilePath : string ,
116+ outputFilePath : string ,
120117 inToOutLineNums : number [ ] [ ]
121118) {
122- const mapFilePath = path . join ( BASE_PATH , relativeMapFilePath ) ;
123- const inputFilePath = path . join ( BASE_PATH , relativeInputFilePath ) ;
124- const outputFilePath = path . join ( BASE_PATH , relativeOutputFilePath ) ;
125-
126119 describe ( 'sourcemapper for tool ' + tool , ( ) => {
127120 const logger = new MockLogger ( ) ;
128121 let sourcemapper : sm . SourceMapper ;
@@ -160,10 +153,7 @@ function testTool(
160153 sourcemapper . getMapInfoInput ( inputFilePath ) ,
161154 null
162155 ) ;
163- const movedPath = path . join (
164- '/some/other/base/dir/' ,
165- relativeInputFilePath
166- ) ;
156+ const movedPath = path . join ( '/some/other/base/dir/' , inputFilePath ) ;
167157 assert . notStrictEqual (
168158 sourcemapper . getMapInfoInput ( inputFilePath ) ,
169159 null ,
@@ -189,20 +179,34 @@ function testTool(
189179 }
190180 ) ;
191181
182+ it (
183+ 'for tool ' +
184+ tool +
185+ ' it can get mapping info output when input file does not exist in the source map' ,
186+ done => {
187+ const mapInfoInput = sourcemapper . getMapInfoInput ( inputFilePath ) ;
188+ assert . notEqual ( mapInfoInput , null ) ;
189+
190+ const mapInfoOutput = sourcemapper . getMapInfoOutput ( 10 , 0 , {
191+ outputFile : mapInfoInput ! . outputFile ,
192+ inputFile : 'some/file/not/in/sourcemap' ,
193+ mapFile : mapInfoInput ! . mapFile ,
194+ mapConsumer : mapInfoInput ! . mapConsumer ,
195+ sources : mapInfoInput ! . sources ,
196+ } ) ;
197+
198+ assert . notEqual ( mapInfoOutput , null ) ;
199+ assert . strictEqual ( mapInfoOutput ! . file , mapInfoInput ! . outputFile ) ;
200+ assert . strictEqual ( mapInfoOutput ! . line , - 1 ) ;
201+ done ( ) ;
202+ }
203+ ) ;
204+
192205 const testLineMapping = ( inputLine : number , expectedOutputLine : number ) => {
193206 const mapInfoInput = sourcemapper . getMapInfoInput ( inputFilePath ) ;
194207 assert . notEqual ( mapInfoInput , null ) ;
195- const info = sourcemapper . getMapInfoOutput (
196- inputFilePath ,
197- inputLine ,
198- 0 ,
199- mapInfoInput !
200- ) ;
201- assert . notStrictEqual (
202- info ,
203- null ,
204- 'The mapping info for file ' + inputFilePath + ' must be non-null'
205- ) ;
208+ const info = sourcemapper . getMapInfoOutput ( inputLine , 0 , mapInfoInput ! ) ;
209+
206210 assert . strictEqual ( info ! . file , outputFilePath ) ;
207211 assert . strictEqual (
208212 info ! . line ,
@@ -228,9 +232,9 @@ function testTool(
228232
229233testTool (
230234 'Babel' ,
231- path . join ( 'babel' , 'out.js.map' ) ,
232- path . join ( 'babel' , 'in.js' ) ,
233- path . join ( 'babel' , 'out.js' ) ,
235+ path . join ( BASE_PATH , path . join ( 'babel' , 'out.js.map' ) ) ,
236+ path . join ( BASE_PATH , path . join ( 'babel' , 'in.js' ) ) ,
237+ path . join ( BASE_PATH , path . join ( 'babel' , 'out.js' ) ) ,
234238 [
235239 [ 1 , 14 ] ,
236240 [ 2 , 15 ] ,
@@ -287,9 +291,9 @@ testTool(
287291
288292testTool (
289293 'Typescript' ,
290- path . join ( 'typescript' , 'out.js.map' ) ,
291- path . join ( 'typescript' , 'in.ts' ) ,
292- path . join ( 'typescript' , 'out.js' ) ,
294+ path . join ( BASE_PATH , path . join ( 'typescript' , 'out.js.map' ) ) ,
295+ path . join ( BASE_PATH , path . join ( 'typescript' , 'in.ts' ) ) ,
296+ path . join ( BASE_PATH , path . join ( 'typescript' , 'out.js' ) ) ,
293297 [
294298 [ 1 , 5 ] ,
295299 [ 2 , 6 ] ,
@@ -307,11 +311,21 @@ testTool(
307311 ]
308312) ;
309313
314+ // This test is for testing that by providing a partial partial match of the
315+ // source file, the breakpoint can still be set correctly.
316+ testTool (
317+ 'Typescript with sub path' ,
318+ path . join ( BASE_PATH , path . join ( 'typescript' , 'out.js.map' ) ) ,
319+ 'in.ts' ,
320+ path . join ( BASE_PATH , path . join ( 'typescript' , 'out.js' ) ) ,
321+ [ [ 1 , 5 ] ]
322+ ) ;
323+
310324testTool (
311325 'Coffeescript' ,
312- path . join ( 'coffeescript' , 'in.js.map' ) ,
313- path . join ( 'coffeescript' , 'in.coffee' ) ,
314- path . join ( 'coffeescript' , 'in.js' ) ,
326+ path . join ( BASE_PATH , path . join ( 'coffeescript' , 'in.js.map' ) ) ,
327+ path . join ( BASE_PATH , path . join ( 'coffeescript' , 'in.coffee' ) ) ,
328+ path . join ( BASE_PATH , path . join ( 'coffeescript' , 'in.js' ) ) ,
315329 [
316330 [ 1 , 1 ] ,
317331 [ 2 , 7 ] ,
@@ -333,9 +347,9 @@ testTool(
333347
334348testTool (
335349 'Webpack with Typescript' ,
336- path . join ( 'webpack-ts' , 'out.js.map' ) ,
337- path . join ( 'webpack-ts' , 'in.ts_' ) ,
338- path . join ( 'webpack-ts' , 'out.js' ) ,
350+ path . join ( BASE_PATH , path . join ( 'webpack-ts' , 'out.js.map' ) ) ,
351+ path . join ( BASE_PATH , path . join ( 'webpack-ts' , 'in.ts_' ) ) ,
352+ path . join ( BASE_PATH , path . join ( 'webpack-ts' , 'out.js' ) ) ,
339353 [
340354 [ 3 , 93 ] ,
341355 [ 4 , 94 ] ,
0 commit comments