Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Thinkmill/jest-fixtures

Use file system fixtures in Jest
https://github.com/Thinkmill/jest-fixtures

fixtures jest test

Last synced: about 2 months ago
JSON representation

Use file system fixtures in Jest

Awesome Lists containing this project

README

        

# jest-fixtures

> [WIP]

## Installation

```sh
yarn add --dev jest-fixtures
```

## API

##### `getFixturePath(cwd, ...fileParts)`

```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');
// ...
});
```

##### `getFixturePathSync(cwd, ...fileParts)`

```js
import {getFixturePathSync} from 'jest-fixtures';

test('example', () => {
let fixturePath = getFixturePathSync(__dirname, 'fixture-name');
let fixtureFilePath = getFixturePathSync(__dirname, 'fixture-name', 'file.txt');
// ...
});
```

##### `createTempDir()`

```js
import {createTempDir} from 'jest-fixtures';

test('example', async () => {
let tempDirPath = await createTempDir();
// ...
});
```

##### `createTempDirSync()`

```js
import {createTempDirSync} from 'jest-fixtures';

test('example', () => {
let tempDirPath = createTempDirSync();
// ...
});
```

##### `copyDir()`

```js
import {copyDir} from 'jest-fixtures';

test('example', async () => {
await copyDir('/path/to/source/dir', '/path/to/dest/dir');
// ...
});
```

##### `copyDirIntoTempDir()`

```js
import {copyDirIntoTempDir} from 'jest-fixtures';

test('example', async () => {
let tempDir = await copyDirIntoTempDir('/path/to/source/dir');
// ...
});
```

##### `copyFixtureIntoTempDir()`

```js
import {copyFixtureIntoTempDir} from 'jest-fixtures';

test('example', async () => {
let tempDir = await copyFixtureIntoTempDir(__dirname, 'fixture-name');
// ...
});
```

##### `cleanupTempDirs()`

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();
});
```