New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ava-fixture

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ava-fixture

Write fixture tests with ava

0.6.0
Source
npm
Version published
Weekly downloads
27
2600%
Maintainers
1
Weekly downloads
 
Created
Source

ava-fixture

NPM version NPM downloads Build status Coverage Status

Helps you to easily write fixture tests with ava.

What is Fixture Test

Fixture tests are tests that require access to some files. The tests may write files and in that case the files can be compared with a baseline (i.e. Baseline Tests)

Usage

Assume you have the following folders:

+ fixtures
  + cases
    + case-1
      - something.txt
    + other-cases
  + baselines
    + case-1
      - something.txt
  + results # empty, not check into repository

When you only need to access files in each test case (i.e. don't need to perform baseline test):

import ava from 'ava';
import fixture from 'ava-fixture';

// Point to the base folder which contain the fixtures.
// Relative path starts from project root.
const ftest = fixture(ava, 'fixture/cases');

// You can also use absolute path.
// const ftest = fixture(ava, join(process.cwd(), 'fixture/cases'));

ftest('test title', 'case-1', (t) => {
  // t is ava test.
  // process.cwd() points to `case-1`

  // ...test away
});

// test title can be omitted
ftest('case-1', (t) => {
  // ...
})

When you want to perform baseline tests:

import test from 'ava';
import fixture from 'ava-fixture';

// Point to the base folder which contain the fixtures.
// Relative path starts from project root.
const btest = fixture(test, 'fixture/cases', 'fixture/baselines', 'fixture/results');

btest('test title', 'case-1', (t, d) => {
  // t is ava test.
  // process.cwd() points to `case-1`
  // d.casePath, d.baselinePath, d.resultPath points to respective folder for `case-1`
  // ...do tests

  // `d.match()` will check if the result folder has the same content as the baseline folder.
  return d.match()
});

// test title can be omitted
btest('case-1', (t) => {
  // ...
})

Other API

import test from 'ava';
import fixture from 'ava-fixture';

const ftest = fixture(test, 'fixture/cases');

ftest.only(...)
ftest.skip(...)

For before(), beforeEach(), after(), afterEach(), todo(), use ava directly.

Contribute

# right after clone
npm install

# begin making changes
git checkout -b <branch>
npm run watch

# edit `webpack.config.dev.js` to exclude dependencies for the global build.

# after making change(s)
git commit -m "<commit message>"
git push

# create PR

Npm Commands

There are a few useful commands you can use during development.

# Run tests (and lint) automatically whenever you save a file.
npm run watch

# Run tests with coverage stats (but won't fail you if coverage does not meet criteria)
npm run test

# Manually verify the project.
# This will be ran during 'npm preversion' so you normally don't need to run this yourself.
npm run verify

# Build the project.
# You normally don't need to do this.
npm run build

# Run tslint
# You normally don't need to do this as `npm run watch` and `npm version` will automatically run lint for you.
npm run lint

Generated by generator-unional@0.3.1

Keywords

ava

FAQs

Package last updated on 10 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts