-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
index.js
57 lines (53 loc) · 1.49 KB
/
index.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
const path = require('path');
const rollup = require('../../dist/rollup');
const { extend, runTestSuiteWithSamples, assertDirectoriesAreEqual } = require('../utils.js');
const FORMATS = ['es', 'cjs', 'amd', 'system'];
runTestSuiteWithSamples('chunking form', path.resolve(__dirname, 'samples'), (dir, config) => {
(config.skip ? describe.skip : config.solo ? describe.only : describe)(
path.basename(dir) + ': ' + config.description,
() => {
let rollupPromise;
FORMATS.forEach(format =>
it('generates ' + format, () => {
process.chdir(dir);
return (
rollupPromise ||
(rollupPromise = rollup.rollup(
extend(
{
input: [dir + '/main.js'],
experimentalCodeSplitting: true,
onwarn: msg => {
if (/No name was provided for/.test(msg)) return;
if (/as external dependency/.test(msg)) return;
console.error(msg);
}
},
config.options || {}
)
))
).then(bundle =>
generateAndTestBundle(
bundle,
extend(
{
dir: dir + '/_actual/' + format,
format,
chunkFileNames: 'generated-[name].js'
},
(config.options || {}).output || {}
),
dir + '/_expected/' + format,
config
)
);
})
);
}
);
});
function generateAndTestBundle(bundle, outputOptions, expectedDir) {
return bundle
.write(outputOptions)
.then(() => assertDirectoriesAreEqual(outputOptions.dir, expectedDir));
}