@tapjs/after
a built-in tap extension for t.after() and t.teardown()
Last updated 5 months ago by isaacs .
BlueOak-1.0.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @tapjs/after 
SYNC missed versions from official npm registry.

@tapjs/after

A default tap plugin providing t.after() and t.teardown().

USAGE

This plugin is installed with tap by default. If you had previously removed it, you can tap plugin add @tapjs/after to bring it back.

import t from 'tap'
t.after(() => {
  // this will run after all the tests in this file are done
})

The method can be called as either t.teardown() or t.after(). In an earlier version of tap, these had slightly different behaviors, but they are now the same.

If the method returns a promise, it will be awaited before moving on to the next test.

So, this test:

import t from 'tap'

t.test('first test', t => {
  t.teardown(async () => {
    // this will wait before moving on
    await new Promise(res => setTimeout(res, 100))
    console.error('end of first test teardown')
  })
  console.error('in first test')
  t.end()
})
t.test('second test', t => {
  console.error('in second test')
  t.end()
})

will print:

in first test
end of first test teardown
in second test

Order

If multiple teardown methods are assigned to a single test, they will be run in reverse order of how they are assigned. This is a change from earlier versions of tap, and provides symmetry with t.before().

In practice, it can make things more straightforward, by keeping cleanup methods close to their associated setup logic. For example:

const connection = await connectToDB()
t.ok(connection, 'connected to database')
t.teardown(() => disconnectFromDB(connection))

const user1 = await createUser(connection)
t.ok(user1, 'created user 1')
t.teardown(() => deleteUser(connection, user1))

const user2 = await createUser(connection)
t.ok(user2, 'created user 2')
t.teardown(() => deleteUser(connection, user2))

If we delete the connection created in the first step before deleting the user records, then we can't use that connection to delete the user records.

This can also be accomplished with subtests, and a single teardown in each section:

t.test('user db tests', async t => {
  const connection = await connectToDB()
  t.ok(connection, 'connected to database')
  t.teardown(() => disconnectFromDB(connection))

  t.test('user 1', async t => {
    const user1 = await createUser(connection)
    t.ok(user1, 'created user 1')
    t.teardown(() => deleteUser(connection, user1))
  })

  t.test('user 2', async t => {
    const user2 = await createUser(connection)
    t.ok(user2, 'created user 2')
    t.teardown(() => deleteUser(connection, user2))
  })
})

Current Tags

  • 3.0.0                                ...           latest (4 months ago)
  • 1.0.0                                ...           pre (a year ago)

68 Versions

  • 3.0.0                                ...           4 months ago
  • 2.0.3                                ...           5 months ago
  • 2.0.2                                ...           5 months ago
  • 2.0.1                                ...           5 months ago
  • 2.0.0                                ...           5 months ago
  • 1.1.31                                ...           5 months ago
  • 1.1.30                                ...           5 months ago
  • 1.1.29                                ...           5 months ago
  • 1.1.28                                ...           5 months ago
  • 1.1.27                                ...           5 months ago
  • 1.1.26                                ...           5 months ago
  • 1.1.25                                ...           5 months ago
  • 1.1.24                                ...           6 months ago
  • 1.1.23                                ...           6 months ago
  • 1.1.22                                ...           6 months ago
  • 1.1.21                                ...           6 months ago
  • 1.1.20                                ...           8 months ago
  • 1.1.19                                ...           8 months ago
  • 1.1.18                                ...           10 months ago
  • 1.1.17                                ...           a year ago
  • 1.1.16                                ...           a year ago
  • 1.1.15                                ...           a year ago
  • 1.1.14                                ...           a year ago
  • 1.1.13                                ...           a year ago
  • 1.1.12                                ...           a year ago
  • 1.1.11                                ...           a year ago
  • 1.1.10                                ...           a year ago
  • 1.1.9                                ...           a year ago
  • 1.1.8                                ...           a year ago
  • 1.1.7                                ...           a year ago
  • 1.1.6                                ...           a year ago
  • 1.1.5                                ...           a year ago
  • 1.1.4                                ...           a year ago
  • 1.1.3                                ...           a year ago
  • 1.1.2                                ...           a year ago
  • 1.1.1                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.7                                ...           a year ago
  • 1.0.6                                ...           a year ago
  • 1.0.5                                ...           a year ago
  • 1.0.4                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 0.0.0-22                                ...           a year ago
  • 0.0.0-21                                ...           a year ago
  • 0.0.0-20                                ...           a year ago
  • 0.0.0-19                                ...           a year ago
  • 0.0.0-18                                ...           a year ago
  • 0.0.0-17                                ...           a year ago
  • 0.0.0-16                                ...           a year ago
  • 0.0.0-15                                ...           a year ago
  • 0.0.0-14                                ...           a year ago
  • 0.0.0-13                                ...           a year ago
  • 0.0.0-12                                ...           a year ago
  • 0.0.0-11                                ...           a year ago
  • 0.0.0-10                                ...           a year ago
  • 0.0.0-9                                ...           a year ago
  • 0.0.0-8                                ...           a year ago
  • 0.0.0-7                                ...           a year ago
  • 0.0.0-6                                ...           a year ago
  • 0.0.0-5                                ...           a year ago
  • 0.0.0-4                                ...           a year ago
  • 0.0.0-3                                ...           a year ago
  • 0.0.0-2                                ...           a year ago
  • 0.0.0-1                                ...           a year ago
  • 0.0.0-0                                ...           a year ago
Maintainers (2)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None

© 2010 - cnpmjs.org x YWFE | Home | YWFE