Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: avajs/ava
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.3.1
Choose a base ref
...
head repository: avajs/ava
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.4.0
Choose a head ref
  • 7 commits
  • 38 files changed
  • 6 contributors

Commits on Mar 17, 2019

  1. Print commands in watch mode

    Stanisław Jaros authored and novemberborn committed Mar 17, 2019

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    cd256ac View commit details
  2. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    99a10a1 View commit details
  3. 1

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    23e302a View commit details

Commits on Mar 18, 2019

  1. Shim all tty methods

    oantoro authored and novemberborn committed Mar 18, 2019

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    c1f6fdf View commit details

Commits on Mar 24, 2019

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    9406470 View commit details
  2. Bump dependencies

    novemberborn authored Mar 24, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0154a7f View commit details
  3. 1.4.0

    novemberborn committed Mar 24, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    novemberborn Mark Wubben
    Copy the full SHA
    20db474 View commit details
Showing with 458 additions and 255 deletions.
  1. +1 −1 .travis.yml
  2. +35 −7 docs/03-assertions.md
  3. +2 −2 docs/06-configuration.md
  4. +2 −2 docs/07-test-timeouts.md
  5. +2 −2 docs/08-common-pitfalls.md
  6. +1 −1 docs/recipes/flow.md
  7. +1 −1 docs/recipes/typescript.md
  8. +54 −25 lib/assert.js
  9. +1 −6 lib/enhance-assert.js
  10. +1 −1 lib/run-status.js
  11. +3 −0 lib/watcher.js
  12. +22 −0 lib/worker/fake-tty.js
  13. BIN media/magic-assert-combined.png
  14. BIN media/magic-assert-nested.png
  15. BIN media/power-assert.png
  16. +0 −11 media/screenshot-fixtures/magic-assert-nested.js
  17. +11 −0 media/screenshot-fixtures/package.json
  18. +8 −0 media/screenshot-fixtures/power-assert.js
  19. +189 −149 package-lock.json
  20. +16 −16 package.json
  21. +2 −1 test/api.js
  22. +28 −0 test/assert.js
  23. +3 −3 test/fixture/enhanced-assertion-formatting.js
  24. +1 −1 test/fixture/just-enhancement-compilation/custom-extension/power-assert.foo
  25. +1 −1 test/fixture/just-enhancement-compilation/power-assert.js
  26. +1 −1 test/fixture/no-babel-compilation/no-power-assert.js
  27. +2 −2 test/fixture/report/regular/test.js
  28. +15 −0 test/fixture/report/timeoutwithmatch/a.js
  29. +1 −0 test/fixture/report/timeoutwithmatch/package.json
  30. +5 −0 test/fixture/tty/is-tty.js
  31. +3 −2 test/helper/report.js
  32. +3 −1 test/integration/watcher.js
  33. +6 −6 test/reporters/mini.regular.log
  34. +4 −4 test/reporters/tap.regular.log
  35. +1 −0 test/reporters/verbose.js
  36. +6 −6 test/reporters/verbose.regular.log
  37. +17 −0 test/reporters/verbose.timeoutwithmatch.log
  38. +10 −3 test/watcher.js
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ matrix:
- node_js: 6
os: windows # npm install --global currently fails on Windows. Skip the tests entirely instead.
cache: npm
before_install: if [[ "$(npm -v)" != "6.6.0" ]] && [[ "${TRAVIS_OS_NAME}" != "windows" ]]; then npm install --global npm@6.6.0; fi
before_install: if [[ "$(npm -v)" != "6.9.0" ]] && [[ "${TRAVIS_OS_NAME}" != "windows" ]]; then npm install --global npm@6.9.0; fi
install: npm ci
before_script: |
if [[ ${FRESH_DEPS} == "true" ]]; then
42 changes: 35 additions & 7 deletions docs/03-assertions.md
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ test('skip assertion', t => {

## Enhanced assertion messages

AVA comes with [`power-assert`](https://github.com/power-assert-js/power-assert) built-in, giving you more descriptive assertion messages. It reads your test and tries to infer more information from the code.
AVA comes with [`power-assert`](https://github.com/power-assert-js/power-assert) built-in, giving you more descriptive assertion messages.

Let's take this example, using Node's standard [`assert` library](https://nodejs.org/api/assert.html):

@@ -101,24 +101,48 @@ If you paste that into a Node REPL it'll return:
AssertionError: false == true
```

In AVA however, this test:
With AVA's `assert` assertion however, this test:

```js
test('enhanced assertions', t => {
const a = /foo/;
const b = 'bar';
const c = 'baz';
t.true(a.test(b) || b === c);
t.assert(a.test(b) || b === c);
});
```

Will output:

```
t.true(a.test(b) || b === c)
| | | |
| "bar" "bar" "baz"
false
6: const c = 'baz';
7: t.assert(a.test(b) || b === c);
8: });
Value is not truthy:
false
a.test(b) || b === c
=> false
b === c
=> false
c
=> 'baz'
b
=> 'bar'
a.test(b)
=> false
b
=> 'bar'
a
=> /foo/
```

## Custom assertions
@@ -147,6 +171,10 @@ Passing assertion.

Failing assertion.

### `.assert(value, [message])`

Asserts that `value` is truthy. This is [`power-assert`](#enhanced-assertion-messages) enabled.

### `.truthy(value, [message])`

Assert that `value` is truthy.
4 changes: 2 additions & 2 deletions docs/06-configuration.md
Original file line number Diff line number Diff line change
@@ -57,8 +57,8 @@ Arguments passed to the CLI will always take precedence over the CLI options con
- `tap`: if `true`, enables the [TAP reporter](./05-command-line.md#tap-reporter)
- `verbose`: if `true`, enables verbose output
- `snapshotDir`: specifies a fixed location for storing snapshot files. Use this if your snapshots are ending up in the wrong location
- `compileEnhancements`: if `false`, disables [power-assert](https://github.com/power-assert-js/power-assert) — which otherwise helps provide more descriptive error messages — and detection of improper use of the `t.throws()` assertion
- `extensions`: extensions of test files that are not precompiled using AVA's Babel presets. Note that files are still compiled to enable power-assert and other features, so you may also need to set `compileEnhancements` to `false` if your files are not valid JavaScript. Setting this overrides the default `"js"` value, so make sure to include that extension in the list, as long as it's not included in `babel.extensions`
- `compileEnhancements`: if `false`, disables [`power-assert`](./03-assertions.md#enhanced-assertion-messages) — which otherwise helps provide more descriptive error messages — and detection of improper use of the `t.throws()` assertion
- `extensions`: extensions of test files that are not precompiled using AVA's Babel presets. Note that files are still compiled to enable `power-assert` and other features, so you may also need to set `compileEnhancements` to `false` if your files are not valid JavaScript. Setting this overrides the default `"js"` value, so make sure to include that extension in the list, as long as it's not included in `babel.extensions`
- `require`: extra modules to require before tests are run. Modules are required in the [worker processes](./01-writing-tests.md#process-isolation)
- `babel`: test file specific Babel options. See our [Babel recipe](./recipes/babel.md#configuring-babel) for more details
- `babel.extensions`: extensions of test files that will be precompiled using AVA's Babel presets. Setting this overrides the default `"js"` value, so make sure to include that extension in the list
4 changes: 2 additions & 2 deletions docs/07-test-timeouts.md
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/do

Timeouts in AVA behave differently than in other test frameworks. AVA resets a timer after each test, forcing tests to quit if no new test results were received within the specified timeout. This can be used to handle stalled tests.

You can configure timeouts using the `--timeout` [command line option](./05-command-line.md), or in the [configuration](./06-configuration.md).
*There is no default timeout.*

You can set timeouts in a human-readable way:
You can configure timeouts using the `--timeout` [command line option](./05-command-line.md), or in the [configuration](./06-configuration.md). They can be set in a human-readable way:

```console
npx ava --timeout=10s # 10 seconds
4 changes: 2 additions & 2 deletions docs/08-common-pitfalls.md
Original file line number Diff line number Diff line change
@@ -75,11 +75,11 @@ AVA [can't trace uncaught exceptions](https://github.com/avajs/ava/issues/214) b

### Why are the enhanced assertion messages not shown?

Ensure that the first parameter passed into your test is named `t`. This is a requirement of [`power-assert`](https://github.com/power-assert-js/power-assert), the library that provides the enhanced messages.
Ensure that the first parameter passed into your test is named `t`. This is a requirement of [`power-assert`](https://github.com/power-assert-js/power-assert), the library that provides the [enhanced messages](./03-assertions.md#enhanced-assertion-messages).

```js
test('one is one', t => {
t.is(1, 1);
t.assert(1 === 1);
});
```

2 changes: 1 addition & 1 deletion docs/recipes/flow.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/do

AVA comes bundled with a Flow definition file. This allows developers to leverage Flow for writing tests.

This guide assumes you've already set up Flow for your project. Note that AVA's definition as been tested with version 0.94.0.
This guide assumes you've already set up Flow for your project. Note that AVA's definition as been tested with version 0.95.1.

We recommend you use AVA's built-in Babel pipeline to strip Flow type annotations and declarations. AVA automatically applies your project's Babel configuration, so everything may just work without changes. Alternatively install [`@babel/plugin-transform-flow-strip-types`](https://www.npmjs.com/package/@babel/plugin-transform-flow-strip-types) and customize AVA's configuration in the `package.json` file (or the `ava.config.js` file) as follows.

2 changes: 1 addition & 1 deletion docs/recipes/typescript.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ Translations: [Español](https://github.com/avajs/ava-docs/blob/master/es_ES/doc

AVA comes bundled with a TypeScript definition file. This allows developers to leverage TypeScript for writing tests.

This guide assumes you've already set up TypeScript for your project. Note that AVA's definition has been tested with version 3.3.3333.
This guide assumes you've already set up TypeScript for your project. Note that AVA's definition has been tested with version 3.3.4000.

## Configuring AVA to compile TypeScript files on the fly

79 changes: 54 additions & 25 deletions lib/assert.js
Original file line number Diff line number Diff line change
@@ -589,110 +589,139 @@ function wrapAssertions(callbacks) {
message: message || 'No snapshot available, run with --update-snapshots'
}));
}
}
};
},

const enhancedAssertions = enhanceAssert(pass, fail, {
truthy(actual, message) {
if (!actual) {
throw new AssertionError({
if (actual) {
pass(this);
} else {
fail(this, new AssertionError({
assertion: 'truthy',
message,
operator: '!!',
values: [formatWithLabel('Value is not truthy:', actual)]
});
}));
}
},

falsy(actual, message) {
if (actual) {
throw new AssertionError({
fail(this, new AssertionError({
assertion: 'falsy',
message,
operator: '!',
values: [formatWithLabel('Value is not falsy:', actual)]
});
}));
} else {
pass(this);
}
},

true(actual, message) {
if (actual !== true) {
throw new AssertionError({
if (actual === true) {
pass(this);
} else {
fail(this, new AssertionError({
assertion: 'true',
message,
values: [formatWithLabel('Value is not `true`:', actual)]
});
}));
}
},

false(actual, message) {
if (actual !== false) {
throw new AssertionError({
if (actual === false) {
pass(this);
} else {
fail(this, new AssertionError({
assertion: 'false',
message,
values: [formatWithLabel('Value is not `false`:', actual)]
});
}));
}
},

regex(string, regex, message) {
if (typeof string !== 'string') {
throw new AssertionError({
fail(this, new AssertionError({
assertion: 'regex',
improperUsage: true,
message: '`t.regex()` must be called with a string',
values: [formatWithLabel('Called with:', string)]
});
}));
return;
}

if (!(regex instanceof RegExp)) {
throw new AssertionError({
fail(this, new AssertionError({
assertion: 'regex',
improperUsage: true,
message: '`t.regex()` must be called with a regular expression',
values: [formatWithLabel('Called with:', regex)]
});
}));
return;
}

if (!regex.test(string)) {
throw new AssertionError({
fail(this, new AssertionError({
assertion: 'regex',
message,
values: [
formatWithLabel('Value must match expression:', string),
formatWithLabel('Regular expression:', regex)
]
});
}));
return;
}

pass(this);
},

notRegex(string, regex, message) {
if (typeof string !== 'string') {
throw new AssertionError({
fail(this, new AssertionError({
assertion: 'notRegex',
improperUsage: true,
message: '`t.notRegex()` must be called with a string',
values: [formatWithLabel('Called with:', string)]
});
}));
return;
}

if (!(regex instanceof RegExp)) {
throw new AssertionError({
fail(this, new AssertionError({
assertion: 'notRegex',
improperUsage: true,
message: '`t.notRegex()` must be called with a regular expression',
values: [formatWithLabel('Called with:', regex)]
});
}));
return;
}

if (regex.test(string)) {
throw new AssertionError({
fail(this, new AssertionError({
assertion: 'notRegex',
message,
values: [
formatWithLabel('Value must not match expression:', string),
formatWithLabel('Regular expression:', regex)
]
}));
return;
}

pass(this);
}
};

const enhancedAssertions = enhanceAssert(pass, fail, {
assert(actual, message) {
if (!actual) {
throw new AssertionError({
assertion: 'assert',
message,
operator: '!!',
values: [formatWithLabel('Value is not truthy:', actual)]
});
}
}
7 changes: 1 addition & 6 deletions lib/enhance-assert.js
Original file line number Diff line number Diff line change
@@ -8,12 +8,7 @@ const concordanceOptions = require('./concordance-options').default;
// https://github.com/avajs/babel-preset-transform-test-files/blob/master/espower-patterns.json
// Then release a new version of that preset and bump the SemVer range here.
const PATTERNS = [
't.truthy(value, [message])',
't.falsy(value, [message])',
't.true(value, [message])',
't.false(value, [message])',
't.regex(contents, regex, [message])',
't.notRegex(contents, regex, [message])'
't.assert(value, [message])'
];

const computeStatement = node => generate(node).code;
2 changes: 1 addition & 1 deletion lib/run-status.js
Original file line number Diff line number Diff line change
@@ -59,7 +59,6 @@ class RunStatus extends Emittery {
case 'declared-test':
stats.declaredTests++;
fileStats.declaredTests++;
this.addPendingTest(event);
break;
case 'hook-failed':
stats.failedHooks++;
@@ -84,6 +83,7 @@ class RunStatus extends Emittery {
} else {
stats.remainingTests++;
fileStats.remainingTests++;
this.addPendingTest(event);
}

break;
3 changes: 3 additions & 0 deletions lib/watcher.js
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ const chokidar = require('chokidar');
const flatten = require('arr-flatten');
const union = require('array-union');
const uniq = require('array-uniq');
const chalk = require('./chalk').get();
const AvaFiles = require('./ava-files');

function rethrowAsync(err) {
@@ -18,6 +19,7 @@ function rethrowAsync(err) {

const MIN_DEBOUNCE_DELAY = 10;
const INITIAL_DEBOUNCE_DELAY = 100;
const END_MESSAGE = chalk.gray('Type `r` and press enter to rerun tests\nType `u` and press enter to update snapshots\n');

class Debouncer {
constructor(watcher) {
@@ -123,6 +125,7 @@ class Watcher {
})
.then(runStatus => {
reporter.endRun();
reporter.lineWriter.writeLine(END_MESSAGE);

if (this.clearLogOnNextRun && (
runStatus.stats.failedHooks > 0 ||
22 changes: 22 additions & 0 deletions lib/worker/fake-tty.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const tty = require('tty');
const ansiEscapes = require('ansi-escapes');
const options = require('./options').get();

const fakeTTYs = new Set();
@@ -10,6 +11,27 @@ tty.isatty = fd => fakeTTYs.has(fd) || isatty(fd);
const simulateTTY = (stream, {colorDepth, columns, rows}) => {
Object.assign(stream, {isTTY: true, columns, rows});

stream.clearLine = dir => {
switch (dir) {
case -1:
stream.write(ansiEscapes.eraseStartLine);
break;
case 1:
stream.write(ansiEscapes.eraseEndLine);
break;
default:
stream.write(ansiEscapes.eraseLine);
}
};

stream.clearScreenDown = () => stream.write(ansiEscapes.eraseDown);

stream.cursorTo = (x, y) => stream.write(ansiEscapes.cursorTo(x, y));

stream.getWindowSize = () => [80, 24];

stream.moveCursor = (x, y) => stream.write(ansiEscapes.cursorMove(x, y));

if (colorDepth !== undefined) {
stream.getColorDepth = () => colorDepth;
}
Binary file modified media/magic-assert-combined.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed media/magic-assert-nested.png
Binary file not shown.
Binary file added media/power-assert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 0 additions & 11 deletions media/screenshot-fixtures/magic-assert-nested.js

This file was deleted.

11 changes: 11 additions & 0 deletions media/screenshot-fixtures/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "screenshot-fixtures",
"version": "1.0.0",
"description": "",
"main": "magic-assert-buffers.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": ""
}
8 changes: 8 additions & 0 deletions media/screenshot-fixtures/power-assert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import test from 'ava';

test('power-assert', t => {
const a = /foo/;
const b = 'bar';
const c = 'baz';
t.assert(a.test(b) || b === c);
});
338 changes: 189 additions & 149 deletions package-lock.json

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ava",
"version": "1.3.1",
"version": "1.4.0",
"description": "Testing can be a drag. AVA helps you get it done.",
"license": "MIT",
"repository": "avajs/ava",
@@ -12,7 +12,7 @@
"scripts": {
"lint": "xo",
"test:flow": "flow check test/flow-types",
"test:tap": "tap --no-cov --reporter=classic --timeout=300 --jobs=2 test/*.js test/reporters/*.js test/integration/*.js",
"test:tap": "tap --no-esm --no-cov --reporter=classic --timeout=300 --jobs=2 test/*.js test/reporters/*.js test/integration/*.js",
"test:typescript": "tsc --noEmit -p test/ts-types",
"test": "npm run lint && npm run test:flow && npm run test:typescript && nyc npm run test:tap"
},
@@ -61,10 +61,10 @@
],
"dependencies": {
"@ava/babel-preset-stage-4": "^2.0.0",
"@ava/babel-preset-transform-test-files": "^4.0.1",
"@ava/babel-preset-transform-test-files": "^5.0.0",
"@ava/write-file-atomic": "^2.2.0",
"@babel/core": "^7.3.4",
"@babel/generator": "^7.3.4",
"@babel/core": "^7.4.0",
"@babel/generator": "^7.4.0",
"@babel/plugin-syntax-async-generators": "^7.2.0",
"@babel/plugin-syntax-object-rest-spread": "^7.2.0",
"@babel/plugin-syntax-optional-catch-binding": "^7.2.0",
@@ -77,7 +77,7 @@
"arrify": "^1.0.0",
"bluebird": "^3.5.3",
"chalk": "^2.4.2",
"chokidar": "^2.1.2",
"chokidar": "^2.1.5",
"chunkd": "^1.0.0",
"ci-parallel-vars": "^1.0.0",
"clean-stack": "^2.0.0",
@@ -96,7 +96,7 @@
"empower-core": "^1.2.0",
"equal-length": "^1.0.0",
"escape-string-regexp": "^1.0.5",
"esm": "^3.2.10",
"esm": "^3.2.20",
"figures": "^2.0.0",
"find-up": "^3.0.0",
"get-port": "^4.2.0",
@@ -131,9 +131,9 @@
"require-precompiled": "^0.1.0",
"resolve-cwd": "^2.0.0",
"slash": "^2.0.0",
"source-map-support": "^0.5.10",
"source-map-support": "^0.5.11",
"stack-utils": "^1.0.2",
"strip-ansi": "^5.0.0",
"strip-ansi": "^5.2.0",
"strip-bom-buf": "^1.0.0",
"supertap": "^1.0.0",
"supports-color": "^6.1.0",
@@ -147,24 +147,24 @@
"codecov": "^3.2.0",
"delay": "^4.1.0",
"execa": "^1.0.0",
"flow-bin": "^0.94.0",
"flow-bin": "^0.95.1",
"get-stream": "^4.1.0",
"git-branch": "^2.0.1",
"has-ansi": "^3.0.0",
"lolex": "^3.1.0",
"nyc": "^13.3.0",
"proxyquire": "^2.1.0",
"react": "^16.8.3",
"react-test-renderer": "^16.8.3",
"react": "^16.8.5",
"react-test-renderer": "^16.8.5",
"replace-string": "^2.0.0",
"signal-exit": "^3.0.0",
"sinon": "^7.2.7",
"sinon": "^7.3.0",
"source-map-fixtures": "^2.1.0",
"tap": "~12.4.1",
"tap": "^12.6.1",
"temp-write": "^3.4.0",
"touch": "^3.1.0",
"ts-node": "^8.0.2",
"typescript": "^3.3.3333",
"ts-node": "^8.0.3",
"typescript": "^3.3.4000",
"xo": "^0.24.0",
"zen-observable": "^0.8.13"
},
3 changes: 2 additions & 1 deletion test/api.js
Original file line number Diff line number Diff line change
@@ -433,6 +433,7 @@ test('enhanced assertion formatting necessary whitespace and empty strings', t =
/foo/
],
[
/!\(new Object\(foo\) instanceof Object\)/,
/new Object\(foo\) instanceof Object/,
/Object/,
/new Object\(foo\)/,
@@ -447,7 +448,7 @@ test('enhanced assertion formatting necessary whitespace and empty strings', t =
]
];

t.plan(14);
t.plan(15);
const api = apiCreator();
const errors = [];
api.on('run', plan => {
28 changes: 28 additions & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
@@ -1513,6 +1513,7 @@ test('.regex() fails if passed a bad value', t => {
assertions.regex(42, /foo/);
}, {
assertion: 'regex',
improperUsage: true,
message: '`t.regex()` must be called with a string',
values: [{label: 'Called with:', formatted: /42/}]
});
@@ -1577,3 +1578,30 @@ test('.notRegex() fails if passed a bad value', t => {

t.end();
});

test('.assert()', t => {
failsWith(t, () => {
assertions.assert(0);
}, {
assertion: 'assert',
message: '',
operator: '!!',
values: [{label: 'Value is not truthy:', formatted: /0/}]
});

failsWith(t, () => {
assertions.assert(false, 'my message');
}, {
assertion: 'assert',
message: 'my message',
operator: '!!',
values: [{label: 'Value is not truthy:', formatted: /false/}]
});

passes(t, () => {
assertions.assert(1);
assertions.assert(true);
});

t.end();
});
6 changes: 3 additions & 3 deletions test/fixture/enhanced-assertion-formatting.js
Original file line number Diff line number Diff line change
@@ -4,16 +4,16 @@ const foo = 'foo';

test('fails with multiple empty string expressions and mixed quotes', t => {
// eslint-disable-next-line quotes, yoda
t.true(foo === '' && "" === foo);
t.assert(foo === '' && "" === foo);
});

test('fails with "instanceof" expression', t => {
// eslint-disable-next-line no-new-object
t.false(new Object(foo) instanceof Object);
t.assert(!(new Object(foo) instanceof Object));
});

test('fails with multiple lines', t => {
t.true(
t.assert(
[foo].filter(item => {
return item === 'bar';
}).length > 0
Original file line number Diff line number Diff line change
@@ -4,5 +4,5 @@ const test = require('../../../..');

test('test', t => {
const bool = false;
t.true(bool);
t.assert(bool);
});
2 changes: 1 addition & 1 deletion test/fixture/just-enhancement-compilation/power-assert.js
Original file line number Diff line number Diff line change
@@ -4,5 +4,5 @@ const test = require('../../..');

test('test', t => {
const bool = false;
t.true(bool);
t.assert(bool);
});
2 changes: 1 addition & 1 deletion test/fixture/no-babel-compilation/no-power-assert.js
Original file line number Diff line number Diff line change
@@ -4,5 +4,5 @@ const test = require('../../..');

test('test', t => {
const bool = false;
t.true(bool);
t.assert(bool);
});
4 changes: 2 additions & 2 deletions test/fixture/report/regular/test.js
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@ test('formatted', t => {
});

test('power-assert', t => {
const foo = 'bar';
t.falsy(foo);
const foo = '';
t.assert(foo);
});

test('bad throws', t => {
15 changes: 15 additions & 0 deletions test/fixture/report/timeoutwithmatch/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import test from '../../../..';

test('passes needle', t => t.pass());

test.cb('slow needle', t => {
setTimeout(t.end, 15000);
});
test.cb('slow two', t => {
setTimeout(t.end, 15000);
});
test.cb('slow three needle', t => {
setTimeout(t.end, 15000);
});

test('passes two', t => t.pass());
1 change: 1 addition & 0 deletions test/fixture/report/timeoutwithmatch/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions test/fixture/tty/is-tty.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,11 @@ const assertTTY = (t, stream) => {
t.true(stream.isTTY);
t.is(typeof stream.columns, 'number');
t.is(typeof stream.rows, 'number');
t.is(typeof stream.clearLine, 'function');
t.is(typeof stream.clearScreenDown, 'function');
t.is(typeof stream.cursorTo, 'function');
t.is(typeof stream.getWindowSize, 'function');
t.is(typeof stream.moveCursor, 'function');
};

test('stderr is a TTY', assertTTY, process.stderr);
5 changes: 3 additions & 2 deletions test/helper/report.js
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ exports.sanitizers = {
version: str => replaceString(str, `v${pkg.version}`, 'v1.0.0-beta.5.1')
};

const run = (type, reporter) => {
const run = (type, reporter, match = []) => {
const projectDir = path.join(__dirname, '../fixture/report', type.toLowerCase());

const options = {
@@ -96,7 +96,7 @@ const run = (type, reporter) => {
require: [],
cacheEnabled: true,
compileEnhancements: true,
match: [],
match,
babelConfig: {testOptions: {}},
resolveTestsFrom: projectDir,
projectDir,
@@ -144,6 +144,7 @@ exports.failFast2 = reporter => run('failFast2', reporter);
exports.only = reporter => run('only', reporter);
exports.timeoutInSingleFile = reporter => run('timeoutInSingleFile', reporter);
exports.timeoutInMultipleFiles = reporter => run('timeoutInMultipleFiles', reporter);
exports.timeoutWithMatch = reporter => run('timeoutWithMatch', reporter, ['*needle*']);
exports.watch = reporter => run('watch', reporter);
exports.typescript = reporter => run('typescript', reporter);
exports.edgeCases = reporter => run('edge-cases', reporter);
4 changes: 3 additions & 1 deletion test/integration/watcher.js
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@ const {test} = require('tap');
const touch = require('touch');
const {execCli} = require('../helper/cli');

const END_MESSAGE = 'Type `r` and press enter to rerun tests\nType `u` and press enter to update snapshots\n';

test('watcher reruns test files when they changed', t => {
let killed = false;

@@ -101,7 +103,7 @@ test('watcher does not rerun test files when they write snapshot files', t => {
killed = true;
}, 500);
} else if (passedFirst && !killed) {
t.is(buffer.replace(/\s/g, ''), '');
t.is(buffer.replace(/\s/g, '').replace(END_MESSAGE.replace(/\s/g, ''), ''), '');
}
});
});
12 changes: 6 additions & 6 deletions test/reporters/mini.regular.log
Original file line number Diff line number Diff line change
@@ -325,16 +325,16 @@ stderr

~/test/fixture/report/regular/test.js:30

29: const foo = 'bar';
 30: t.falsy(foo); 
31: });
29: const foo = '';
 30: t.assert(foo); 
31: });

Value is not falsy:
Value is not truthy:

'bar'
''

foo
=> 'bar'
=> ''



8 changes: 4 additions & 4 deletions test/reporters/tap.regular.log
Original file line number Diff line number Diff line change
@@ -174,11 +174,11 @@ not ok 22 - test › formatted
not ok 23 - test › power-assert
---
name: AssertionError
assertion: falsy
operator: '!'
assertion: assert
operator: '!!'
values:
'Value is not falsy:': '''bar'''
at: 'falsy (test.js:30:4)'
'Value is not truthy:': ''''''
at: 'assert (test.js:30:4)'
...
---tty-stream-chunk-separator
# test › bad throws
1 change: 1 addition & 0 deletions test/reporters/verbose.js
Original file line number Diff line number Diff line change
@@ -44,5 +44,6 @@ test('verbose reporter - timeout', t => {

t.test('single file run', run('timeoutInSingleFile'));
t.test('multiple files run', run('timeoutInMultipleFiles'));
t.test('single file with only certain tests matched run', run('timeoutWithMatch'));
t.end();
});
12 changes: 6 additions & 6 deletions test/reporters/verbose.regular.log
Original file line number Diff line number Diff line change
@@ -286,16 +286,16 @@ stderr

~/test/fixture/report/regular/test.js:30

29: const foo = 'bar';
 30: t.falsy(foo); 
31: });
29: const foo = '';
 30: t.assert(foo); 
31: });

Value is not falsy:
Value is not truthy:

'bar'
''

foo
=> 'bar'
=> ''



17 changes: 17 additions & 0 deletions test/reporters/verbose.timeoutwithmatch.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

---tty-stream-chunk-separator
✔ passes needle
---tty-stream-chunk-separator

✖ Timed out while running tests

2 tests were pending in ~/test/fixture/report/timeoutwithmatch/a.js

◌ slow needle
◌ slow three needle

---tty-stream-chunk-separator

1 test passed

---tty-stream-chunk-separator
13 changes: 10 additions & 3 deletions test/watcher.js
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ const {test} = require('tap');
const AvaFiles = require('../lib/ava-files');
const {setImmediate} = require('../lib/now-and-timers');

require('../lib/chalk').set({});

// Helper to make using beforeEach less arduous
function makeGroup(test) {
return (desc, fn) => {
@@ -71,7 +73,10 @@ group('chokidar', (beforeEach, test, group) => {
debug = sinon.spy();

reporter = {
endRun: sinon.spy()
endRun: sinon.spy(),
lineWriter: {
writeLine: sinon.spy()
}
};

api = {
@@ -221,7 +226,7 @@ group('chokidar', (beforeEach, test, group) => {
});

test('starts running the initial tests', t => {
t.plan(4);
t.plan(6);

let done;
api.run.returns(new Promise(resolve => {
@@ -234,11 +239,13 @@ group('chokidar', (beforeEach, test, group) => {
t.ok(api.run.calledOnce);
t.strictDeepEqual(api.run.firstCall.args, [files, defaultApiOptions]);

// The endRun method is only called after the run promise fulfils
// The endRun and lineWriter.writeLine methods are only called after the run promise fulfils
t.ok(reporter.endRun.notCalled);
t.ok(reporter.lineWriter.writeLine.notCalled);
done();
return delay().then(() => {
t.ok(reporter.endRun.calledOnce);
t.ok(reporter.lineWriter.writeLine.calledOnce);
});
});