Warning
This package is deprecated and no longer maintained. Read fixtures with JSON.parse(await readFile(new URL('./fixtures/name.json', import.meta.url))) from node:fs/promises instead.
Tiny helper function to read JSON fixtures for tests
npm install @zentered/read-fixturesimport { test } from 'node:test'
import assert from 'node:assert/strict'
import readFixture from '@zentered/read-fixtures'
test('process events', async () => {
const mockData = await readFixture('log_stream.json')
assert.deepEqual(mockData, { hello: 'world' })
})| Argument | Default | Description |
|---|---|---|
name |
required | File name of the JSON fixture, for example log_stream.json. |
folder |
'fixtures' |
Folder under test/ that holds the file. |
Files resolve from process.cwd()/test/<folder>/<name>. Run tests from the project root so process.cwd() points there.
// reads test/custom/log_stream.json
const mockData = await readFixture('log_stream.json', 'custom')