Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including jest-fixtures with all npm packages installed. Try it out:

var jestFixtures = require("jest-fixtures")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

jest-fixtures v0.6.0

Use file system fixtures in Jest

jest-fixtures

[WIP]

Installation

yarn add --dev jest-fixtures

API

getFixturePath(cwd, ...fileParts)
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)
import {getFixturePathSync} from 'jest-fixtures';

test('example', () => {
  let fixturePath = getFixturePathSync(__dirname, 'fixture-name');
  let fixtureFilePath = getFixturePathSync(__dirname, 'fixture-name', 'file.txt');
  // ...
});
createTempDir()
import {createTempDir} from 'jest-fixtures';

test('example', async () => {
  let tempDirPath = await createTempDir();
  // ...
});
createTempDirSync()
import {createTempDirSync} from 'jest-fixtures';

test('example', () => {
  let tempDirPath = createTempDirSync();
  // ...
});
copyDir()
import {copyDir} from 'jest-fixtures';

test('example', async () => {
  await copyDir('/path/to/source/dir', '/path/to/dest/dir');
  // ...
});
copyDirIntoTempDir()
import {copyDirIntoTempDir} from 'jest-fixtures';

test('example', async () => {
  let tempDir = await copyDirIntoTempDir('/path/to/source/dir');
  // ...
});
copyFixtureIntoTempDir()
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.

import {createTempDir, cleanupTempDirs} from 'jest-fixtures';

test('example', async () => {
  await createTempDir();
  await createTempDir();
  cleanupTempDirs();
});

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free