1 | 'use strict';
|
2 |
|
3 |
|
4 | var test = require('tap').test
|
5 | , browserify = require('browserify')
|
6 | , convert = require('convert-source-map')
|
7 | , mold = require('..')
|
8 |
|
9 |
|
10 | function mapFileUrlComment(sourcemap, cb) {
|
11 | setTimeout(function () {
|
12 | cb('//@ sourceMappingURL=' + '/bundle.js.map');
|
13 | }, 5);
|
14 | }
|
15 |
|
16 | function mapFileUrlCommentSync(sourcemap) {
|
17 | return '//@ sourceMappingURL=' + '/bundle.js.map';
|
18 | }
|
19 |
|
20 | test('mold transform async', function (t) {
|
21 | t.plan(2)
|
22 | var bundle = '';
|
23 | browserify()
|
24 | .require(require.resolve('../examples/project/js/main.js'), { entry: true })
|
25 | .bundle({ debug: true })
|
26 | .pipe(mold.transform(mapFileUrlComment))
|
27 | .on('error', function (err) { console.error(err); })
|
28 | .on('data', function (data) {
|
29 | bundle += data;
|
30 | })
|
31 | .on('end', function () {
|
32 | t.notOk(~bundle.indexOf('application/json'), 'removes original comment')
|
33 | t.ok(~bundle.indexOf('//@ sourceMappingURL=/bundle.js.map'), 'adds returned comment')
|
34 | });
|
35 | });
|
36 |
|
37 | test('mold transform sync', function (t) {
|
38 | t.plan(2)
|
39 | var bundle = '';
|
40 | browserify()
|
41 | .require(require.resolve('../examples/project/js/main.js'), { entry: true })
|
42 | .bundle({ debug: true })
|
43 | .pipe(mold.transform(mapFileUrlCommentSync))
|
44 | .on('error', function (err) { console.error(err); })
|
45 | .on('data', function (data) {
|
46 | bundle += data;
|
47 | })
|
48 | .on('end', function () {
|
49 | t.notOk(~bundle.indexOf('application/json'), 'removes original comment')
|
50 | t.ok(~bundle.indexOf('//@ sourceMappingURL=/bundle.js.map'), 'adds returned comment')
|
51 | });
|
52 | });
|