/
_config.js
59 lines (57 loc) · 1.52 KB
/
_config.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
const fs = require('fs');
const path = require('path');
const { atomicWriteFileSync, syncFile } = require('../../../../utils');
let configFile;
module.exports = {
description: 'immediately reloads the config file if a change happens while it is parsed',
command: 'rollup -cw',
before() {
// This test writes a config file that prints a message to stderr but delays resolving to a
// config. The stderr message is observed by the parent process and triggers overwriting the
// config file. That way, we simulate a complicated config file being changed while it is parsed.
configFile = path.resolve(__dirname, 'rollup.config.js');
fs.writeFileSync(
configFile,
`
console.error('initial');
export default new Promise(resolve => {
setTimeout(
() =>
resolve({
input: 'main.js',
output: {
file: '_actual/output1.js',
format: 'es'
}
}),
3000
);
});`
);
},
after() {
fs.unlinkSync(configFile);
},
abortOnStderr(data) {
if (data === 'initial\n') {
atomicWriteFileSync(
configFile,
`
console.error('updated');
export default {
input: 'main.js',
output: {
file: '_actual/output2.js',
format: "es"
}
};
`
);
syncFile(configFile);
return false;
}
if (data.includes(`created _actual${path.sep}output2.js`)) {
return new Promise(resolve => setTimeout(() => resolve(true), 600));
}
}
};