• This repository has been archived on 21/Jul/2020
  • Stars
    star
    116
  • Rank 292,832 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

More Repositories

1

webpack-blocks

๐Ÿ“ฆ Configure webpack using functional feature blocks.
JavaScript
2,979
star
2

threads.js

๐Ÿงต Make web workers & worker threads as simple as a function call.
TypeScript
2,942
star
3

leakage

๐Ÿ› Memory leak testing for node.
JavaScript
1,583
star
4

pg-listen

๐Ÿ“ก PostgreSQL LISTEN & NOTIFY for node.js that finally works.
TypeScript
540
star
5

typed-emitter

๐Ÿ”ฉ Type-safe event emitter interface for TypeScript
JavaScript
250
star
6

use-inline-memo

โš›๏ธ React hook for memoizing values inline anywhere in a component
TypeScript
163
star
7

postguard

๐Ÿ› Statically validate Postgres SQL queries in JS / TS code and derive schemas.
TypeScript
161
star
8

laravel-js-localization

Simple, ease-to-use and flexible package for the Laravel web framework. Allows you to use localized messages of the Laravel webapp (see `resources/lang` directory) in your Javascript code.
PHP
143
star
9

squid

๐Ÿฆ‘ Provides SQL tagged template strings and schema definition functions.
TypeScript
124
star
10

postcss-debug

Debug your postcss workflow with ease! Creates snapshots of your CSS files before/after each postcss plugin is run.
JavaScript
94
star
11

react-usestyles

๐Ÿ– Style components using React hooks. Abstracts the styling library away.
JavaScript
87
star
12

postcss-theme

PostCSS plugin to enable versatile theming.
JavaScript
87
star
13

react-stateful-fn

โš› Stateful functional components for React.
JavaScript
57
star
14

puppet-run

๐Ÿค– Run anything JavaScript in a headless Chrome from your command line
TypeScript
53
star
15

threadpool-js

Javascript thread pool implementation using web workers.
JavaScript
47
star
16

jquery-dim-background

jQuery plugin to dim the current page except for some user-defined top elements.
JavaScript
43
star
17

observable-fns

๐Ÿ•ต๏ธโ€โ™€๏ธ Light-weight observable implementation and functional utilities in TypeScript
TypeScript
41
star
18

npm-launch

๐Ÿš€ Minimalistic task runner on steroids!
JavaScript
39
star
19

drag-mock

Trigger HTML5 drag & drop events for testing
JavaScript
35
star
20

gear

๐Ÿ›  Experimental tool to bootstrap typed JavaScript code.
JavaScript
33
star
21

proposal-double-colon-types

๐Ÿค“ JS / Flow syntax proposal. Types ร  la Hindley-Milner.
20
star
22

http-event-stream

๐Ÿ“ก Modern spec-compliant Server Sent Events stream implementation.
TypeScript
19
star
23

ts

โš™๏ธ The CLI that TypeScript deserves.
TypeScript
18
star
24

key-store

๐Ÿ” Isomorphic encrypted key store written in TypeScript.
TypeScript
17
star
25

plow

๐Ÿ‘จโ€๐ŸŒพ Postgres migrations and seeding made easy
TypeScript
14
star
26

isomorphic-crypto

๐Ÿ”’ Isomorphic crypto package for node and the browser.
JavaScript
12
star
27

type-reflect

โ˜๏ธ TypeScript plugin providing access to type information at runtime
TypeScript
11
star
28

srv

๐Ÿ“ก Functional node server. Composable routing. Take a request, return a response.
TypeScript
9
star
29

rungpt

GPT client with local plugin framework, built by GPT-4
TypeScript
9
star
30

php-easygit

Manage Git repositories from within your PHP webapp. Commit, branch, clone, checkout, ...
PHP
7
star
31

zaster

๐Ÿ’ธ Headless multi-blockchain wallet and SDK.
TypeScript
7
star
32

react-commandments

๐Ÿ“– Thou shalt honor thy reactive code and keep it holy.
6
star
33

koa-router-index

Koa v2 middleware to create an index page for API servers.
JavaScript
5
star
34

gulp-elixir-modules

Elixir extension for handling frontend modules easily.
JavaScript
5
star
35

json-sql-import

Small PHP tool to import JSON data into database tables using transformation rules.
PHP
4
star
36

puppet-run-plugins

๐Ÿงฉ Plugins for puppet-run.
TypeScript
4
star
37

shutter-legacy

๐Ÿ“ธ Visual snapshot testing with no effort.
TypeScript
3
star
38

deep-assert

๐Ÿ” Better deep-equals comparison, supporting custom property assertions and pretty diffs.
TypeScript
3
star
39

ideabox

Place to collect techy ideas and get feedback.
1
star
40

bundle-decomposition-research

JavaScript
1
star
41

stellar-wallet

With the new Stellar wallet to the moon ๐Ÿš€
JavaScript
1
star