array.js
1.97 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var browserify = require('../');
var vm = require('vm');
var test = require('tap').test;
test('array add', function (t) {
var expected = [ 'ONE', 'TWO', 'THREE' ];
t.plan(expected.length);
var b = browserify();
var files = [
__dirname + '/array/one.js',
__dirname + '/array/two.js',
__dirname + '/array/three.js'
];
b.add(files);
b.bundle(function (err, src) {
vm.runInNewContext(src, { console: { log: log } });
function log (msg) {
t.equal(msg, expected.shift());
}
});
});
test('array require', function (t) {
t.plan(3);
var b = browserify();
var files = [ 'defined', 'subarg' ];
b.require(files);
b.bundle(function (err, src) {
var c = {};
vm.runInNewContext(src, c);
t.equal(c.require('defined')(undefined, true), true);
t.equal(c.require('defined')(undefined, false), false);
t.deepEqual(c.require('subarg')(['-x', '3']), { x: 3, _: [] });
});
});
test('array require opts', function (t) {
t.plan(3);
var b = browserify();
var files = [
{ file: require.resolve('defined'), expose: 'abc' },
{ file: require.resolve('subarg'), expose: 'def' }
];
b.require(files);
b.bundle(function (err, src) {
var c = {};
vm.runInNewContext(src, c);
t.equal(c.require('abc')(undefined, true), true);
t.equal(c.require('abc')(undefined, false), false);
t.deepEqual(c.require('def')(['-x', '3']), { x: 3, _: [] });
});
});
test('array external', function (t) {
t.plan(2);
var b = browserify(__dirname + '/external/main.js');
b.external(['util','freelist']);
b.bundle(function (err, src) {
if (err) return t.fail(err);
vm.runInNewContext(
'function require (x) {'
+ 'if (x==="freelist") return function (n) { return n + 1000 }'
+ '}'
+ src,
{ t: t }
);
});
});