/
write-bundle.js
98 lines (92 loc) · 1.98 KB
/
write-bundle.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
const assert = require('assert');
const rollup = require('../../dist/rollup');
const { loader } = require('../utils.js');
describe('bundle.write()', () => {
it('fails without options or options.file', () => {
return rollup
.rollup({
input: 'x',
plugins: [
{
resolveId: () => 'test',
load: () => '// empty'
}
]
})
.then(bundle => {
assert.throws(() => {
bundle.write();
}, /You must supply an options object/);
assert.throws(() => {
bundle.write({format: 'esm'});
}, /You must specify "output\.file"/);
});
});
it('expects output.name for UMD bundles', () => {
let bundle;
return rollup
.rollup({
input: 'x',
plugins: [
{
resolveId: () => 'test',
load: () => 'export var foo = 42;'
}
]
})
.then(rollupInstance => {
bundle = rollupInstance;
return bundle.generate({
format: 'umd'
});
})
.catch(err => {
assert.throws(() => {
throw err;
}, /You must supply "output\.name" for UMD bundles/);
});
});
it('throws on es6 format', () => {
return rollup
.rollup({
input: 'x',
plugins: [
{
resolveId: () => {
return 'test';
},
load: () => {
return '// empty';
}
}
]
})
.then(bundle => {
assert.throws(() => {
return bundle.generate({ format: 'es6' });
}, /The "es6" output format is deprecated – use "esm" instead/);
});
});
it('works when output options is an array', () => {
const warnings = [];
const options = {
input: 'x',
plugins: [loader({ x: `console.log( 42 );` })],
onwarn: warning => warnings.push(warning),
output: [
{
format: 'cjs'
},
{
format: 'es'
}
]
};
return rollup.rollup(options).then(bundle => {
assert.equal(warnings.length, 0, 'No warnings for UNKNOWN');
assert.throws(() => {
return Promise.all(options.output.map(o => bundle.write(o)));
}, /You must specify "output\.file"./);
});
});
});