/
_config.js
63 lines (61 loc) · 1.72 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
60
61
62
63
const fs = require('fs');
const path = require('path');
const { atomicWriteFileSync } = require('../../../../utils');
let configFile;
module.exports = {
repeat: 10,
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 watches itself for changes and resolves only once it has
// been rewritten. As soon as that watcher is set up, the config file writes a message to stderr
// that is observed by the parent process and triggers overwriting the config file.
// That way, we reliably simulate a complicated config file being changed while it is parsed.
fs.mkdirSync(path.resolve(__dirname, '_actual'));
configFile = path.resolve(__dirname, 'rollup.config.js');
fs.writeFileSync(
configFile,
`
import chokidar from 'chokidar';
export default new Promise(resolve => {
const watcher = chokidar.watch(${JSON.stringify(configFile)})
.on('change', () => {
watcher.close();
setTimeout(() => resolve({
input: { output1: 'main.js' },
output: {
dir: '_actual',
format: 'es'
}
}), 600)
});
console.error('initial');
});
`
);
},
after() {
fs.unlinkSync(configFile);
},
abortOnStderr(data) {
if (data === 'initial\n') {
atomicWriteFileSync(
configFile,
`
console.error('updated');
export default {
input: {output2: "main.js"},
output: {
dir: "_actual",
format: "es"
}
};
`
);
return false;
}
if (data === 'updated\n') {
return new Promise(resolve => setTimeout(() => resolve(true), 500));
}
}
};