forked from parcel-bundler/parcel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbundler.js
99 lines (83 loc) · 2.42 KB
/
bundler.js
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
const assert = require('assert');
const sinon = require('sinon');
const {assertBundleTree, bundle, bundler, nextBundle} = require('./utils');
describe('bundler', function() {
it('should bundle once before exporting middleware', async function() {
let b = bundler(__dirname + '/integration/bundler-middleware/index.js');
b.middleware();
await nextBundle(b);
assert(b.entryAssets);
});
it('should defer bundling if a bundle is pending', async () => {
const b = bundler(__dirname + '/integration/html/index.html');
b.pending = true; // bundle in progress
const spy = sinon.spy(b, 'bundle');
// first bundle, with existing bundle pending
const bundlePromise = b.bundle();
// simulate bundle finished
b.pending = false;
b.emit('buildEnd');
// wait for bundle to complete
await bundlePromise;
assert(spy.calledTwice);
});
it('should enforce asset type path to be a string', () => {
const b = bundler(__dirname + '/integration/html/index.html');
assert.throws(() => {
b.addAssetType('.ext', {});
}, 'should be a module path');
});
it('should enforce setup before bundling', () => {
const b = bundler(__dirname + '/integration/html/index.html');
b.farm = true; // truthy
assert.throws(() => {
b.addAssetType('.ext', __filename);
}, 'before bundling');
assert.throws(() => {
b.addPackager('type', 'packager');
}, 'before bundling');
});
it('should support multiple entry points', async function() {
let b = await bundle([
__dirname + '/integration/multi-entry/one.html',
__dirname + '/integration/multi-entry/two.html'
]);
await assertBundleTree(b, [
{
type: 'html',
assets: ['one.html'],
childBundles: [
{
type: 'js',
assets: ['shared.js']
}
]
},
{
type: 'html',
assets: ['two.html'],
childBundles: []
}
]);
});
it('should support multiple entry points as a glob', async function() {
let b = await bundle(__dirname + '/integration/multi-entry/*.html');
await assertBundleTree(b, [
{
type: 'html',
assets: ['one.html'],
childBundles: [
{
type: 'js',
assets: ['shared.js']
}
]
},
{
type: 'html',
assets: ['two.html'],
childBundles: []
}
]);
});
});