react / wstein / node_modules / browserify / node_modules / browser-pack / node_modules / combine-source-map / node_modules / inline-source-map / test / source-content.js
80556 views'use strict';1/*jshint asi: true*/23var test = require('tap').test4var generator = require('..');56var foo = '' + function foo () {7var hello = 'hello';8var world = 'world';9console.log('%s %s', hello, world);10}1112var bar = '' + function bar () {13console.log('yes?');14}1516function decode(base64) {17return new Buffer(base64, 'base64').toString();18}1920function inspect(obj, depth) {21console.log(require('util').inspect(obj, false, depth || 5, true));22}2324test('generated mappings', function (t) {2526t.test('one file with source content', function (t) {27var gen = generator()28.addGeneratedMappings('foo.js', foo)29.addSourceContent('foo.js', foo)3031t.deepEqual(32gen.toJSON()33, { "version": 3,34"file": "",35"sources": [36"foo.js"37],38"names": [],39"mappings": "AAAA;AACA;AACA;AACA;AACA",40"sourceRoot": "",41"sourcesContent": [42"function foo() {\n var hello = 'hello';\n var world = 'world';\n console.log('%s %s', hello, world);\n}"43],44}45, 'includes source content'46)4748t.equal(49decode(gen.base64Encode())50, '{"version":3,"sources":["foo.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA","file":"","sourceRoot":"","sourcesContent":["function foo() {\\n var hello = \'hello\';\\n var world = \'world\';\\n console.log(\'%s %s\', hello, world);\\n}"]}'51, 'encodes generated mappings including source content'52)53t.equal(54gen.inlineMappingUrl()55, '//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQUNBO0FBQ0E7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyJmdW5jdGlvbiBmb28oKSB7XG4gIHZhciBoZWxsbyA9ICdoZWxsbyc7XG4gIHZhciB3b3JsZCA9ICd3b3JsZCc7XG4gIGNvbnNvbGUubG9nKCclcyAlcycsIGhlbGxvLCB3b3JsZCk7XG59Il19'56, 'returns correct inline mapping url including source content'57)58t.end()59})6061t.test('two files with source content', function (t) {62var gen = generator()63.addGeneratedMappings('foo.js', foo)64.addSourceContent('foo.js', foo)65.addGeneratedMappings('bar.js', bar)66.addSourceContent('bar.js', bar)6768t.deepEqual(69gen.toJSON()70, { "version": 3,71"file": "",72"sources": [73"foo.js",74"bar.js"75],76"names": [],77"mappings": "ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA",78"sourceRoot": "",79"sourcesContent": [80"function foo() {\n var hello = 'hello';\n var world = 'world';\n console.log('%s %s', hello, world);\n}",81"function bar() {\n console.log('yes?');\n}"82],83}84, 'includes source content for both files'85)8687t.deepEqual(88decode(gen.base64Encode())89, '{"version":3,"sources":["foo.js","bar.js"],"names":[],"mappings":"ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA","file":"","sourceRoot":"","sourcesContent":["function foo() {\\n var hello = \'hello\';\\n var world = \'world\';\\n console.log(\'%s %s\', hello, world);\\n}","function bar() {\\n console.log(\'yes?\');\\n}"]}'90, 'encodes generated mappings including source content'91)92t.equal(93gen.inlineMappingUrl()94, '//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyIsImJhci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUNBQSxBREFBO0FDQ0EsQURBQTtBQ0NBLEFEQUE7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6WyJmdW5jdGlvbiBmb28oKSB7XG4gIHZhciBoZWxsbyA9ICdoZWxsbyc7XG4gIHZhciB3b3JsZCA9ICd3b3JsZCc7XG4gIGNvbnNvbGUubG9nKCclcyAlcycsIGhlbGxvLCB3b3JsZCk7XG59IiwiZnVuY3Rpb24gYmFyKCkge1xuICBjb25zb2xlLmxvZygneWVzPycpO1xufSJdfQ=='95, 'returns correct inline mapping url including source content'96)97t.end()98})99100t.test('two files, only one with source content', function (t) {101var gen = generator()102.addGeneratedMappings('foo.js', foo)103.addGeneratedMappings('bar.js', bar)104.addSourceContent('bar.js', bar)105106t.deepEqual(107gen.toJSON()108, { "version": 3,109"file": "",110"sources": [111"foo.js",112"bar.js"113],114"names": [],115"mappings": "ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA",116"sourcesContent": [ null, "function bar() {\n console.log('yes?');\n}" ],117"sourceRoot": ""118}119, 'includes source content for the file with source content and [null] for the other file'120)121122t.deepEqual(123decode(gen.base64Encode())124, '{"version":3,"sources":["foo.js","bar.js"],"names":[],"mappings":"ACAA,ADAA;ACCA,ADAA;ACCA,ADAA;AACA;AACA","file":"","sourceRoot":"","sourcesContent":[null,"function bar() {\\n console.log(\'yes?\');\\n}"]}'125, 'encodes generated mappings including source content'126)127t.equal(128gen.inlineMappingUrl()129, '//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImZvby5qcyIsImJhci5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUNBQSxBREFBO0FDQ0EsQURBQTtBQ0NBLEFEQUE7QUFDQTtBQUNBIiwiZmlsZSI6IiIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzQ29udGVudCI6W251bGwsImZ1bmN0aW9uIGJhcigpIHtcbiAgY29uc29sZS5sb2coJ3llcz8nKTtcbn0iXX0='130, 'returns correct inline mapping url including source content'131)132t.end()133})134})135136137