diff --git a/bin/src/run/watch.ts b/bin/src/run/watch.ts index d09ab82bff2..eec4d29f078 100644 --- a/bin/src/run/watch.ts +++ b/bin/src/run/watch.ts @@ -42,6 +42,7 @@ export default function watch( const warnings = batchWarnings(); + let processConfigsErr: any; const initialConfigs = processConfigs(configs); const clearScreen = initialConfigs.every(config => config.watch.clearScreen !== false); @@ -52,8 +53,6 @@ export default function watch( let watcher: Watcher; let configWatcher: Watcher; - let processConfigsErr: any; - function processConfigs(configs: RollupWatchOptions[]): RollupWatchOptions[] { return configs.map(options => { const merged = mergeOptions({ diff --git a/test/chunking-form/samples/manual-chunks-function/_config.js b/test/chunking-form/samples/manual-chunks-function/_config.js index 0ea976037f8..7dce4fbb810 100644 --- a/test/chunking-form/samples/manual-chunks-function/_config.js +++ b/test/chunking-form/samples/manual-chunks-function/_config.js @@ -4,7 +4,6 @@ module.exports = { input: ['main-a'], manualChunks(id) { if (id[id.length - 5] === '-') { - console.log(id, id[id.length - 4]); return `chunk-${id[id.length - 4]}`; } } diff --git a/test/cli/index.js b/test/cli/index.js index 325f488b5c5..9aa7f6abc5b 100644 --- a/test/cli/index.js +++ b/test/cli/index.js @@ -25,8 +25,8 @@ runTestSuiteWithSamples( const command = 'node ' + path.resolve(__dirname, '../../bin') + path.sep + config.command; - exec(command, {}, (err, code, stderr) => { - if (err) { + const childProcess = exec(command, { timeout: 2000 }, (err, code, stderr) => { + if (err && !err.killed) { if (config.error) { const shouldContinue = config.error(err); if (!shouldContinue) return done(); @@ -111,6 +111,12 @@ runTestSuiteWithSamples( } } }); + + childProcess.stderr.on('data', data => { + if (config.abortOnStderr && config.abortOnStderr(data)) { + childProcess.kill('SIGINT'); + } + }); } ); }, diff --git a/test/cli/samples/watch/_config.js b/test/cli/samples/watch/_config.js new file mode 100644 index 00000000000..85833195535 --- /dev/null +++ b/test/cli/samples/watch/_config.js @@ -0,0 +1,9 @@ +module.exports = { + description: 'does not fail in watch-mode with clearScreen: false', + command: 'rollup -cw', + abortOnStderr(data) { + if (data.includes('created')) { + return true; + } + } +}; diff --git a/test/cli/samples/watch/_expected.js b/test/cli/samples/watch/_expected.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/cli/samples/watch/foo.js b/test/cli/samples/watch/foo.js new file mode 100644 index 00000000000..3b8dc9fedfc --- /dev/null +++ b/test/cli/samples/watch/foo.js @@ -0,0 +1 @@ +export var foo = 42; diff --git a/test/cli/samples/watch/main.js b/test/cli/samples/watch/main.js new file mode 100644 index 00000000000..8ab8dbd37ef --- /dev/null +++ b/test/cli/samples/watch/main.js @@ -0,0 +1,3 @@ +import { foo } from './foo.js'; + +assert.equal( foo, 42 ); diff --git a/test/cli/samples/watch/rollup.config.js b/test/cli/samples/watch/rollup.config.js new file mode 100644 index 00000000000..1b6e0556847 --- /dev/null +++ b/test/cli/samples/watch/rollup.config.js @@ -0,0 +1,10 @@ +export default { + input: 'main.js', + output: { + file: '_actual.js', + format: 'esm' + }, + watch: { + clearScreen: false + } +};