jest-fixtures
Version:
Use file system fixtures in Jest
164 lines (119 loc) • 3.11 kB
Markdown
> [WIP]
```sh
yarn add --dev jest-fixtures
```
```js
import {getFixturePath} from 'jest-fixtures';
test('example', async () => {
let fixturePath = await getFixturePath(__dirname, 'fixture-name');
let fixtureFilePath = await getFixturePath(__dirname, 'fixture-name', 'file.txt');
// ...
});
```
```js
import {getFixturePathSync} from 'jest-fixtures';
test('example', () => {
let fixturePath = getFixturePathSync(__dirname, 'fixture-name');
let fixtureFilePath = getFixturePathSync(__dirname, 'fixture-name', 'file.txt');
// ...
});
```
```js
import {createTempDir} from 'jest-fixtures';
test('example', async () => {
let tempDirPath = await createTempDir();
// ...
});
```
```js
import {createTempDirSync} from 'jest-fixtures';
test('example', () => {
let tempDirPath = createTempDirSync();
// ...
});
```
```js
import {copyDir} from 'jest-fixtures';
test('example', async () => {
await copyDir('/path/to/source/dir', '/path/to/dest/dir');
// ...
});
```
```js
import {copyDirIntoTempDir} from 'jest-fixtures';
test('example', async () => {
let tempDir = await copyDirIntoTempDir('/path/to/source/dir');
// ...
});
```
```js
import {copyFixtureIntoTempDir} from 'jest-fixtures';
test('example', async () => {
let tempDir = await copyFixtureIntoTempDir(__dirname, 'fixture-name');
// ...
});
```
Deletes every temporary directory created by `jest-fixtures`. This is called
automatically when the Jest process exits.
```js
import {createTempDir, cleanupTempDirs} from 'jest-fixtures';
test('example', async () => {
await createTempDir();
await createTempDir();
cleanupTempDirs();
});
```
<!--
```js
import {getFixturePath, loadFixture} from 'jest-fixtures';
test('example', async () => {
let fixturePath = await getFixturePath(__dirname, 'foo');
let fixture = await loadFixture(fixturePath);
// ...
});
```
```js
import {getFixturePathSync, loadFixtureSync} from 'jest-fixtures';
test('example', () => {
let fixturePath = getFixturePathSync(__dirname, 'foo');
let fixture = loadFixtureSync(fixturePath);
// ...
});
```
```js
// __mocks__/fs.js
import {createFsMock} from 'jest-fixtures';
module.exports = createFsMock();
```
```js
// __mocks__/fs.js
import {createFsMock} from 'jest-fixtures';
module.exports = createFsMock();
```
```js
import {getFixturePath, loadFixture} from 'jest-fixtures';
import * as fs from 'fs';
jest.mock('fs');
test('example', async () => {
let fixturePath = await getFixturePath(__dirname, 'foo');
let fixture = await loadFixture(fixturePath);
fs.__setFixture__(fixture);
// ...
});
```
-->