-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
index.js
67 lines (63 loc) · 1.89 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
58
59
60
61
62
63
64
65
66
67
const path = require('path');
const rollup = require('../../dist/rollup');
const { compareWarnings, extend, runTestSuiteWithSamples } = require('../utils.js');
const FORMATS = ['amd', 'cjs', 'system', 'es', 'iife', 'umd'];
runTestSuiteWithSamples('sourcemaps', path.resolve(__dirname, 'samples'), (dir, config) => {
(config.skip ? describe.skip : config.solo ? describe.only : describe)(
path.basename(dir) + ': ' + config.description,
() => {
(config.formats || FORMATS).forEach(format =>
it('generates ' + format, () => {
process.chdir(dir);
const warnings = [];
const inputOptions = extend(
{
input: dir + '/main.js',
onwarn: warning => warnings.push(warning)
},
config.options || {}
);
const outputOptions = extend(
{
file: dir + '/_actual/bundle.' + format + '.js',
format,
sourcemap: true
},
(config.options || {}).output || {}
);
return rollup.rollup(inputOptions).then(bundle =>
generateAndTestBundle(bundle, outputOptions, config, format, warnings).then(() => {
// cache rebuild does not reemit warnings.
if (config.warnings) {
return;
}
// test cache noop rebuild
return rollup
.rollup(extend({ cache: bundle }, inputOptions))
.then(bundle =>
generateAndTestBundle(bundle, outputOptions, config, format, warnings)
);
})
);
})
);
}
);
});
function generateAndTestBundle(bundle, outputOptions, config, format, warnings) {
return bundle
.write(outputOptions)
.then(() => {
if (config.warnings) {
compareWarnings(warnings, config.warnings);
} else if (warnings.length) {
throw new Error(`Unexpected warnings`);
}
return bundle.generate(outputOptions);
})
.then(({ output: [{ code, map }] }) => {
if (config.test) {
return config.test(code, map, { format });
}
});
}