# @tapjs/fixture

> Tap plugin to provide t.testdir() and t.fixture()

Latest version **4.3.12** (published 2026-09-03) · BlueOak-1.0.0 license · 0 weekly downloads

## Install

```sh
npm install @tapjs/fixture
pnpm add @tapjs/fixture
yarn add @tapjs/fixture
bun add @tapjs/fixture
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.3.12 |
| Published | 2026-09-03 |
| First published | 2023-08-04 |
| Weekly downloads | 0 |
| License | BlueOak-1.0.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | 20 \|\| >=22 |
| Dependencies | 2 |
| Unpacked size | 66.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2423 |
| Author | Isaac Z. Schlueter |
| Maintainers | ljharb, isaacs |
| Keywords | tapjs plugin |

## Links

- npm: https://www.npmjs.com/package/@tapjs/fixture
- Repository: https://github.com/tapjs/tapjs
- Homepage: https://github.com/tapjs/tapjs/tree/main/src/fixture#readme
- Issues: https://github.com/tapjs/tapjs/issues
- Funding: https://github.com/sponsors/isaacs
- npm.io page: https://npm.io/package/@tapjs/fixture

## Dependencies (2)

- [mkdirp](https://npm.io/package/mkdirp.md) ^3.0.0
- [rimraf](https://npm.io/package/rimraf.md) ^6.0.0

## Recent versions

- 4.3.12 (latest) — 2026-09-03
- 1.0.0 (pre) — 2023-09-15
- 4.3.11 — 2026-07-27
- 4.3.10 — 2026-05-15
- 4.3.9 — 2026-05-13
- 4.3.8 — 2026-05-01
- 4.3.7 — 2026-04-17
- 4.3.6 — 2026-04-15
- 4.3.5 — 2026-04-05
- 4.3.4 — 2026-02-20
- 4.3.3 — 2026-02-18
- 4.3.2 — 2026-02-18
- 4.3.1 — 2026-02-05
- 4.3.0 — 2025-12-01
- 4.2.1 — 2025-11-26
- … 75 more at https://npm.io/package/@tapjs/fixture/versions

## README

# `@tapjs/fixture`

A default tap plugin providing `t.testdir()` and `t.fixture()`
methods, for creating temporary directories with stuff for tests
to operate on.

Fixtures created with this plugin live folders under
`./.tap/fixtures`, in the root of the project. The folder name is
based on the name of the test file, and the name of the test.

For example, if a file at `./src/foo.test.mjs` had this:

```js
import t from 'tap'
t.test('child test', async t => {
  t.testdir({ file: 'contents' })
})
```

Then a file would be created at
`.tap/fixtures/src-foo.test.mjs-child-test/file` containing
`'contents'`.

## USAGE

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

### `t.testdir(contents?: FixtureDirContent): string`

Create a directory with some stuff in it.

If no contents provided, just creates an empty directory.

```ts
import t from 'tap'
import { lstatSync } from 'node:fs'

t.test('subtest that has a test directory', t => {
  const dir = t.testdir({
    // objects are subdirectories
    subdir: {
      // strings or buffers are files
      'file.txt': 'some contents',
      // to create links or symlinks, use the t.fixture() method
      symlink: t.fixture('symlink', 'file.txt'),
      hardlink: t.fixture('link', 'file.txt'),
    },
  })
  t.equal(lstatSync(dir + '/subdir/symlink').isSymbolicLink(), true)
  t.end()
})
// dir removed when test ends
```

If you do not provide a contents argument, then it will create an
empty directory.

Though it's called `t.testdir()` you can actually use it to
create files or links as well.

```ts
import t from 'tap'
import { readFileSync } from 'node:fs'
t.test('test "dir" is actually file', t => {
  const file = t.testdir('file contents')
  t.equal(readFileSync(file, 'utf8'), 'file contents')
  t.end()
})
```

### `t.testdirName: string`

This is a string that gives you the string path that
`t.testdir()` will write to.

### `saveFixture` test option, `t.saveFixture: boolean`

If set to `true`, then the test will not delete its fixtures when
it finishes.

If set on the test object, this must be set _before_ calling
`t.testdir()`, or it won't have any effect, since the deletion is
scheduled at the moment it's created.

---
_Source: https://npm.io/package/@tapjs/fixture · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
