{"name":"@tapjs/after","version":"3.3.10","keywords":["tapjs plugin"],"author":{"name":"Isaac Z. Schlueter"},"license":"BlueOak-1.0.0","_id":"@tapjs/after@3.3.10","maintainers":[{"name":"ljharb","email":"ljharb@gmail.com"},{"name":"isaacs","email":"i@izs.me"}],"homepage":"https://github.com/tapjs/tapjs/tree/main/src/after#readme","bugs":{"url":"https://github.com/tapjs/tapjs/issues"},"tap":{"typecheck":false},"dist":{"shasum":"5f00f599fa83c51a5b92f8e05bd28e7748749f1c","tarball":"http://registry-npm.ywwl.com/@tapjs/after/download/@tapjs/after-3.3.10.tgz","fileCount":13,"integrity":"sha512-zAeZAUZ9Su5PgTvczJLzlbUObpAMSFqnd+mIVp1TpgVn6Hc/elPEzZ9oe1hWdz8bInKdisdcx0LK0sv2qJO/dQ==","signatures":[{"sig":"MEUCIGWbb5IphLoT9/ZwdhSwKGQbqsyFgqudBvl1QXvItCSeAiEAl/WtmEhlmyQLWPhkFP3hVhn+4U+6KrwWV9aMvwVnkAs=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18975,"size":4438,"noattachment":false,"key":"/@tapjs/after/-/@tapjs/after-3.3.10.tgz"},"main":"./dist/commonjs/index.js","tshy":{"main":true,"exports":{".":"./src/index.ts","./package.json":"./package.json"},"selfLink":false},"type":"module","types":"./dist/commonjs/index.d.ts","module":"./dist/esm/index.js","engines":{"node":"20 || >=22"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./package.json":"./package.json"},"gitHead":"9b0010e9d33f4aec5d00cdfb6c3dd5cad0649eef","scripts":{"snap":"tap","test":"tap","format":"prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache","prepare":"tshy","presnap":"npm run prepare","pretest":"npm run prepare","typedoc":"typedoc --tsconfig tsconfig/esm.json ./src/*.ts"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"repository":{"url":"git+ssh://git@github.com/tapjs/tapjs.git","path":"src/after","type":"git"},"_npmVersion":"11.12.1","description":"a built-in tap extension for t.after() and t.teardown()","directories":{},"_nodeVersion":"26.0.0","dependencies":{"is-actual-promise":"^1.0.1"},"_hasShrinkwrap":false,"peerDependencies":{"@tapjs/core":"4.5.8"},"_npmOperationalInternal":{"tmp":"tmp/after_3.3.10_1778873803646_0.44172198720636335","host":"s3://npm-registry-packages-npm-production"},"readme":"# `@tapjs/after`\n\nA default tap plugin providing `t.after()` and `t.teardown()`.\n\n## USAGE\n\nThis plugin is installed with tap by default. If you had\npreviously removed it, you can `tap plugin add @tapjs/after` to\nbring it back.\n\n```ts\nimport t from 'tap'\nt.after(() => {\n  // this will run after all the tests in this file are done\n})\n```\n\nThe method can be called as either `t.teardown()` or `t.after()`.\nIn an earlier version of tap, these had slightly different\nbehaviors, but they are now the same.\n\nIf the method returns a promise, it will be awaited before moving\non to the next test.\n\nSo, this test:\n\n```js\nimport t from 'tap'\n\nt.test('first test', t => {\n  t.teardown(async () => {\n    // this will wait before moving on\n    await new Promise(res => setTimeout(res, 100))\n    console.error('end of first test teardown')\n  })\n  console.error('in first test')\n  t.end()\n})\nt.test('second test', t => {\n  console.error('in second test')\n  t.end()\n})\n```\n\nwill print:\n\n```\nin first test\nend of first test teardown\nin second test\n```\n\n## Order\n\nIf multiple teardown methods are assigned to a single test, they\nwill be run in _reverse_ order of how they are assigned. This is\na change from earlier versions of tap, and provides symmetry with\n`t.before()`.\n\nIn practice, it can make things more straightforward, by keeping\ncleanup methods close to their associated setup logic. For\nexample:\n\n```js\nconst connection = await connectToDB()\nt.ok(connection, 'connected to database')\nt.teardown(() => disconnectFromDB(connection))\n\nconst user1 = await createUser(connection)\nt.ok(user1, 'created user 1')\nt.teardown(() => deleteUser(connection, user1))\n\nconst user2 = await createUser(connection)\nt.ok(user2, 'created user 2')\nt.teardown(() => deleteUser(connection, user2))\n```\n\nIf we delete the connection created in the first step _before_\ndeleting the user records, then we can't use that connection to\ndelete the user records.\n\nThis can also be accomplished with subtests, and a single\nteardown in each section:\n\n```js\nt.test('user db tests', async t => {\n  const connection = await connectToDB()\n  t.ok(connection, 'connected to database')\n  t.teardown(() => disconnectFromDB(connection))\n\n  t.test('user 1', async t => {\n    const user1 = await createUser(connection)\n    t.ok(user1, 'created user 1')\n    t.teardown(() => deleteUser(connection, user1))\n  })\n\n  t.test('user 2', async t => {\n    const user2 = await createUser(connection)\n    t.ok(user2, 'created user 2')\n    t.teardown(() => deleteUser(connection, user2))\n  })\n})\n```\n","publish_time":1778873803778,"_cnpm_publish_time":1778873803778,"dist-tags":{"latest":"3.3.13","pre":"1.0.0"}}