/
index.js
47 lines (45 loc) · 1.4 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
const path = require('path');
const rollup = require('../../dist/rollup');
const { extend, runTestSuiteWithSamples } = require('../utils.js');
const assert = require('assert');
runTestSuiteWithSamples('file hashes', path.resolve(__dirname, 'samples'), (dir, config) => {
(config.skip ? describe.skip : config.solo ? describe.only : describe)(
path.basename(dir) + ': ' + config.description,
() => {
it(`generates correct hashes`, () => {
process.chdir(dir);
return Promise.all(
[config.options1, config.options2].map(options =>
rollup
.rollup(options)
.then(bundle =>
bundle.generate(
extend(
{ format: 'esm', chunkFileNames: '[hash]', entryFileNames: '[hash]' },
options.output
)
)
)
)
).then(([generated1, generated2]) => {
const fileContentsByHash = new Map();
addAndCheckFileContentsByHash(fileContentsByHash, generated1);
addAndCheckFileContentsByHash(fileContentsByHash, generated2);
});
});
}
);
});
function addAndCheckFileContentsByHash(fileContentsByHash, generated) {
for (const chunk of generated.output) {
const hash = chunk.fileName;
if (fileContentsByHash.has(hash)) {
assert.equal(
fileContentsByHash.get(hash),
chunk.code,
'Two chunks contained different code even though the hashes were the same.'
);
}
fileContentsByHash.set(hash, chunk.code);
}
}