{"name":"@tapjs/after","version":"3.3.4","keywords":["tapjs plugin"],"author":{"name":"Isaac Z. Schlueter"},"license":"BlueOak-1.0.0","_id":"@tapjs/after@3.3.4","maintainers":[{"name":"ljharb","email":"ljharb@gmail.com"},{"name":"isaacs","email":"i@izs.me"}],"homepage":"https://github.com/tapjs/tapjs/src/after#readme","bugs":{"url":"https://github.com/tapjs/tapjs/issues"},"tap":{"typecheck":false},"dist":{"shasum":"e26a7f5648524768645c206d22ef26077bbd0e94","tarball":"http://registry-npm.ywwl.com/@tapjs/after/download/@tapjs/after-3.3.4.tgz","fileCount":13,"integrity":"sha512-Y8DL0F9Ux6Swe7b5g4qLFgJUEFrVr5fhmVOENw4D/x7rDRyx/3c86Ya1p9iJrpkE2RnvdGq9AxR/rTM137Y7Lg==","signatures":[{"sig":"MEQCICWgTdiA1tqXQ+fQwe6a0iaCshklCMl6n/DVyoZ+CE36AiAkdSOKb5VzyEgcSGm4D7Fi8LHMmev79xZy0wq45XRwNQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18941,"size":4422,"noattachment":false,"key":"/@tapjs/after/-/@tapjs/after-3.3.4.tgz"},"main":"./dist/commonjs/index.js","tshy":{"main":true,"exports":{".":"./src/index.ts","./package.json":"./package.json"}},"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":"6f774b1133181e6062e2aca86596234c914cee4c","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.10.0","description":"a built-in tap extension for t.after() and t.teardown()","directories":{},"_nodeVersion":"25.6.1","dependencies":{"is-actual-promise":"^1.0.1"},"_hasShrinkwrap":false,"peerDependencies":{"@tapjs/core":"4.5.2"},"_npmOperationalInternal":{"tmp":"tmp/after_3.3.4_1771605312012_0.6318432922917092","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":1771605312162,"_cnpm_publish_time":1771605312162,"dist-tags":{"latest":"3.3.13","pre":"1.0.0"}}