Giter VIP home page Giter VIP logo

ava-spec's Introduction

DEPRECATED Please use Jest which is more powerful than Ava and supports describe out of the box.

AVA Spec

Build Status

Installation

AVA Spec is meant to be installed next to AVA, so please follow its installation instructions first.

Then, install ava-spec as a development dependency:

$ npm install --save-dev ava-spec

You still run tests with ava command. The only thing that changes are tests themselves.

Usage

First of all, you can use ava-spec as a drop-in for ava:

import test from 'ava-spec';

test('AVA Spec is 100% compatible with ava', t => {
  t.is(true, true);
});

Jasmine-like DSL is supported:

import {describe} from 'ava-spec';

describe('AVA Spec', it => {
  it('can look almost like jasmine', t => {
    t.deepEqual([1, 2], [1, 2]);
  });

  it.todo('supports all chaining modifiers!');
});

Or write cucumber-like scenarios:

import {feature} from 'ava-spec';

feature('Cash withdrawal.', scenario => {
  scenario('Not enough money in ATM', t => {
    // Cucumber-like keywords are available
  });
});

Or just group tests together:

test.serial.skip.group(test => {
  test('AVA Spec can be used to just group some tests', t => {
    t.not(true, false);
  });
});

Last but not least you can pass groups around in fun ways:

const subject = test.describe('You');

subject('do not need to use callbacks!', t => {
  t.is(2 + 2, 4);
});

Result:

  - AVA Spec can be used to just group some tests
  ✔ AVA Spec is 100% compatible with ava
  ✔ AVA Spec can look almost like jasmine
  - AVA Spec supports all chaining modifiers!
  ✔ Cash withdrawal. Not enough money in ATM
  ✔ You do not need to use callbacks!

  4 tests passed
  1 test skipped
  1 test todo

API

AVA spec allows you to define test groups using 3 equivalent methods:

test.describe([title], implementation)

test.feature([title], implementation)

test.group([title], implementation)

title

Type: string

A group title.

implementation(ava)

Type: function

It is called by AVA Spec with modified AVA instance as so:

  1. Group modifiers are applied to all tests inside it
  2. Group title is prefixed to all test titles inside it

Caveats

Currently AVA Spec doesn't support per-group hooks.

Team

Adam Stankiewicz Please help me!
Adam Stankiewicz Become co-author!

ava-spec's People

Contributors

bensower avatar jrolfs avatar sheerun avatar tjbenton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ava-spec's Issues

Feature request, support per-group hooks.

Support per-group hooks.
It most important functionality for "described-it" style of the tests.
Are you still planning to develop this functionality in ava-spec?

Nested async describes don't register tests

If I have a nested async describe, AVA doesn't recognize there being any tests. Here's an example.

import { describe } from 'ava-spec';
import fs from 'mz/fs';

describe('describe async', async it => {
  const dir1 = await fs.readdir('.');
  console.log(dir1);

  // I've tried this next line with and without `await` in front of it.
  it.describe('level two', async it => {
    const dir2 = await fs.readdir('.');
    console.log(dir2);

    // I've also tried this next line with and without `await` in front of it.
    it('to be registered', t => {
      t.is(1, 1);
    });
  });
});

Here's what I get with npm test

npm test

> [email protected] test /Users/me/code/bug-demo
> ava

[ '.DS_Store',
  '.editorconfig',
  '.eslintignore',
  '.eslintrc.js',
  '.git',
  '.gitignore',
  '.npmrc',
  'expectations',
  'node_modules',
  'package.json',
  'test.js' ]
[ '.DS_Store',
  '.editorconfig',
  '.eslintignore',
  '.eslintrc.js',
  '.git',
  '.gitignore',
  '.npmrc',
  'expectations',
  'node_modules',
  'package.json',
  'test.js' ]

  1 exception

  ✖ No tests found in test.js
npm ERR! Test failed.  See above for more details.

and with node --inspect node_modules/ava/profile.js test.js

Debugger listening on ws://127.0.0.1:9229/563cfe58-5793-4ab1-b198-1cebd2f9cb02
For help see https://nodejs.org/en/docs/inspector
UNHANDLED AVA EVENT: no-tests { avaRequired: true }
[ '.DS_Store',
  '.editorconfig',
  '.eslintignore',
  '.eslintrc.js',
  '.git',
  '.gitignore',
  '.npmrc',
  'expectations',
  'node_modules',
  'package.json',
  'test.js' ]
[ '.DS_Store',
  '.editorconfig',
  '.eslintignore',
  '.eslintrc.js',
  '.git',
  '.gitignore',
  '.npmrc',
  'expectations',
  'node_modules',
  'package.json',
  'test.js' ]

How can I make it aware of the assertion/test?

only is not working.

I want to run just single test case, so I wrote a test using "it.only" but it does not work. Is not it implemented yet?

Reusable tests

What would be really very useful is if ava-spec enabled tests to be held in an ava helper directory and somehow included into test files where the contained tests could be invoked.

So in a helper file you would have something like:

var reusableTest2 = test.serial('Ava spec enables reusable tests', async t => {
  t.is(2 + 3, 5);
});
var reusableTest2 = test.serial('Ava spec enables reusable tests', async t => {
  t.is(2 + 2, 4);
});

Then in another Ava test file:

test.serial.group('Reused tests', test => {

  reusableTest1();

  reusableTest2();
});

