diff --git a/.eslintignore b/.eslintignore index 25fbf5a1..d6699189 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ node_modules/ coverage/ +test/fixtures diff --git a/src/cmd/test.ts b/src/cmd/test.ts index b47216bd..40eb5ec4 100644 --- a/src/cmd/test.ts +++ b/src/cmd/test.ts @@ -107,7 +107,13 @@ export class TestCommand extends BaseCommand { const mochaArgs = await this.formatMochaArgs(); if (!mochaArgs) return; - await this.forkNode(mochaFile, mochaArgs); + await this.forkNode(mochaFile, mochaArgs, { + execArgv: [ + ...process.execArgv, + // https://github.com/mochajs/mocha/issues/2640#issuecomment-1663388547 + '--unhandled-rejections=strict', + ], + }); } protected async formatMochaArgs() { diff --git a/test/cmd/test.test.ts b/test/cmd/test.test.ts index 767a28d5..b4626aef 100644 --- a/test/cmd/test.test.ts +++ b/test/cmd/test.test.ts @@ -168,6 +168,14 @@ describe('test/cmd/test.test.ts', () => { .end(); }); + it('should success js', () => { + return coffee.fork(eggBin, [ 'test' ], { cwd: path.join(fixtures, 'test-unhandled-rejection') }) + // .debug() + .expect('stdout', / Uncaught Error: mock error/) + .expect('code', 1) + .end(); + }); + it('test parallel', () => { if (process.platform === 'win32') return; return coffee.fork(eggBin, [ 'test', '--parallel' ], { diff --git a/test/fixtures/test-unhandled-rejection/package.json b/test/fixtures/test-unhandled-rejection/package.json new file mode 100644 index 00000000..1633ac83 --- /dev/null +++ b/test/fixtures/test-unhandled-rejection/package.json @@ -0,0 +1,6 @@ +{ + "name": "test-unhandled-rejection", + "files": [ + "lib" + ] +} diff --git a/test/fixtures/test-unhandled-rejection/test/a.test.js b/test/fixtures/test-unhandled-rejection/test/a.test.js new file mode 100644 index 00000000..61cdb364 --- /dev/null +++ b/test/fixtures/test-unhandled-rejection/test/a.test.js @@ -0,0 +1,5 @@ +describe('a.test.js', () => { + it('should success', () => { + Promise.reject(new Error('mock error')); + }); +});