insert.js
1.21 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
var test = require('tape');
var mdeps = require('module-deps');
var bpack = require('browser-pack');
var insert = require('../');
var concat = require('concat-stream');
var vm = require('vm');
test('process.nextTick inserts', function (t) {
t.plan(4);
var s = mdeps()
s.pipe(bpack({ raw: true })).pipe(concat(function (src) {
var c = {
t: t,
setTimeout: setTimeout,
clearTimeout: clearTimeout
};
vm.runInNewContext(src, c);
}));
s.write({ transform: inserter, global: true })
s.end(__dirname + '/insert/main.js');
});
test('buffer inserts', function (t) {
t.plan(2);
var s = mdeps({
modules: { buffer: require.resolve('buffer/') }
});
s.pipe(bpack({ raw: true })).pipe(concat(function (src) {
var c = {
t: t,
setTimeout: setTimeout,
clearTimeout: clearTimeout,
Uint8Array: Uint8Array,
DataView: DataView
};
vm.runInNewContext(src, c);
}));
s.write({ transform: inserter, global: true })
s.end(__dirname + '/insert/buffer.js');
});
function inserter (file) {
return insert(file, {
basedir: __dirname + '/insert'
});
}