Sha256: 43f3e50c3b650011164bb92dedb516e1b16e0f189584464ed5fd407239874316

Contents?: true

Size: 1.99 KB

Versions: 7

Compression:

Stored size: 1.99 KB

Contents

var test = require('tap').test;
var pack = require('../');
var convert = require('convert-source-map');
var parse = require('parse-base64vlq-mappings');

var foo = { 
    version: 3,
    file: 'foo.js',
    sourceRoot: '',
    sources: [ 'foo.coffee' ],
    names: [],
    mappings: ';AAAA;CAAA;CAAA,CAAA,CAAA,IAAO,GAAK;CAAZ',
    sourcesContent: [ 'console.log(require \'./bar.js\')\n' ] };

test('pack one file with source file field and existing sourcemap', function (t) {
    t.plan(7);
    
    var mapComment = convert.fromObject(foo).toComment();
    var fooMappings = parse(foo.mappings);

    var p = pack();
    var src = '';
    p.on('data', function (buf) { src += buf });
    p.on('end', function () {

        var sm = convert.fromSource(src).toObject();
        var mappings = parse(sm.mappings);

        var remainingMaps = src.match(convert.commentRegex);

        // remove map for _prelude.js
        mappings.shift();

        var fstMap = mappings[0];
        var fstFooMap = fooMappings[0];
        var lstMap = mappings.pop();
        var lstFooMap = fooMappings.pop();

        t.deepEqual(fstMap.original, fstFooMap.original, 'first original mappings are same');
        t.deepEqual(lstMap.original, lstFooMap.original, 'last original mappings are same');

        t.equal(fstMap.generated.column, fstFooMap.generated.column, 'first generated columns are same');
        t.equal(lstMap.generated.column, lstFooMap.generated.column, 'last generated columns are same');

        t.equal(fstMap.generated.line, fstFooMap.generated.line + 1, 'first generated line is offset by 1');
        t.equal(lstMap.generated.line, lstFooMap.generated.line + 1, 'last generated line is offset by 1');

        t.equal(remainingMaps.length, 1, 'removes orinal source maps');
    });
    
    p.end(JSON.stringify([
        {
            id: 'xyz',
            source: '(function() {\n\n  console.log(require(\'./bar.js\'));\n\n}).call(this);\n' + '\n' + mapComment,
            sourceFile: 'foo.js'
        }
    ]));
});

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
minimum_viable_product-0.0.11 test/dummy/node_modules/browser-pack/test/source-maps-existing.js
brwy_rails-0.0.6 test/dummy/node_modules/browser-pack/test/source-maps-existing.js
brwy_rails-0.0.5 test/dummy/node_modules/browser-pack/test/source-maps-existing.js
brwy_rails-0.0.4 test/dummy/node_modules/browser-pack/test/source-maps-existing.js
brwy_rails-0.0.3 test/dummy/node_modules/browser-pack/test/source-maps-existing.js
brwy_rails-0.0.2 test/dummy/node_modules/browser-pack/test/source-maps-existing.js
brwy_rails-0.0.1 test/dummy/node_modules/browser-pack/test/source-maps-existing.js