Skip to content

Commit

Permalink
Do not swallow other errors when there are unfinished hook actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Feb 18, 2022
1 parent a4d6a4e commit 1bf84e2
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/hookActions.ts
Expand Up @@ -40,6 +40,6 @@ process.on('exit', () => {
err += formatAction(action) + '\n';
}
console.error('%s', err);
process.exit(1);
process.exitCode = 1;
}
});
20 changes: 20 additions & 0 deletions test/cli/samples/unfulfilled-hook-actions-error/_config.js
@@ -0,0 +1,20 @@
const assert = require('assert');
const { assertIncludes } = require('../../../utils.js');

module.exports = {
description: 'does not swallow errors on unfulfilled hooks actions',
command: 'node build.mjs',
after(err) {
// exit code check has to be here as error(err) is only called upon failure
assert.strictEqual(err && err.code, 1);
},
error() {
// do not abort test upon error
return true;
},
stderr(stderr) {
assertIncludes(stderr, '[!] Error: unfinished hook action(s) on exit');
assertIncludes(stderr, '(test) transform');
assertIncludes(stderr, 'Error: Error must be displayed.');
}
};
Empty file.
1 change: 1 addition & 0 deletions test/cli/samples/unfulfilled-hook-actions-error/a.js
@@ -0,0 +1 @@
console.log('a');
1 change: 1 addition & 0 deletions test/cli/samples/unfulfilled-hook-actions-error/b.js
@@ -0,0 +1 @@
console.log('b');
23 changes: 23 additions & 0 deletions test/cli/samples/unfulfilled-hook-actions-error/build.mjs
@@ -0,0 +1,23 @@
import { rollup } from 'rollup';

let resolveA;
const waitForA = new Promise(resolve => (resolveA = resolve));

// The error must not be swallowed when using top-level-await
await rollup({
input: './index.js',
plugins: [
{
name: 'test',
transform(code, id) {
if (id.endsWith('a.js')) {
resolveA();
return new Promise(() => {});
}
if (id.endsWith('b.js')) {
return waitForA.then(() => Promise.reject(new Error('Error must be displayed.')))
}
}
}
]
});
1 change: 1 addition & 0 deletions test/cli/samples/unfulfilled-hook-actions-error/c.js
@@ -0,0 +1 @@
console.log('c');
3 changes: 3 additions & 0 deletions test/cli/samples/unfulfilled-hook-actions-error/index.js
@@ -0,0 +1,3 @@
import './a.js';
import './b.js';
import './c.js';

0 comments on commit 1bf84e2

Please sign in to comment.