Giter VIP home page Giter VIP logo

ava-ts's Introduction

AVA-TS

Build Status NPM Version

Native TypeScript support for sindresorhus' awesome AVA test runner out of the box, without a prior build step.

๐Ÿš€ Zero-configuration setup
โฉ Parallel test execution
๐Ÿ–ผ Snapshot testing
๐Ÿ“ˆ All your favorite reporters

This is a fork of the official AVA repository with a couple of minimally invasive changes. Uses ts-node/register instead of Babel. Not the cleanest solution, but it works well.

Installation

npm install --save-dev ava-ts ava ts-node

# Using yarn:
yarn add --dev ava-ts ava ts-node

Usage

Write your tests in TypeScript as you would usually do and import from ava, not from ava-ts, just as you would always do.

// test.ts

import test from 'ava'

test('one plus two equals three', t => {
  t.is(1 + 2, 3)
})

Instead of running ava, just run the ava-ts CLI tool instead. That's it!

It will use all the same options and defaults you know from AVA, but searches for *.ts files instead of *.js.

$ ava-ts --help

  Fork of the AVA test runner with native typescript support ๐Ÿš€

  Usage
    ava-ts [<file|directory|glob> ...]

  Options
    --init                  Add AVA to your project
    --fail-fast             Stop after first test failure
    --serial, -s            Run tests serially
    --tap, -t               Generate TAP output
    --verbose, -v           Enable verbose output
    --color                 Force color output
    --no-color              Disable color output
    --match, -m             Only run tests with matching title (Can be repeated)
    --watch, -w             Re-run tests when tests and source files change
    --timeout, -T           Set global timeout
    --concurrency, -c       Max number of test files running at the same time (Default: CPU cores)
    --update-snapshots, -u  Update snapshots

  Examples
    ava-ts
    ava-ts test.ts test2.ts
    ava-ts test-*.ts
    ava-ts test
    ava-ts --init
    ava-ts --init foo.ts

  Default patterns when no arguments:
  test.ts test.tsx test-*.ts test-*.tsx test/**/*.ts test/**/*.tsx **/__tests__/**/*.ts **/__tests__/**/*.tsx **/*.test.ts **/*.test.tsx

Documentation

See AVA's official docs for detailed information.

test.before() registers a hook to be run before the first test in your test file. Similarly test.after() registers a hook to be run after the last test. Use test.after.always() to register a hook that will always run once your tests and other hooks complete. .always() hooks run regardless of whether there were earlier failures or if all tests were skipped, so they are ideal for cleanup tasks. There are two exceptions to this however. If you use --fail-fast AVA will stop testing as soon as a failure occurs, and it won't run any hooks including the .always() hooks. Uncaught exceptions will crash your tests, possibly preventing .always() hooks from running. If a test is skipped with the .skip modifier, the respective .beforeEach() and .afterEach() hooks are not run. Likewise, if all tests in a test file are skipped .before() and .after() hooks for the file are not run. Hooks modified with .always() will always run, even if all tests are skipped.

Limitations

There are a few limitations compared to the original ava CLI.

  • No babel support
  • No power assert

Frequently Asked Questions

How to use AVA-TS when the module compiler option is set to ES6 modules?

Especially when working with bundlers like webpack you will encounter this issue. Fortunately, there is a simple fix to make TypeScript emit node-style modules when running AVA-TS:

TS_NODE_COMPILER_OPTIONS='{"module":"commonjs"}' ava-ts

On Windows:

