multi_entry.js
2.78 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var browserify = require('../');
var vm = require('vm');
var path = require('path');
var test = require('tap').test;
var fs = require('fs');
var testFiles = [
path.join(__dirname, 'multi_entry/a.js'),
path.join(__dirname, 'multi_entry/b.js'),
path.join(__dirname, 'multi_entry/c.js')
];
test('multi entry', function (t) {
t.plan(6);
var b = browserify([
testFiles[0],
testFiles[1]
]);
b.add(testFiles[2]);
b.on('dep', function(row) {
if (row.entry) {
t.ok(testFiles.indexOf(row.file) > -1, 'should contain full entry path');
}
});
b.bundle(function (err, src) {
var c = {
times : 0,
t : t
};
vm.runInNewContext(src, c);
});
});
test('multi entry relative', function (t) {
t.plan(6);
var rTestFiles = testFiles.map(function(x) {
return x.replace(__dirname + '/', '');
});
var b = browserify({
entries: [rTestFiles[0], rTestFiles[1]],
basedir: __dirname
});
b.add(rTestFiles[2]);
b.on('dep', function(row) {
if (row.entry) {
t.ok(testFiles.indexOf(row.file) > -1, 'should contain full entry path');
}
});
b.bundle(function (err, src) {
var c = {
times : 0,
t : t
};
vm.runInNewContext(src, c);
});
});
test('multi entry relative cwd', function (t) {
t.plan(6);
var rTestFiles = testFiles.map(function(x) {
return x.replace(__dirname + '/', './');
});
var b = browserify({
entries: [rTestFiles[0], rTestFiles[1]],
basedir: __dirname
});
b.add(rTestFiles[2]);
b.on('dep', function(row) {
if (row.entry) {
t.ok(testFiles.indexOf(row.file) > -1, 'should contain full entry path');
}
});
b.bundle(function (err, src) {
var c = {
times : 0,
t : t
};
vm.runInNewContext(src, c);
});
});
test('entries as streams', function (t) {
t.plan(6);
// commondir blows up with streams and without basedir
var opts = { basedir: __dirname + '/multi_entry' };
var b = browserify([
fs.createReadStream(testFiles[0]),
fs.createReadStream(testFiles[1])
], opts);
b.add(fs.createReadStream(testFiles[2]));
b.on('dep', function(row) {
if (row.entry) {
t.similar(
row.file,
RegExp(path.join(__dirname, 'multi_entry/_stream_').replace(/\\/g, '\\\\') + '[\\d].js'),
'should be full entry path'
);
}
});
b.bundle(function (err, src) {
var c = {
times : 0,
t : t
};
vm.runInNewContext(src, c);
});
});