# @natlibfi/fixugen

> Generate Node.js unit tests from fixtures and callbacks

Latest version **4.0.0** (published 2026-09-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @natlibfi/fixugen
pnpm add @natlibfi/fixugen
yarn add @natlibfi/fixugen
bun add @natlibfi/fixugen
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2026-09-28 |
| First published | 2020-06-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=24 |
| Dependencies | 1 |
| Unpacked size | 36.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | The National Library of Finland |
| Maintainers | drone-melinda, natlibfi-jonollil |

## Links

- npm: https://www.npmjs.com/package/@natlibfi/fixugen
- Repository: https://github.com/NatLibFi/fixugen-js
- Homepage: https://www.npmjs.com/package/@natlibfi/fixugen
- Issues: https://github.com/natlibfi/fixugen-js/issues
- npm.io page: https://npm.io/package/@natlibfi/fixugen

## Dependencies (1)

- [@natlibfi/fixura](https://npm.io/package/@natlibfi/fixura.md) ^5.0.0

## Recent versions

- 4.0.0 (latest) — 2026-09-28
- 4.0.0-alpha.4 (next) — 2026-07-07
- 4.0.0-alpha.3 — 2026-07-07
- 4.0.0-alpha.2 — 2026-05-13
- 4.0.0-alpha.1 — 2026-04-14
- 3.0.1 — 2026-03-05
- 3.0.1-alpha.1 — 2026-03-05
- 3.0.0 — 2025-11-05
- 3.0.0-alpha.7 — 2025-10-22
- 3.0.0-alpha.6 — 2025-08-29
- 3.0.0-alpha.5 — 2025-07-14
- 3.0.0-alpha.4 — 2025-07-10
- 3.0.0-alpha.3 — 2025-07-10
- 3.0.0-alpha.1 — 2025-07-09
- 2.0.15 — 2025-06-26
- … 43 more at https://npm.io/package/@natlibfi/fixugen/versions

## README

# Generate Node.js unit tests from fixtures and callbacks
[![NPM Version](https://img.shields.io/npm/v/@natlibfi/fixugen.svg)](https://npmjs.org/package/@natlibfi/fixugen) [![Node Version](https://img.shields.io/node/v/@natlibfi/fixugen.svg)]()

Provides test callbacks with [Fixura's](https://www.npmjs.com/package/@natlibfi/fixura) functions to fetch test fixtures.

## Usage
The test fixture directory is parsed as follows: Each subdirectory becomes a unit test group (node:test's `describe`) and inner subdirectories each represent individual tests (node:test's `it`). For custom test variables see metadata example.

```js
import generateTests from '@natlibfi/fixugen';
import {dirname} from 'node:path';
import {fileURLToPath} from 'node:url';

const __dirname = dirname(fileURLToPath(import.meta.url));

generateTests({
  callback,
  path: [__dirname, '..', 'test-fixtures']
});

function callback({getFixture, custom}) {
  const expectedValue = getFixture('value.txt');
  const value = generateSomething(custom);
  expect(value).to.equal(expectedValue);
}
```

### Options
- **callback**: A callback function passed to node:test's `it`. Receives Fixura's function as arguments.
  - **dirName**: callback gets dirName variable that is one folder up
- **path**: An array of path components which make up a path to the test fixtures directory
- **recurse**: Whether to recurse into the subdirectories of **path**. If `false` the last directory of the path is used as the name of the node:test's describe-call and it's direct subdirectories are used as unit test directories. Defaults to **true**
- **fixura**: Options that are passed to Fixura.
- **useMetadataFile**: If set to true, reads and parses a file named `metadata.json` in each unit test directory. The content must be a JSON object and it's properties as passed to the unit test callback function.
  - If a property `description` is present, it is used as the test's description (Defaults to *false* and folder name is used).
  - If a property `skip` is present, it decides if test is skipped (Defaults to *false*).
  - If a property `only` is present, it decides if this/these tests are only run (Defaults to *false*).
- **hooks**: An object which maps the following properties to node:test's corresponding callbacks: **after**, **before**, **afterEach**, **beforeEach**

### Example metadata.json
```json
{
  "description": "Example description of test",
  "skip": false,
  "only": false,
  "custom": "Custom variable delivered for test"
}
```

## License and copyright

Copyright (c) 2020, 2023-2026 **University Of Helsinki (The National Library Of Finland)**

This project's source code is licensed under the terms of **MIT** or any later version.

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