UNPKG

1.8 kBJavaScriptView Raw
1var test = require('tap').test;
2var browserify = require('../');
3var through = require('through2');
4var vm = require('vm');
5
6test('ordinary debug', function (t) {
7 t.plan(1);
8
9 var stream = through();
10 stream.push('console.log(1+2)');
11 stream.push(null);
12
13 var b = browserify({ debug: true });
14 b.add(stream);
15 b.bundle(function (err, buf) {
16 var src = buf.toString('utf8');
17 var last = src.split('\n').slice(-2)[0];
18 t.ok(
19 /\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,[\w+\/=]+$/
20 .test(last)
21 );
22 });
23});
24
25test('debug standalone', function (t) {
26 t.plan(1);
27
28 var stream = through();
29 stream.push('console.log(1+2)');
30 stream.push(null);
31
32 var b = browserify({ debug: true, standalone: 'xyz' });
33 b.add(stream);
34 b.bundle(function (err, buf) {
35 var src = buf.toString('utf8');
36 var last = src.split('\n').slice(-2)[0];
37 t.ok(
38 /\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,[\w+\/=]+$/
39 .test(last)
40 );
41 });
42});
43
44test('debug standalone exposed', function (t) {
45 t.plan(2);
46
47 var stream = through();
48 stream.push('console.log(1+2)');
49 stream.push(null);
50
51 var b = browserify({ debug: true, standalone: 'xyz' });
52 b.require(__dirname + '/debug_standalone/x.js', { expose: 'xxx' });
53 b.bundle(function (err, buf) {
54 var src = buf.toString('utf8');
55 var last = src.split('\n').slice(-2)[0];
56 t.ok(
57 /\/\/# sourceMappingURL=data:application\/json;charset=utf-8;base64,[\w+\/=]+$/
58 .test(last)
59 );
60 var c = { window: {} };
61 vm.runInNewContext(src, c);
62 t.equal(c.window.xyz, 555);
63 });
64});