require_expose.js
1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var browserify = require('../');
var test = require('tap').test;
var vm = require('vm');
test('require expose external module', function (t) {
t.plan(2);
var b = browserify({ basedir: __dirname });
b.require('beep', { expose: 'bip' });
b.bundle(function (err, src) {
t.ifError(err);
var c = { };
vm.runInNewContext(src, c);
t.equal(c.require('bip'), 'boop');
})
});
test('renaming builtin', function (t) {
t.plan(2);
var b = browserify({ basedir: __dirname });
b.require('os', { expose: 'bone' });
b.bundle(function (err, src) {
t.ifError(err);
var c = { };
vm.runInNewContext(src, c);
t.equal(c.require('bone').platform(), 'browser');
})
});
test('exposed modules do not leak across bundles', function (t) {
var bundle1, bundle2;
bundle1 = browserify();
bundle1.add(__dirname + '/require_expose/main.js');
bundle1.require(__dirname + '/require_expose/some_dep.js', { expose: 'foo' });
bundle1.bundle(function (err, src) {
if (err) t.fail(err);
var c = {};
vm.runInNewContext(src, c);
t.equal(c.foo, 'some_dep');
bundle2 = browserify();
bundle2.add(__dirname + '/require_expose/main.js');
bundle2.bundle(function (err) {
t.ok(err && err.message.match(/Cannot find module 'foo'/), 'should fail with missing module');
t.end();
});
});
});