Skip to content

Commit

Permalink
See if we can trigger a stuck watcher by writing again
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jan 14, 2022
1 parent baa6773 commit 71dcc88
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
2 changes: 2 additions & 0 deletions test/cli/samples/wait-for-bundle-input/_config.js
Expand Up @@ -18,5 +18,7 @@ module.exports = {
// wait longer than one polling interval
setTimeout(() => atomicWriteFileSync(mainFile, 'export default 42;'), 600);
}
// We wait for a regular abort as we do not watch
return false;
}
};
2 changes: 1 addition & 1 deletion test/cli/samples/watch/bundle-error/_config.js
Expand Up @@ -17,7 +17,7 @@ module.exports = {
},
abortOnStderr(data) {
if (data.includes('Error: Unexpected token')) {
setTimeout(() => atomicWriteFileSync(mainFile, 'export default 42;'), 500);
atomicWriteFileSync(mainFile, 'export default 42;');
return false;
}
if (data.includes('created _actual')) {
Expand Down
4 changes: 3 additions & 1 deletion test/cli/samples/watch/no-config-file/_config.js
@@ -1,8 +1,10 @@
const path = require('path');

module.exports = {
description: 'watches without a config file',
command: 'rollup main.js --watch --format es --file _actual/main.js',
abortOnStderr(data) {
if (data.includes('created _actual/main.js')) {
if (data.includes(`created _actual${path.sep}main.js`)) {
return true;
}
}
Expand Down
4 changes: 3 additions & 1 deletion test/cli/samples/watch/node-config-file/_config.js
@@ -1,8 +1,10 @@
const path = require('path');

module.exports = {
description: 'watches using a node_modules config files',
command: 'rollup --watch --config node:custom',
abortOnStderr(data) {
if (data.includes('created _actual/main.js')) {
if (data.includes(`created _actual${path.sep}main.js`)) {
return true;
}
}
Expand Down
37 changes: 25 additions & 12 deletions test/cli/samples/watch/watch-config-early-update/_config.js
Expand Up @@ -2,7 +2,9 @@ const fs = require('fs');
const path = require('path');
const { writeAndSync } = require('../../../../utils');

let configFile;
const configFile = path.join(__dirname, 'rollup.config.js');
let updateRetryTimeout;
let retries = 0;

module.exports = {
repeat: 100,
Expand All @@ -15,7 +17,6 @@ module.exports = {
// parsed. To do that, the first config hooks into process.stderr and looks for a log from the
// second config.
// That way, we simulate a complicated config file being changed while it is parsed.
configFile = path.join(__dirname, 'rollup.config.js');
fs.mkdirSync(path.join(__dirname, '_actual'));
writeAndSync(
configFile,
Expand Down Expand Up @@ -49,9 +50,25 @@ module.exports = {
},
abortOnStderr(data) {
if (data === 'initial\n') {
writeAndSync(
configFile,
`
retries = 0;
updateConfig();
return false;
}
if (data.includes(`created _actual${path.sep}output2.js`)) {
clearTimeout(updateRetryTimeout);
return true;
}
}
};

const updateConfig = () => {
if (retries > 0) {
console.error('RETRIED updateConfig', retries);
}
retries++;
writeAndSync(
configFile,
`
console.error('updated');
export default {
input: 'main.js',
Expand All @@ -60,11 +77,7 @@ module.exports = {
format: "es"
}
};`
);
return false;
}
if (data.includes(`created _actual${path.sep}output2.js`)) {
return new Promise(resolve => setTimeout(() => resolve(true), 500));
}
}
);
// rarely, the watcher does not trigger on MacOS
updateRetryTimeout = setTimeout(updateConfig, 1000);
};
2 changes: 1 addition & 1 deletion test/cli/samples/watch/watch-config-error/_config.js
Expand Up @@ -48,7 +48,7 @@ module.exports = {
return false;
}
if (data.includes(`created _actual${path.sep}main2.js`)) {
return new Promise(resolve => setTimeout(() => resolve(true), 600));
return true;
}
}
};
5 changes: 3 additions & 2 deletions test/cli/samples/watch/watch-config-no-update/_config.js
Expand Up @@ -23,9 +23,10 @@ module.exports = {
fs.unlinkSync(configFile);
},
abortOnStderr(data) {
if (data.includes('created _actual/main.js')) {
if (data.includes(`created _actual${path.sep}main.js`)) {
atomicWriteFileSync(configFile, configContent);
return new Promise(resolve => setTimeout(() => resolve(true), 500));
// wait some time for the watcher to trigger
return new Promise(resolve => setTimeout(() => resolve(true), 600));
}
},
stderr(stderr) {
Expand Down

0 comments on commit 71dcc88

Please sign in to comment.