Skip to content

failFast causes process to exit before always.afterEach hooks complete #820

@bundacia

Description

@bundacia

Description

If I try and do something asynchronous (or just slow?) from an always.afterEach() function while the failFast flag is set in my package.json the process won't wait for it to complete when the test fails. My specific case if is that I'm trying to do some database cleanup after each test and even though the afterEach hook gets called it doesn't seem to be given a chance to finish before the process exits.

I've tried to distill this down to a simple example:

import test from 'ava'

test.afterEach.always('CLEANUP', async t => {
  console.log('START', t.title)

  await new Promise(resolve => setTimeout(resolve, 5000))

  console.log('END', t.title)
})

test('Test', async t => {
  console.log('START', t.title)
  t.plan(1)

  t.is(1, 2)
  console.log('END', t.title)
})

This is the output I get:

START Test
END Test
  ✖ Test 1 === 2
START CLEANUP for Test

  1 test failed [10:42:18]


  1. Test
  AssertionError: 1 === 2
    _callee2$ (cleanup-test.js:15:5)
    Test.fn (cleanup-test.js:11:1)

I would expect to see END CLEANUP printed

Environment

Node.js v5.11.0
darwin 15.3.0

(Originally asked on SO: From http://stackoverflow.com/questions/37118762/ava-aftereach-callback-not-completing)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcurrent functionality does not work as desired

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions