@tapjs/after
Advanced tools
Comparing version 0.0.0-18 to 0.0.0-19
@@ -57,3 +57,3 @@ "use strict"; | ||
let fn; | ||
while ((fn = this.#onTeardown.shift())) { | ||
while ((fn = this.#onTeardown.pop())) { | ||
try { | ||
@@ -60,0 +60,0 @@ const ret = fn.call(this.#t.t); |
@@ -54,3 +54,3 @@ /** | ||
let fn; | ||
while ((fn = this.#onTeardown.shift())) { | ||
while ((fn = this.#onTeardown.pop())) { | ||
try { | ||
@@ -57,0 +57,0 @@ const ret = fn.call(this.#t.t); |
{ | ||
"name": "@tapjs/after", | ||
"version": "0.0.0-18", | ||
"version": "0.0.0-19", | ||
"description": "a built-in tap extension for t.after() and t.teardown()", | ||
@@ -35,5 +35,3 @@ "type": "module", | ||
"keywords": [ | ||
"tap", | ||
"spy", | ||
"fake" | ||
"tapjs plugin" | ||
], | ||
@@ -47,3 +45,3 @@ "author": "Isaac Z. Schlueter", | ||
"peerDependencies": { | ||
"@tapjs/core": "0.0.0-18" | ||
"@tapjs/core": "0.0.0-19" | ||
}, | ||
@@ -50,0 +48,0 @@ "engines": { |
@@ -52,1 +52,53 @@ # `@tapjs/after` | ||
``` | ||
## 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: | ||
```js | ||
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: | ||
```js | ||
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)) | ||
}) | ||
}) | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18636
104