react / wstein / node_modules / browserify / node_modules / browser-pack / test / source-maps-existing.js
80529 viewsvar test = require('tap').test;1var pack = require('../');2var convert = require('convert-source-map');3var parse = require('parse-base64vlq-mappings');45var foo = {6version: 3,7file: 'foo.js',8sourceRoot: '',9sources: [ 'foo.coffee' ],10names: [],11mappings: ';AAAA;CAAA;CAAA,CAAA,CAAA,IAAO,GAAK;CAAZ',12sourcesContent: [ 'console.log(require \'./bar.js\')\n' ] };1314test('pack one file with source file field and existing sourcemap', function (t) {15t.plan(7);1617var mapComment = convert.fromObject(foo).toComment();18var fooMappings = parse(foo.mappings);1920var p = pack();21var src = '';22p.on('data', function (buf) { src += buf });23p.on('end', function () {2425var sm = convert.fromSource(src).toObject();26var mappings = parse(sm.mappings);2728var remainingMaps = src.match(convert.commentRegex);2930// remove map for _prelude.js31mappings.shift();3233var fstMap = mappings[0];34var fstFooMap = fooMappings[0];35var lstMap = mappings.pop();36var lstFooMap = fooMappings.pop();3738t.deepEqual(fstMap.original, fstFooMap.original, 'first original mappings are same');39t.deepEqual(lstMap.original, lstFooMap.original, 'last original mappings are same');4041t.equal(fstMap.generated.column, fstFooMap.generated.column, 'first generated columns are same');42t.equal(lstMap.generated.column, lstFooMap.generated.column, 'last generated columns are same');4344t.equal(fstMap.generated.line, fstFooMap.generated.line + 1, 'first generated line is offset by 1');45t.equal(lstMap.generated.line, lstFooMap.generated.line + 1, 'last generated line is offset by 1');4647t.equal(remainingMaps.length, 1, 'removes orinal source maps');48});4950p.end(JSON.stringify([51{52id: 'xyz',53source: '(function() {\n\n console.log(require(\'./bar.js\'));\n\n}).call(this);\n' + '\n' + mapComment,54sourceFile: 'foo.js'55}56]));57});58596061