@@ -21,24 +21,30 @@ var path = require('path');
2121
2222var SourceMapper = require ( '../build/src/agent/sourcemapper.js' ) ;
2323
24+ var BASE_PATH = path . join ( __dirname , 'fixtures' , 'sourcemapper' ) ;
25+
2426/**
25- * @param {string } tool The name of the tool that was used to generate the
27+ * @param {string } tool The name of the tool that was used to generate the
2628 * given sourcemap data
27- * @param {string } mapFilePath The path to the sourcemap file of a
29+ * @param {string } relativeMapFilePath The path to the sourcemap file of a
2830 * transpilation to test
29- * @param {string } inputFilePath The path to the input file that was
31+ * @param {string } relativeInputFilePath The path to the input file that was
3032 * transpiled to generate the specified sourcemap file
31- * @param {string } outputFilePath The path to the output file that was
32- * generated during the transpilation process that constructed the
33+ * @param {string } relativeOutputFilePath The path to the output file that was
34+ * generated during the transpilation process that constructed the
3335 * specified sourcemap file
3436 * @param {Array.<Array.<number, number>> } inToOutLineNums An array of arrays
3537 * where each element in the array is a pair of numbers. The first number
3638 * in the pair is the line number from the input file and the second number
3739 * in the pair is the expected line number in the corresponding output file
38- *
40+ *
3941 * Note: The line numbers are zero-based
4042 */
41- function testTool ( tool , mapFilePath , inputFilePath , outputFilePath , inToOutLineNums ) {
43+ function testTool ( tool , relativeMapFilePath , relativeInputFilePath , relativeOutputFilePath , inToOutLineNums ) {
44+ var mapFilePath = path . join ( BASE_PATH , relativeMapFilePath ) ;
45+ var inputFilePath = path . join ( BASE_PATH , relativeInputFilePath ) ;
46+ var outputFilePath = path . join ( BASE_PATH , relativeOutputFilePath ) ;
47+
4248 describe ( 'sourcemapper for tool ' + tool , function ( ) {
4349 var sourcemapper ;
4450
@@ -62,11 +68,21 @@ function testTool(tool, mapFilePath, inputFilePath, outputFilePath, inToOutLineN
6268 done ( ) ;
6369 } ) ;
6470
65- it ( 'for tool ' + tool +
71+ it ( 'for tool ' + tool +
72+ ' it states that it has mapping info for files with a path' +
73+ ' similar to a path it knows about' ,
74+ function ( done ) {
75+ assert . equal ( sourcemapper . hasMappingInfo ( relativeInputFilePath ) , true ) ;
76+ var movedPath = path . join ( '/some/other/base/dir/' , relativeInputFilePath ) ;
77+ assert . equal ( sourcemapper . hasMappingInfo ( movedPath ) , true ) ;
78+ done ( ) ;
79+ } ) ;
80+
81+ it ( 'for tool ' + tool +
6682 ' it states that it does not have mapping info for a file it ' +
6783 'doesn\'t recognize' ,
6884 function ( done ) {
69- assert . equal ( sourcemapper . hasMappingInfo ( 'INVALID_' + inputFilePath ) , false ) ;
85+ assert . equal ( sourcemapper . hasMappingInfo ( inputFilePath + '_INVALID' ) , false ) ;
7086 done ( ) ;
7187 } ) ;
7288
@@ -90,11 +106,10 @@ function testTool(tool, mapFilePath, inputFilePath, outputFilePath, inToOutLineN
90106 } ) ;
91107}
92108
93- var basePath = path . join ( __dirname , 'fixtures' , 'sourcemapper' ) ;
94- testTool ( 'Babel' ,
95- path . join ( basePath , 'babel' , 'out.js.map' ) ,
96- path . join ( basePath , 'babel' , 'in.js' ) ,
97- path . join ( basePath , 'babel' , 'out.js' ) , [
109+ testTool ( 'Babel' ,
110+ path . join ( 'babel' , 'out.js.map' ) ,
111+ path . join ( 'babel' , 'in.js' ) ,
112+ path . join ( 'babel' , 'out.js' ) , [
98113 [ 1 , 14 ] ,
99114 [ 2 , 15 ] ,
100115 [ 3 , 16 ] ,
@@ -148,9 +163,9 @@ testTool('Babel',
148163] ) ;
149164
150165testTool ( 'Typescript' ,
151- path . join ( basePath , 'typescript' , 'out.js.map' ) ,
152- path . join ( basePath , 'typescript' , 'in.ts' ) ,
153- path . join ( basePath , 'typescript' , 'out.js' ) , [
166+ path . join ( 'typescript' , 'out.js.map' ) ,
167+ path . join ( 'typescript' , 'in.ts' ) ,
168+ path . join ( 'typescript' , 'out.js' ) , [
154169 [ 1 , 5 ] ,
155170 [ 2 , 6 ] ,
156171 [ 3 , 9 ] ,
@@ -167,9 +182,9 @@ testTool('Typescript',
167182] ) ;
168183
169184testTool ( 'Coffeescript' ,
170- path . join ( basePath , 'coffeescript' , 'in.js.map' ) ,
171- path . join ( basePath , 'coffeescript' , 'in.coffee' ) ,
172- path . join ( basePath , 'coffeescript' , 'in.js' ) , [
185+ path . join ( 'coffeescript' , 'in.js.map' ) ,
186+ path . join ( 'coffeescript' , 'in.coffee' ) ,
187+ path . join ( 'coffeescript' , 'in.js' ) , [
173188 [ 1 , 1 ] ,
174189 [ 2 , 7 ] ,
175190 [ 3 , 8 ] ,
0 commit comments