Obviously the above would not work as it is but, hopefully it illustrates the idea?

Broken contract for ava macos

It looks to me like test macros are broken inside describe functions. Currently test functions passed to a macro result in an argument of type object. I'll update this with examples when I am not on a mobile connection.

Breaks with AVA 0.15.1

I'm planning on looking into this and hopefully opening a PR, but after upgrading AVA in my project that uses ava-spec I'm getting the following error:

[my-project]/node_modules/ava/lib/runner.js:101
                if (fn.title) {
                      ^

TypeError: Cannot read property 'title' of null
    at Runner._addTest ([my-project]/node_modules/ava/lib/runner.js:101:9)
    at Runner.<anonymous> ([my-project]/node_modules/ava/lib/runner.js:89:8)
    at Function.wrappedFn ([my-project]/node_modules/option-chain/index.js:36:14)
    at Function.<anonymous> ([my-project]/node_modules/ava-spec/lib/index.js:91:19)
    at Function.wrappedFn ([my-project]/node_modules/option-chain/index.js:36:14)
    at Object.<anonymous> ([my-project]/test/mixins/event-emitter.test.js:10:6)
    at Module._compile (module.js:541:32)
    at extensions.(anonymous function) ([my-project]/node_modules/require-precompiled/index.js:13:11)
    at Object.require.extensions.(anonymous function) [as .js] ([my-project]/node_modules/ava/lib/test-worker.js:91:3)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> ([my-project]/node_modules/ava/lib/test-worker.js:95:1)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Function.Module.runMain (module.js:575:10)
    at startup (node.js:160:18)
    at node.js:449:3

My first guess is possibly some sort of conflict with the Macro support that was introduced? It looks like the tests in this project don't actually run against AVA, maybe we should consider doing so to catch these sorts of things?

Feature request: have ava-spec load ava itself.

I get the no-unused-vars error from XO/ESlint when using the define spec.

screen shot 2018-03-11 at 1 12 52 am

screen shot 2018-03-11 at 1 14 13 am

If I do not import ava, eg:

// import test from 'ava'
import {define} from 'ava-spec'

define('my feature', it => {
	it('should work', t => {
		t.pass()
	})
})

...then I get the follow console error when running ava.

/Users/al/repos/markdown-renderer/lib/parser.test.js:5
(0, _avaSpec.define)('my feature', it => {
                    ^

TypeError: (0 , _avaSpec.define) is not a function
    at Object.<anonymous> (/Users/al/repos/markdown-renderer/lib/parser.test.js:4:1)
    at Module._compile (module.js:662:30)
    at Module.replacementCompile (/Users/al/repos/markdown-renderer/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at extensions.(anonymous function) (/Users/al/repos/markdown-renderer/node_modules/require-precompiled/index.js:13:11)
    at /Users/al/repos/markdown-renderer/node_modules/nyc/node_modules/append-transform/index.js:62:4
    at require.extensions.(anonymous function) (/Users/al/repos/markdown-renderer/node_modules/ava/lib/process-adapter.js:100:4)
    at Object.<anonymous> (/Users/al/repos/markdown-renderer/node_modules/nyc/node_modules/append-transform/index.js:62:4)
    at Module.load (module.js:575:32)
    at tryModuleLoad (module.js:515:12)
    at Function.Module._load (module.js:507:3)
    at Module.require (module.js:606:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/al/repos/markdown-renderer/node_modules/ava/lib/test-worker.js:62:1)
    at Module._compile (module.js:662:30)
    at Module.replacementCompile (/Users/al/repos/markdown-renderer/node_modules/nyc/node_modules/append-transform/index.js:58:13)
    at module.exports (/Users/al/repos/markdown-renderer/node_modules/nyc/node_modules/default-require-extensions/js.js:8:9)

It would be nice if ava-spec loaded ava itself internally so I would not have to put disable-eslint rules in front of each import of ava. Doing this for all tests across a codebase seems like a lot of grunt work.

`.only` and `.skip` support

first of all, thank you for ava-spec lib.

.only and .skip are useful and supported by ava, but couldnt get ava-spec to work with it.
what do you thinkg?

No 'describe' output in reporter

Hi there, firstly thanks for this library. It's a great add-on for Ava and I am finding it useful for converting mocha tests.

I'm expecting to see grouped reports like I do in mocha, eg:

Some feature
 - Test 1
 - Test 2
 - Test 3

There is no output of the text passed as the first argument to describe.

import {describe} from 'ava-spec'
describe('This is not output to the reporter', it => {
  it('...but this is output', t => {
    t.pass()
  })
})

Note: I am executing the tests with the verbose reporter:

ava lib/**/*.spec.js --verbose

Am I doing something wrong? Should I expect to see describe text output in the reporter?

Full gherkin spec still missing (or undocumented)

Was having a look at using an xSpec (Jasmine-like) or xBehave (cucumber-like, AKA Gherkin) and noticed I wasn't able to use classic Gherkin keywords such as When/Then/And (to name a few of the most critical).

I had a look at the source code, but there's no mention to those keywords ("scenario" is also not listed, and seems to be just a naming convention for the first argument on the "feature" keyword), so my guess is that this is not implemented at all.

A full-blown cucumber-like syntax will probably be complex, so for the short term the most realistic thing to do is to remove that part of the readme and, if the effort seems worth it, put this in the backlog (more than happy to contribute a PR or two to help with that...).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.