set TS_NODE_COMPILER_OPTIONS={\"module\":\"commonjs\"} && ava-ts

If you feel this use case needs to be improved, complain in #5 ๐Ÿ˜‰

License

MIT. The fork as well as the original. AVA is a project of always awesome Sindre Sorhus.

ava-ts's People

Contributors

andywer avatar anoff avatar ariporad avatar cgcgbcbc avatar codeslikejaggars avatar floatdrop avatar fluffywaffles avatar forresst avatar ivogabe avatar jamestalmage avatar jfmengels avatar jokeyrhyme avatar kasperlewau avatar kevva avatar lasalefamine avatar leebyron avatar lukechilds avatar mightyiam avatar nfcampos avatar novemberborn avatar ntwb avatar pine avatar samverschueren avatar silvenon avatar sindresorhus avatar sotojuan avatar thomasbem avatar timdeschryver avatar twada avatar yatharthx 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-ts's Issues

Clean Stack Traces

Ava has a great feature of clean stack traces that ava-ts seems to be missing out on

Ava

  Config โ€บ register

  /Users/derenge/WebstormProjects/fado/src/actions/Config.test.ts:4

   3: test('register', (t) => {
   4:     t.is(1, 2)           
   5: })                       

  Difference:

  - 1
  + 2

Ava-ts

  Config.ts โ€บ register

  /Users/derenge/WebstormProjects/fado/node_modules/ava-ts/lib/assert.js:102

  Difference:

  - 1
  + 2

  ExecutionContext.is (node_modules/ava-ts/lib/assert.js:102:17)
  Test.ava_1.test [as fn] (src/actions/Config.test.ts:4:7)
  Test.callFn (node_modules/ava-ts/lib/test.js:306:18)
  Test.run (node_modules/ava-ts/lib/test.js:319:23)
  runNext (node_modules/ava-ts/lib/sequence.js:58:44)
  Sequence.run (node_modules/ava-ts/lib/sequence.js:90:10)
  Concurrent.run (node_modules/ava-ts/lib/concurrent.js:41:37)
  runNext (node_modules/ava-ts/lib/sequence.js:58:44)
  Sequence.run (node_modules/ava-ts/lib/sequence.js:90:10)
  runNext (node_modules/ava-ts/lib/sequence.js:58:44)
  Sequence.run (node_modules/ava-ts/lib/sequence.js:90:10)
  Bluebird.try (node_modules/ava-ts/lib/runner.js:224:48)
  Runner.run (node_modules/ava-ts/lib/runner.js:224:22)
  process.on.options (node_modules/ava-ts/lib/main.js:84:10)
  process.emit (node_modules/source-map-support/source-map-support.js:452:21)
  process.on.message (node_modules/ava-ts/lib/process-adapter.js:14:10)
  process.emit (node_modules/source-map-support/source-map-support.js:452:21)

Is this a setup issue with source maps on my end?

ts-node peer dependency

Hello,

I am looking to use this in a few projects that keep dependencies up to date with greenkeeper. As such, I would like to use the latest version of ts-node. ava-ts has a peer dependency on ts-node@^3.0.0. Is an update to target the latest version possible? I have tried installing the latest version and everything seems to work, but I may be missing things since I am unfamiliar with how everything ties together.

Thanks
Gerrit

Support *.tsx

Although *.ts files seem to run perfectly well, I'm having trouble getting *.tsx files to be recognised.

With ava-ts **/*.test.{ts,tsx} it claims it cannot find any *.tsx files, but finds an abundance of *.ts files and runs them successfully. I've tried renaming my .tsx files to .ts, and although ava-ts then finds them, it fails to compile โ€” potentially because they now have an incorrect extension, or it may be an additional issue to resolve.

Do you have any examples of how to add support for .tsx?

Coverage with NYC

I deleted the template because I have a simple question: how do I output coverage with ava-ts?

Should test failure line numbers be accurate?

Thanks so much for creating ava-ts - it's been really helpful in my projects. I've noticed, however, that wherever ava would normally output line numbers where a test failed, I get completely unrelated code:

  2 tests failed

  rooms.ts โ€บ validates room sizes

  /mnt/c/Users/Jack/git/sl-tethers/src/rooms.ts:79

   78:   };
   79:   rules: {         
   80:     rounds: number;

  Rejected promise returned by test. Reason:

  Error (BadRequest) {
    status: 400,
    message: 'You need to pick a room size.',
  }

As you can see from the example, I'm throwing an error within a function, but the highlighted output actually points to a unrelated interface declaration.

Is this a known problem? Do sourcemaps work with ava-ts?

Unexpected token import on require file

Description

When I use the ava config below, require file cannot be transpiled.

Test Source (setup-test-env.ts)

import {configure} from "enzyme";
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });

Error Message & Stack Trace

(function (exports, require, module, __filename, __dirname) { import {configure} from "enzyme";
                                                              ^^^^^^

SyntaxError: Unexpected token import

Config

Copy the relevant section from package.json:

{
  "ava": {
    "require": [
      "./test/setup-test-env.ts"
    ]
  }
}

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.