test_runner: run t.after() if test body throws · nodejs/node@c5004d4 · GitHub
Skip to content

Commit c5004d4

Browse files
cjihrigtargos
authored andcommitted
test_runner: run t.after() if test body throws
This commit fixes a bug where t.after() was not called if the test body threw an exception. PR-URL: #45870 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 10367c4 commit c5004d4

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

lib/internal/test_runner/test.js

Lines changed: 7 additions & 1 deletion

test/message/test_runner_hooks.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,10 @@ test('afterEach throws and test fails', async (t) => {
142142
await t.test('1', () => { throw new Error('test'); });
143143
await t.test('2', () => {});
144144
});
145+
146+
test('t.after() is called if test body throws', (t) => {
147+
t.after(() => {
148+
t.diagnostic('- after() called');
149+
});
150+
throw new Error('bye');
151+
});

test/message/test_runner_hooks.out

Lines changed: 21 additions & 3 deletions

0 commit comments

Comments
 (0)