UNPKG

1.12 kBJavaScriptView Raw
1'use strict';
2/*jshint asi: true */
3
4var test = require('tap').test
5 , path = require('path')
6 , fs = require('fs')
7 , browserify = require('browserify')
8 , convert = require('convert-source-map')
9 , mold = require('..')
10 , jsRoot = path.join(__dirname, '..', 'examples', 'project')
11
12test('mold sources', function (t) {
13 t.plan(4)
14
15 var bundle = '';
16 browserify()
17 .require(require.resolve('../examples/project/js/main.js'), { entry: true })
18 .bundle({ debug: true })
19 .pipe(mold.transformSourcesRelativeTo(jsRoot))
20 .on('error', function (err) { console.error(err); })
21 .on('data', function (data) {
22 bundle += data;
23 })
24 .on('end', function () {
25 var sm = convert.fromSource(bundle);
26 var sources = sm.getProperty('sources');
27
28 t.equal(sources.length, 3, 'molds 3 sources')
29 t.ok(~sources.indexOf('js/main.js'), 'molds main.js relative to root')
30 t.ok(~sources.indexOf('js/foo.js'), 'molds foo.js relative to root')
31 t.ok(~sources.indexOf('js/wunder/bar.js'), 'molds wunder/bar.js relative to root')
32 });
33});