forked from rollup/rollup
/
write-bundle.js
72 lines (68 loc) · 1.52 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
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('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"./);
});
});
});