From 4f8a532773b523ee9bdc50613cd2a3661cad7ad8 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Mon, 29 Jan 2018 14:16:10 +0000 Subject: [PATCH 1/2] Require tests to have titles Stop deriving a title from the test implementation function's name. Note that this can't quite be expressed in the type definitions. Hopefully when we tackle #1182 it'll be easier to write the appropriate definition. --- docs/common-pitfalls.md | 10 +- docs/recipes/when-to-use-plan.md | 16 ++-- index.js.flow | 12 +-- lib/test-collection.js | 16 +--- package-lock.json | 5 - package.json | 1 - readme.md | 56 ++++------- test/api.js | 4 +- test/cli.js | 2 +- test/fixture/ava-paths/target/test.js | 2 +- test/fixture/caching/test.js | 2 +- .../circular-reference-on-assertion.js | 2 +- test/fixture/debug-arg.js | 2 +- test/fixture/error-in-anonymous-function.js | 2 +- test/fixture/es2015-source-maps.js | 2 +- test/fixture/es2015.js | 2 +- test/fixture/exclusive-nonexclusive.js | 4 +- test/fixture/exclusive.js | 2 +- test/fixture/fake-timers.js | 2 +- test/fixture/formatting-color.js | 2 +- test/fixture/hooks-failing.js | 2 +- test/fixture/hooks-passing.js | 2 +- test/fixture/ignored-dirs/fixtures/test.js | 2 +- test/fixture/ignored-dirs/helpers/test.js | 2 +- .../improper-t-throws/async-callback.js | 2 +- .../caught-and-leaked-slowly.js | 2 +- .../caught-and-leaked-too-slowly.js | 2 +- .../improper-t-throws/caught-and-leaked.js | 2 +- test/fixture/improper-t-throws/caught.js | 2 +- .../improper-t-throws/leaked-from-promise.js | 2 +- test/fixture/improper-t-throws/promise.js | 2 +- test/fixture/improper-t-throws/throws.js | 2 +- .../improper-t-throws/unhandled-rejection.js | 2 +- test/fixture/infinity-stack-trace.js | 2 +- test/fixture/inspect-arg.js | 2 +- .../power-assert.js | 2 +- test/fixture/long-stack-trace/test.js | 2 +- test/fixture/match-no-match.js | 2 +- .../no-babel-compilation/no-power-assert.js | 2 +- .../no-babel-compilation/require-helper.js | 2 +- test/fixture/pkg-conf/defaults/test.js | 2 +- .../pkg-conf/fail-without-assertions/test.js | 2 +- test/fixture/pkg-conf/pkg-overrides/actual.js | 2 +- test/fixture/pkg-conf/pkg-overrides/test.js | 2 +- test/fixture/pkg-conf/precedence/a.js | 2 +- test/fixture/pkg-conf/precedence/b.js | 2 +- .../dir-a-wrapper/dir-a/dir-a-wrapper-3.js | 2 +- .../dir-a-wrapper/dir-a/dir-a-wrapper-4.js | 2 +- .../resolve-dir/dir-a/dir-a-base-1.js | 2 +- .../resolve-dir/dir-a/dir-a-base-2.js | 2 +- test/fixture/power-assert.js | 6 +- test/fixture/precompile-helpers/test/test.js | 2 +- test/fixture/process-cwd-default.js | 2 +- test/fixture/process-cwd-pkgdir.js | 2 +- test/fixture/serial.js | 2 +- test/fixture/skip-only.js | 2 +- test/fixture/stalled-tests/callback.js | 2 +- test/fixture/stalled-tests/observable.js | 2 +- test/fixture/stalled-tests/promise.js | 2 +- test/fixture/symlinkdir/symlink.js | 2 +- test/fixture/target-symlink.js | 2 +- .../trigger-worker-exception/test-fallback.js | 2 +- test/fixture/trigger-worker-exception/test.js | 2 +- test/fixture/validate-installed-global.js | 2 +- test/flow-types/regression-1114.js.flow | 4 +- test/flow-types/regression-1148.js.flow | 2 +- test/flow-types/regression-1500.js.flow | 2 +- test/hooks.js | 46 ++++----- test/runner.js | 95 +++++++------------ test/test-collection.js | 2 +- test/ts-types/regression-1347.ts | 2 +- types/base.d.ts | 10 +- 72 files changed, 166 insertions(+), 235 deletions(-) diff --git a/docs/common-pitfalls.md b/docs/common-pitfalls.md index 0f067132a..090cfcbf9 100644 --- a/docs/common-pitfalls.md +++ b/docs/common-pitfalls.md @@ -25,7 +25,7 @@ Use the `concurrency` flag to limit the number of processes ran. For example, if You may be running an asynchronous operation inside a test and wondering why it's not finishing. If your asynchronous operation uses promises, you should return the promise: ```js -test(t => { +test('fetches foo', t => { return fetch().then(data => { t.is(data, 'foo'); }); @@ -35,7 +35,7 @@ test(t => { Better yet, use `async` / `await`: ```js -test(async t => { +test('fetches foo', async t => { const data = await fetch(); t.is(data, 'foo'); }); @@ -44,7 +44,7 @@ test(async t => { If you're using callbacks, use [`test.cb`](https://github.com/avajs/ava#callback-support): ```js -test.cb(t => { +test.cb('fetches foo', t => { fetch((err, data) => { t.is(data, 'foo'); t.end(); @@ -55,7 +55,7 @@ test.cb(t => { Alternatively, promisify the callback function using something like [`pify`](https://github.com/sindresorhus/pify): ```js -test(async t => { +test('fetches foo', async t => { const data = await pify(fetch)(); t.is(data, 'foo'); }); @@ -70,7 +70,7 @@ AVA [can't trace uncaught exceptions](https://github.com/avajs/ava/issues/214) b 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. ```js -test(t => { +test('one is one', t => { t.is(1, 1); }); ``` diff --git a/docs/recipes/when-to-use-plan.md b/docs/recipes/when-to-use-plan.md index 19d9982bf..4975b677e 100644 --- a/docs/recipes/when-to-use-plan.md +++ b/docs/recipes/when-to-use-plan.md @@ -13,7 +13,7 @@ Many users transitioning from `tap`/`tape` are accustomed to using `t.plan()` pr `t.plan()` is unnecessary in most sync tests. ```js -test(t => { +test('simple sums', t => { // BAD: there is no branching here - t.plan() is pointless t.plan(2); @@ -27,7 +27,7 @@ test(t => { ### Promises that are expected to resolve ```js -test(t => { +test('gives foo', t => { t.plan(1); return somePromise().then(result => { @@ -43,7 +43,7 @@ At a glance, this tests appears to make good use of `t.plan()` since an async pr 2. It would be better to take advantage of `async`/`await`: ```js -test(async t => { +test('gives foo', async t => { t.is(await somePromise(), 'foo'); }); ``` @@ -51,7 +51,7 @@ test(async t => { ### Promises with a `.catch()` block ```js -test(t => { +test('rejects with foo', t => { t.plan(2); return shouldRejectWithFoo().catch(reason => { @@ -65,7 +65,7 @@ Here, the use of `t.plan()` seeks to ensure that the code inside the `catch` blo Instead, you should take advantage of `t.throws` and `async`/`await`, as this leads to flatter code that is easier to reason about: ```js -test(async t => { +test('rejects with foo', async t => { const reason = await t.throws(shouldRejectWithFoo()); t.is(reason.message, 'Hello'); t.is(reason.foo, 'bar'); @@ -75,7 +75,7 @@ test(async t => { ### Ensuring a catch statement happens ```js -test(t => { +test('throws', t => { t.plan(2); try { @@ -96,7 +96,7 @@ As stated in the previous example, using the `t.throws()` assertion with `async` ### Ensuring multiple callbacks are actually called ```js -test.cb(t => { +test.cb('invokes callbacks', t => { t.plan(2); const callbackA = () => { @@ -120,7 +120,7 @@ In most cases, it's a bad idea to use any complex branching inside your tests. A const testData = require('./fixtures/test-definitions.json'); testData.forEach(testDefinition => { - test(t => { + test('foo or bar', t => { const result = functionUnderTest(testDefinition.input); // testDefinition should have an expectation for `foo` or `bar` but not both diff --git a/index.js.flow b/index.js.flow index d21470695..5734a3963 100644 --- a/index.js.flow +++ b/index.js.flow @@ -111,8 +111,8 @@ type ContextualCallbackTest = TestImplementation { +test('arrays are equal', t => { t.deepEqual([1, 2], [1, 2]); }); ``` @@ -313,7 +313,7 @@ AVA tries to run test files with their current working directory set to the dire ### Creating tests -To create a test you call the `test` function you imported from AVA. Provide the optional title and implementation function. The function will be called when your test is run. It's passed an [execution object](#t) as its first argument. +To create a test you call the `test` function you imported from AVA. Provide the required title and implementation function. The function will be called when your test is run. It's passed an [execution object](#t) as its first argument. **Note:** In order for the [enhanced assertion messages](#enhanced-assertion-messages) to behave correctly, the first argument **must** be named `t`. @@ -325,26 +325,6 @@ test('my passing test', t => { }); ``` -#### Titles - -Titles are optional, meaning you can do: - -```js -test(t => { - t.pass(); -}); -``` - -It's recommended to provide test titles if you have more than one test. - -If you haven't provided a test title, but the implementation is a named function, that name will be used as the test title: - -```js -test(function name(t) { - t.pass(); -}); -``` - ### Assertion planning Assertion plans ensure tests only pass when a specific number of assertions have been executed. They'll help you catch cases where tests exit too early. They'll also cause tests to fail if too many assertions are executed, which can be useful if you have assertions inside callbacks or loops. @@ -356,7 +336,7 @@ Note that, unlike [`tap`](https://www.npmjs.com/package/tap) and [`tape`](https: These examples will result in a passed test: ```js -test(t => { +test('resolves with 3', t => { t.plan(1); return Promise.resolve(3).then(n => { @@ -364,7 +344,7 @@ test(t => { }); }); -test.cb(t => { +test.cb('invokes callback', t => { t.plan(1); someAsyncFunction(() => { @@ -377,7 +357,7 @@ test.cb(t => { These won't: ```js -test(t => { +test('loops twice', t => { t.plan(2); for (let i = 0; i < 3; i++) { @@ -385,7 +365,7 @@ test(t => { } }); // Fails, 3 assertions are executed which is too many -test(t => { +test('invokes callback synchronously', t => { t.plan(1); someAsyncFunction(() => { @@ -399,7 +379,7 @@ test(t => { Tests are run concurrently by default, however, sometimes you have to write tests that cannot run concurrently. In these rare cases you can use the `.serial` modifier. It will force those tests to run serially *before* the concurrent ones. ```js -test.serial(t => { +test.serial('passes serially', t => { t.pass(); }); ``` @@ -574,7 +554,7 @@ test.afterEach.always(t => { // This runs after each test and other test hooks, even if they failed }); -test(t => { +test('title', t => { // Regular test }); ``` @@ -612,7 +592,7 @@ test.beforeEach(t => { t.context.data = generateUniqueData(); }); -test(t => { +test('context data is foo', t => { t.is(t.context.data + 'bar', 'foobar'); }); ``` @@ -624,7 +604,7 @@ test.beforeEach(t => { t.context = 'unicorn'; }); -test(t => { +test('context is unicorn', t => { t.is(t.context, 'unicorn'); }); ``` @@ -703,7 +683,7 @@ You'll have to configure AVA to not fail tests if no assertions are executed, be ```js import assert from 'assert'; -test(t => { +test('custom assertion', t => { assert(true); }); ``` @@ -737,7 +717,7 @@ You can also transpile your modules in a separate process and refer to the trans If you return a promise in the test you don't need to explicitly end the test as it will end when the promise resolves. ```js -test(t => { +test('resolves with unicorn', t => { return somePromise().then(result => { t.is(result, 'unicorn'); }); @@ -766,7 +746,7 @@ test(async function (t) { }); // Async arrow function -test(async t => { +test('promises the truth', async t => { const value = await promiseFn(); t.true(value); }); @@ -779,7 +759,7 @@ AVA comes with built-in support for [observables](https://github.com/zenparsing/ *You do not need to use "callback mode" or call `t.end()`.* ```js -test(t => { +test('handles observables', t => { t.plan(3); return Observable.of(1, 2, 3, 4, 5, 6) .filter(n => { @@ -795,7 +775,7 @@ test(t => { AVA supports using `t.end` as the final callback when using node-style error-first callback APIs. AVA will consider any truthy value passed as the first argument to `t.end` to be an error. Note that `t.end` requires "callback mode", which can be enabled by using the `test.cb` chain. ```js -test.cb(t => { +test.cb('data.txt can be read', t => { // `t.end` automatically checks for error as first argument fs.readFile('data.txt', t.end); }); @@ -864,7 +844,7 @@ Log values contextually alongside the test result instead of immediately printin Assertions are mixed into the [execution object](#t) provided to each test implementation: ```js -test(t => { +test('unicorns are truthy', t => { t.truthy('unicorn'); // Assertion }); ``` @@ -1044,7 +1024,7 @@ If you are running AVA against precompiled test files, AVA will try and use sour Any assertion can be skipped using the `skip` modifier. Skipped assertions are still counted, so there is no need to change your planned assertion count. ```js -test(t => { +test('skip assertion', t => { t.plan(2); t.skip.is(foo(), 5); // No need to change your plan count when skipping t.is(1, 1); @@ -1073,7 +1053,7 @@ AssertionError: false == true In AVA however, this test: ```js -test(t => { +test('enhanced assertions', t => { const a = /foo/; const b = 'bar'; const c = 'baz'; diff --git a/test/api.js b/test/api.js index b83255ee0..559f6716e 100644 --- a/test/api.js +++ b/test/api.js @@ -69,19 +69,17 @@ function generateTests(prefix, apiCreator) { }); test(`${prefix} test title prefixes — multiple files`, t => { - t.plan(6); + t.plan(5); const separator = ` ${figures.pointerSmall} `; const files = [ path.join(__dirname, 'fixture/async-await.js'), - path.join(__dirname, 'fixture/es2015.js'), path.join(__dirname, 'fixture/generators.js'), path.join(__dirname, 'fixture/subdir/in-a-subdir.js') ]; const expected = [ ['async-await', 'async function'].join(separator), ['async-await', 'arrow async function'].join(separator), - ['es2015', '[anonymous]'].join(separator), ['generators', 'generator function'].join(separator), ['subdir', 'in-a-subdir', 'subdir'].join(separator) ]; diff --git a/test/cli.js b/test/cli.js index 081961259..ca16a0484 100644 --- a/test/cli.js +++ b/test/cli.js @@ -528,7 +528,7 @@ test('use current working directory if `package.json` is not found', () => { const cliPath = require.resolve('../cli.js'); const avaPath = require.resolve('../'); - fs.writeFileSync(testFilePath, `import test from ${JSON.stringify(avaPath)};\ntest(t => { t.pass(); });`); + fs.writeFileSync(testFilePath, `import test from ${JSON.stringify(avaPath)};\ntest('test', t => { t.pass(); });`); return execa(process.execPath, [cliPath], {cwd}); }); diff --git a/test/fixture/ava-paths/target/test.js b/test/fixture/ava-paths/target/test.js index 137bcd035..eb38ef946 100644 --- a/test/fixture/ava-paths/target/test.js +++ b/test/fixture/ava-paths/target/test.js @@ -1,6 +1,6 @@ /* eslint-disable import/no-extraneous-dependencies, import/no-unresolved */ import test from 'ava'; -test(t => { +test('test', t => { t.pass(); }); diff --git a/test/fixture/caching/test.js b/test/fixture/caching/test.js index 8bd357561..e893ee744 100644 --- a/test/fixture/caching/test.js +++ b/test/fixture/caching/test.js @@ -1,5 +1,5 @@ import test from '../../../'; -test(t => { +test('test', t => { t.true(2 + 2 === 4); }); diff --git a/test/fixture/circular-reference-on-assertion.js b/test/fixture/circular-reference-on-assertion.js index 3603efe86..452e35477 100644 --- a/test/fixture/circular-reference-on-assertion.js +++ b/test/fixture/circular-reference-on-assertion.js @@ -1,6 +1,6 @@ import test from '../../'; -test(t => { +test('test', t => { const circular = ['a', 'b']; circular.push(circular); t.deepEqual([circular, 'c'], [circular, 'd']); diff --git a/test/fixture/debug-arg.js b/test/fixture/debug-arg.js index cbee6f5ab..6d62bc8cb 100644 --- a/test/fixture/debug-arg.js +++ b/test/fixture/debug-arg.js @@ -1,5 +1,5 @@ import test from '../../'; -test(t => { +test('test', t => { t.true(process.execArgv[0].indexOf('--debug') === 0); }); diff --git a/test/fixture/error-in-anonymous-function.js b/test/fixture/error-in-anonymous-function.js index b78b2631b..1a9051bde 100644 --- a/test/fixture/error-in-anonymous-function.js +++ b/test/fixture/error-in-anonymous-function.js @@ -4,7 +4,7 @@ const getAnonymousFn = () => () => { throw new Error(); }; -test(t => { +test('test', t => { getAnonymousFn()(); t.pass(); }); diff --git a/test/fixture/es2015-source-maps.js b/test/fixture/es2015-source-maps.js index 4ed44e35f..63c3dda1f 100644 --- a/test/fixture/es2015-source-maps.js +++ b/test/fixture/es2015-source-maps.js @@ -1,6 +1,6 @@ import test from '../../'; -test(t => { +test('test', t => { t.pass(); }); diff --git a/test/fixture/es2015.js b/test/fixture/es2015.js index cb2bbbc10..56bf8fb88 100644 --- a/test/fixture/es2015.js +++ b/test/fixture/es2015.js @@ -1,5 +1,5 @@ import test from '../../'; -test(t => { +test('test', t => { t.pass(); }); diff --git a/test/fixture/exclusive-nonexclusive.js b/test/fixture/exclusive-nonexclusive.js index 77d5a0384..2f68cd105 100644 --- a/test/fixture/exclusive-nonexclusive.js +++ b/test/fixture/exclusive-nonexclusive.js @@ -1,9 +1,9 @@ import test from '../../'; -test.only(t => { +test.only('only', t => { t.pass(); }); -test(t => { +test('test', t => { t.fail(); }); diff --git a/test/fixture/exclusive.js b/test/fixture/exclusive.js index 59071ec44..d596e2609 100644 --- a/test/fixture/exclusive.js +++ b/test/fixture/exclusive.js @@ -1,5 +1,5 @@ import test from '../..'; -test.only(t => { +test.only('test', t => { t.pass(); }); diff --git a/test/fixture/fake-timers.js b/test/fixture/fake-timers.js index 599a4b074..294bb4135 100644 --- a/test/fixture/fake-timers.js +++ b/test/fixture/fake-timers.js @@ -1,7 +1,7 @@ import sinon from 'sinon'; import test from '../../'; -test(t => { +test('test', t => { sinon.useFakeTimers(Date.now() + 10000); t.pass(); }); diff --git a/test/fixture/formatting-color.js b/test/fixture/formatting-color.js index 77f34f5d5..15110cdd0 100644 --- a/test/fixture/formatting-color.js +++ b/test/fixture/formatting-color.js @@ -1,5 +1,5 @@ import test from '../..'; -test(t => { +test('test', t => { t.deepEqual({foo: 1}, {foo: 2}); }); diff --git a/test/fixture/hooks-failing.js b/test/fixture/hooks-failing.js index ece3b0f01..fc3b695d2 100644 --- a/test/fixture/hooks-failing.js +++ b/test/fixture/hooks-failing.js @@ -1,7 +1,7 @@ import test from '../../'; test.beforeEach(fail); -test(pass); +test('pass', pass); function pass() {} diff --git a/test/fixture/hooks-passing.js b/test/fixture/hooks-passing.js index 98f585012..c2f9ec5a0 100644 --- a/test/fixture/hooks-passing.js +++ b/test/fixture/hooks-passing.js @@ -4,7 +4,7 @@ test.before(pass); test.beforeEach(pass); test.after(pass); test.afterEach(pass); -test(pass); +test('pass', pass); function pass(t) { t.pass(); diff --git a/test/fixture/ignored-dirs/fixtures/test.js b/test/fixture/ignored-dirs/fixtures/test.js index 33cdc7c26..84543f040 100644 --- a/test/fixture/ignored-dirs/fixtures/test.js +++ b/test/fixture/ignored-dirs/fixtures/test.js @@ -1,5 +1,5 @@ import test from '../../../../'; -test(t => { +test('test', t => { t.pass(); }); diff --git a/test/fixture/ignored-dirs/helpers/test.js b/test/fixture/ignored-dirs/helpers/test.js index 33cdc7c26..84543f040 100644 --- a/test/fixture/ignored-dirs/helpers/test.js +++ b/test/fixture/ignored-dirs/helpers/test.js @@ -1,5 +1,5 @@ import test from '../../../../'; -test(t => { +test('test', t => { t.pass(); }); diff --git a/test/fixture/improper-t-throws/async-callback.js b/test/fixture/improper-t-throws/async-callback.js index aeeff6258..2d160b04c 100644 --- a/test/fixture/improper-t-throws/async-callback.js +++ b/test/fixture/improper-t-throws/async-callback.js @@ -1,6 +1,6 @@ import test from '../../..'; -test.cb(t => { +test.cb('test', t => { setTimeout(() => { t.throws(throwSync()); }); diff --git a/test/fixture/improper-t-throws/caught-and-leaked-slowly.js b/test/fixture/improper-t-throws/caught-and-leaked-slowly.js index 1258fff50..96d83ac96 100644 --- a/test/fixture/improper-t-throws/caught-and-leaked-slowly.js +++ b/test/fixture/improper-t-throws/caught-and-leaked-slowly.js @@ -1,6 +1,6 @@ import test from '../../..'; -test(t => { +test('test', t => { try { t.throws(throwSync()); } catch (err) { diff --git a/test/fixture/improper-t-throws/caught-and-leaked-too-slowly.js b/test/fixture/improper-t-throws/caught-and-leaked-too-slowly.js index 772a5b14d..ea63e16a2 100644 --- a/test/fixture/improper-t-throws/caught-and-leaked-too-slowly.js +++ b/test/fixture/improper-t-throws/caught-and-leaked-too-slowly.js @@ -1,6 +1,6 @@ import test from '../../..'; -test(t => { +test('test', t => { try { t.throws(throwSync()); } catch (err) { diff --git a/test/fixture/improper-t-throws/caught-and-leaked.js b/test/fixture/improper-t-throws/caught-and-leaked.js index 5768e226e..663d66b8b 100644 --- a/test/fixture/improper-t-throws/caught-and-leaked.js +++ b/test/fixture/improper-t-throws/caught-and-leaked.js @@ -1,6 +1,6 @@ import test from '../../..'; -test(t => { +test('test', t => { try { t.throws(throwSync()); } catch (err) { diff --git a/test/fixture/improper-t-throws/caught.js b/test/fixture/improper-t-throws/caught.js index 491b39b0e..da7020d9d 100644 --- a/test/fixture/improper-t-throws/caught.js +++ b/test/fixture/improper-t-throws/caught.js @@ -1,6 +1,6 @@ import test from '../../..'; -test(t => { +test('test', t => { try { t.throws(throwSync()); } catch (err) {} diff --git a/test/fixture/improper-t-throws/leaked-from-promise.js b/test/fixture/improper-t-throws/leaked-from-promise.js index f9cc36158..09bdf00bb 100644 --- a/test/fixture/improper-t-throws/leaked-from-promise.js +++ b/test/fixture/improper-t-throws/leaked-from-promise.js @@ -1,6 +1,6 @@ import test from '../../..'; -test(t => { +test('test', t => { try { t.throws(throwSync()); } catch (err) { diff --git a/test/fixture/improper-t-throws/promise.js b/test/fixture/improper-t-throws/promise.js index 55d727776..4d60e33aa 100644 --- a/test/fixture/improper-t-throws/promise.js +++ b/test/fixture/improper-t-throws/promise.js @@ -1,6 +1,6 @@ import test from '../../..'; -test(t => { +test('test', t => { return Promise.resolve().then(() => { t.throws(throwSync()); }); diff --git a/test/fixture/improper-t-throws/throws.js b/test/fixture/improper-t-throws/throws.js index fadcd5fb0..008231d14 100644 --- a/test/fixture/improper-t-throws/throws.js +++ b/test/fixture/improper-t-throws/throws.js @@ -1,6 +1,6 @@ import test from '../../..'; -test(t => { +test('test', t => { t.throws(throwSync()); }); diff --git a/test/fixture/improper-t-throws/unhandled-rejection.js b/test/fixture/improper-t-throws/unhandled-rejection.js index 5790c0f86..cd5158661 100644 --- a/test/fixture/improper-t-throws/unhandled-rejection.js +++ b/test/fixture/improper-t-throws/unhandled-rejection.js @@ -1,6 +1,6 @@ import test from '../../..'; -test.cb(t => { +test.cb('test', t => { Promise.resolve().then(() => { t.throws(throwSync()); }); diff --git a/test/fixture/infinity-stack-trace.js b/test/fixture/infinity-stack-trace.js index b8aed2da3..acb822113 100644 --- a/test/fixture/infinity-stack-trace.js +++ b/test/fixture/infinity-stack-trace.js @@ -2,7 +2,7 @@ import test from '../../'; Error.stackTraceLimit = 1; -test(t => { +test('test', t => { const c = () => t.fail(); const b = () => c(); const a = () => b(); diff --git a/test/fixture/inspect-arg.js b/test/fixture/inspect-arg.js index b0a36b590..95ef6346f 100644 --- a/test/fixture/inspect-arg.js +++ b/test/fixture/inspect-arg.js @@ -1,5 +1,5 @@ import test from '../../'; -test(t => { +test('test', t => { t.true(process.execArgv[0].indexOf('--inspect') === 0); }); diff --git a/test/fixture/just-enhancement-compilation/power-assert.js b/test/fixture/just-enhancement-compilation/power-assert.js index b7e6fa92f..99bab9868 100644 --- a/test/fixture/just-enhancement-compilation/power-assert.js +++ b/test/fixture/just-enhancement-compilation/power-assert.js @@ -2,7 +2,7 @@ const test = require('../../../'); -test(t => { +test('test', t => { const bool = false; t.true(bool); }); diff --git a/test/fixture/long-stack-trace/test.js b/test/fixture/long-stack-trace/test.js index a4469e9ef..b69ad77d7 100644 --- a/test/fixture/long-stack-trace/test.js +++ b/test/fixture/long-stack-trace/test.js @@ -3,7 +3,7 @@ import Bluebird from './_enable-trace'; // This promise throwing pattern was used in bluebird documentation for long stack traces // http://bluebirdjs.com/docs/api/promise.longstacktraces.html -test(async t => { +test('test', async t => { await Bluebird.resolve().then(() => { return Bluebird.resolve().then(() => { return Bluebird.resolve().then(() => { diff --git a/test/fixture/match-no-match.js b/test/fixture/match-no-match.js index 8fd50a0f2..4b38a0594 100644 --- a/test/fixture/match-no-match.js +++ b/test/fixture/match-no-match.js @@ -8,6 +8,6 @@ test.only('bar', t => { t.pass(); }); -test.only(t => { +test.only('baz', t => { t.pass(); }); diff --git a/test/fixture/no-babel-compilation/no-power-assert.js b/test/fixture/no-babel-compilation/no-power-assert.js index b7e6fa92f..99bab9868 100644 --- a/test/fixture/no-babel-compilation/no-power-assert.js +++ b/test/fixture/no-babel-compilation/no-power-assert.js @@ -2,7 +2,7 @@ const test = require('../../../'); -test(t => { +test('test', t => { const bool = false; t.true(bool); }); diff --git a/test/fixture/no-babel-compilation/require-helper.js b/test/fixture/no-babel-compilation/require-helper.js index f2f158a3a..6c22749d5 100644 --- a/test/fixture/no-babel-compilation/require-helper.js +++ b/test/fixture/no-babel-compilation/require-helper.js @@ -2,6 +2,6 @@ const test = require('../../../'); -test(t => { +test('test', t => { t.throws(() => require('./_helper'), SyntaxError); }); diff --git a/test/fixture/pkg-conf/defaults/test.js b/test/fixture/pkg-conf/defaults/test.js index c209f3b68..86163e864 100644 --- a/test/fixture/pkg-conf/defaults/test.js +++ b/test/fixture/pkg-conf/defaults/test.js @@ -2,7 +2,7 @@ import test from '../../../../'; const opts = JSON.parse(process.argv[2]); -test(t => { +test('test', t => { t.is(opts.failFast, false); t.is(opts.serial, false); t.is(opts.cacheEnabled, true); diff --git a/test/fixture/pkg-conf/fail-without-assertions/test.js b/test/fixture/pkg-conf/fail-without-assertions/test.js index a2792088c..62446a885 100644 --- a/test/fixture/pkg-conf/fail-without-assertions/test.js +++ b/test/fixture/pkg-conf/fail-without-assertions/test.js @@ -1,3 +1,3 @@ import test from '../../../..'; -test(() => {}); +test('test', () => {}); diff --git a/test/fixture/pkg-conf/pkg-overrides/actual.js b/test/fixture/pkg-conf/pkg-overrides/actual.js index 9d82e6100..fd1383802 100644 --- a/test/fixture/pkg-conf/pkg-overrides/actual.js +++ b/test/fixture/pkg-conf/pkg-overrides/actual.js @@ -2,7 +2,7 @@ import test from '../../../../'; const opts = JSON.parse(process.argv[2]); -test(t => { +test('test', t => { t.is(opts.failFast, true); t.is(opts.serial, true); t.is(opts.cacheEnabled, false); diff --git a/test/fixture/pkg-conf/pkg-overrides/test.js b/test/fixture/pkg-conf/pkg-overrides/test.js index 83ddb0e7b..232ea423b 100644 --- a/test/fixture/pkg-conf/pkg-overrides/test.js +++ b/test/fixture/pkg-conf/pkg-overrides/test.js @@ -2,6 +2,6 @@ import test from '../../../../'; // This should never be loaded - package.json overrides files to call `actual.js` -test(t => { +test('test', t => { t.fail(); }); diff --git a/test/fixture/pkg-conf/precedence/a.js b/test/fixture/pkg-conf/precedence/a.js index 83ddb0e7b..232ea423b 100644 --- a/test/fixture/pkg-conf/precedence/a.js +++ b/test/fixture/pkg-conf/precedence/a.js @@ -2,6 +2,6 @@ import test from '../../../../'; // This should never be loaded - package.json overrides files to call `actual.js` -test(t => { +test('test', t => { t.fail(); }); diff --git a/test/fixture/pkg-conf/precedence/b.js b/test/fixture/pkg-conf/precedence/b.js index 83ddb0e7b..232ea423b 100644 --- a/test/fixture/pkg-conf/precedence/b.js +++ b/test/fixture/pkg-conf/precedence/b.js @@ -2,6 +2,6 @@ import test from '../../../../'; // This should never be loaded - package.json overrides files to call `actual.js` -test(t => { +test('test', t => { t.fail(); }); diff --git a/test/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-3.js b/test/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-3.js index f7f3994d5..1637f8170 100644 --- a/test/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-3.js +++ b/test/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-3.js @@ -1,5 +1,5 @@ import test from '../../../../../../'; -test(t => { +test('test', t => { t.pass(); }); diff --git a/test/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-4.js b/test/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-4.js index f7f3994d5..1637f8170 100644 --- a/test/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-4.js +++ b/test/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-4.js @@ -1,5 +1,5 @@ import test from '../../../../../../'; -test(t => { +test('test', t => { t.pass(); }); diff --git a/test/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-1.js b/test/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-1.js index f5af94d7a..b999b33ea 100644 --- a/test/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-1.js +++ b/test/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-1.js @@ -1,5 +1,5 @@ import test from '../../../../../'; -test(t => { +test('test', t => { t.pass(); }); diff --git a/test/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-2.js b/test/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-2.js index f5af94d7a..b999b33ea 100644 --- a/test/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-2.js +++ b/test/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-2.js @@ -1,5 +1,5 @@ import test from '../../../../../'; -test(t => { +test('test', t => { t.pass(); }); diff --git a/test/fixture/power-assert.js b/test/fixture/power-assert.js index a22f2c688..78ee8ffff 100644 --- a/test/fixture/power-assert.js +++ b/test/fixture/power-assert.js @@ -1,16 +1,16 @@ import test from '../../'; -test.serial(t => { +test.serial('bar', t => { const a = 'foo'; t.true(a === 'bar'); }); -test.serial(t => { +test.serial('foo', t => { const a = 'bar'; t.true(a === 'foo', 'with message'); }); -test.serial(t => { +test.serial('span', t => { const React = { // eslint-disable-line no-unused-vars createElement: type => type }; diff --git a/test/fixture/precompile-helpers/test/test.js b/test/fixture/precompile-helpers/test/test.js index 79c8480ce..84812c864 100644 --- a/test/fixture/precompile-helpers/test/test.js +++ b/test/fixture/precompile-helpers/test/test.js @@ -2,7 +2,7 @@ import test from '../../../../'; import a from './helpers/a'; import b from './_b'; -test(async t => { +test('test', async t => { await a(); await b(); diff --git a/test/fixture/process-cwd-default.js b/test/fixture/process-cwd-default.js index 78c4eb463..35314c213 100644 --- a/test/fixture/process-cwd-default.js +++ b/test/fixture/process-cwd-default.js @@ -2,7 +2,7 @@ import path from 'path'; import pkgConf from 'pkg-conf'; import test from '../../'; -test(t => { +test('test', t => { const conf = pkgConf.sync('ava'); const pkgDir = path.dirname(pkgConf.filepath(conf)); t.is(process.cwd(), pkgDir); diff --git a/test/fixture/process-cwd-pkgdir.js b/test/fixture/process-cwd-pkgdir.js index b1aad6418..1fdfea5ac 100644 --- a/test/fixture/process-cwd-pkgdir.js +++ b/test/fixture/process-cwd-pkgdir.js @@ -1,5 +1,5 @@ import test from '../../'; -test(t => { +test('test', t => { t.is(process.cwd(), __dirname); }); diff --git a/test/fixture/serial.js b/test/fixture/serial.js index 20332425c..186ba22fa 100644 --- a/test/fixture/serial.js +++ b/test/fixture/serial.js @@ -16,6 +16,6 @@ test.cb('second', t => { }, 100); }); -test(t => { +test('test', t => { t.deepEqual(tests, ['first', 'second']); }); diff --git a/test/fixture/skip-only.js b/test/fixture/skip-only.js index 99d995a56..f4e05f1d7 100644 --- a/test/fixture/skip-only.js +++ b/test/fixture/skip-only.js @@ -1,5 +1,5 @@ import test from '../../'; -test.skip(t => { +test.skip('test', t => { t.fail(); }); diff --git a/test/fixture/stalled-tests/callback.js b/test/fixture/stalled-tests/callback.js index 6022936b7..37621a1f2 100644 --- a/test/fixture/stalled-tests/callback.js +++ b/test/fixture/stalled-tests/callback.js @@ -1,5 +1,5 @@ import test from '../../..'; -test.cb(t => { +test.cb('test', t => { t.pass(); }); diff --git a/test/fixture/stalled-tests/observable.js b/test/fixture/stalled-tests/observable.js index 98ebe4878..72756c4cd 100644 --- a/test/fixture/stalled-tests/observable.js +++ b/test/fixture/stalled-tests/observable.js @@ -1,7 +1,7 @@ import Observable from 'zen-observable'; import test from '../../..'; -test(t => { +test('test', t => { return new Observable(() => { t.pass(); }); diff --git a/test/fixture/stalled-tests/promise.js b/test/fixture/stalled-tests/promise.js index 0c317ab8d..330564298 100644 --- a/test/fixture/stalled-tests/promise.js +++ b/test/fixture/stalled-tests/promise.js @@ -1,6 +1,6 @@ import test from '../../..'; -test(t => { +test('test', t => { return new Promise(() => { t.pass(); }); diff --git a/test/fixture/symlinkdir/symlink.js b/test/fixture/symlinkdir/symlink.js index 0d5fdc9e4..91aa9c284 100644 --- a/test/fixture/symlinkdir/symlink.js +++ b/test/fixture/symlinkdir/symlink.js @@ -1,5 +1,5 @@ import test from '../../../'; -test(t => { +test('test', t => { t.pass(); }); diff --git a/test/fixture/target-symlink.js b/test/fixture/target-symlink.js index cb2bbbc10..56bf8fb88 100644 --- a/test/fixture/target-symlink.js +++ b/test/fixture/target-symlink.js @@ -1,5 +1,5 @@ import test from '../../'; -test(t => { +test('test', t => { t.pass(); }); diff --git a/test/fixture/trigger-worker-exception/test-fallback.js b/test/fixture/trigger-worker-exception/test-fallback.js index 27b164653..6c4098bf8 100644 --- a/test/fixture/trigger-worker-exception/test-fallback.js +++ b/test/fixture/trigger-worker-exception/test-fallback.js @@ -1,5 +1,5 @@ import test from '../../../'; -test(async () => { +test('test', async () => { throw new Error('Hi :)'); }); diff --git a/test/fixture/trigger-worker-exception/test.js b/test/fixture/trigger-worker-exception/test.js index 306607c21..f2e0b3866 100644 --- a/test/fixture/trigger-worker-exception/test.js +++ b/test/fixture/trigger-worker-exception/test.js @@ -4,6 +4,6 @@ import {restoreAfterFirstCall} from './hack'; restoreAfterFirstCall(); -test(async () => { +test('test', async () => { throw new Error('Hi :)'); }); diff --git a/test/fixture/validate-installed-global.js b/test/fixture/validate-installed-global.js index c78eb4e8d..112bbb531 100644 --- a/test/fixture/validate-installed-global.js +++ b/test/fixture/validate-installed-global.js @@ -1,3 +1,3 @@ import test from '../../'; -test(t => t.is(global.foo, 'bar')); +test('test', t => t.is(global.foo, 'bar')); diff --git a/test/flow-types/regression-1114.js.flow b/test/flow-types/regression-1114.js.flow index 307e85799..dfe7756ab 100644 --- a/test/flow-types/regression-1114.js.flow +++ b/test/flow-types/regression-1114.js.flow @@ -11,7 +11,7 @@ test('Named test', t => { t.end(); }); -test(t => { +test('test', t => { t.pass('Success'); // $ExpectError: Unknown method "unknownAssertion" t.unknownAssertion('Whoops'); @@ -20,7 +20,7 @@ test(t => { t.end(); }); -test.cb(t => { +test.cb('test', t => { t.pass('Success'); t.end(); }); diff --git a/test/flow-types/regression-1148.js.flow b/test/flow-types/regression-1148.js.flow index f08f65dcf..45cf45f8d 100644 --- a/test/flow-types/regression-1148.js.flow +++ b/test/flow-types/regression-1148.js.flow @@ -2,7 +2,7 @@ const test = require('../../index.js.flow'); -test(t => { +test('test', t => { t.throws(() => { throw new Error(); }); t.throws(Promise.reject(new Error())); diff --git a/test/flow-types/regression-1500.js.flow b/test/flow-types/regression-1500.js.flow index d402aca34..ca4f83d98 100644 --- a/test/flow-types/regression-1500.js.flow +++ b/test/flow-types/regression-1500.js.flow @@ -2,7 +2,7 @@ const test = require('../../index.js.flow'); -test(t => { +test('test', t => { t.snapshot({}); t.snapshot({}, "a message"); t.snapshot({}, {id: "snapshot-id"}); diff --git a/test/hooks.js b/test/hooks.js index c0a2f3931..a0795c985 100644 --- a/test/hooks.js +++ b/test/hooks.js @@ -38,7 +38,7 @@ test('before', t => { arr.push('a'); }); - runner.chain.test(a => { + runner.chain.test('test', a => { a.pass(); arr.push('b'); }); @@ -58,7 +58,7 @@ test('after', t => { arr.push('b'); }); - runner.chain.test(a => { + runner.chain.test('test', a => { a.pass(); arr.push('a'); }); @@ -82,7 +82,7 @@ test('after not run if test failed', t => { arr.push('a'); }); - runner.chain.test(() => { + runner.chain.test('test', () => { throw new Error('something went wrong'); }); return runner.run({}).then(() => { @@ -104,7 +104,7 @@ test('after.always run even if test failed', t => { arr.push('a'); }); - runner.chain.test(() => { + runner.chain.test('test', () => { throw new Error('something went wrong'); }); return runner.run({}).then(() => { @@ -150,7 +150,7 @@ test('stop if before hooks failed', t => { throw new Error('something went wrong'); }); - runner.chain.test(a => { + runner.chain.test('test', a => { a.pass(); arr.push('b'); a.end(); @@ -178,12 +178,12 @@ test('before each with concurrent tests', t => { arr[k++].push('b'); }); - runner.chain.test(a => { + runner.chain.test('c', a => { a.pass(); arr[0].push('c'); }); - runner.chain.test(a => { + runner.chain.test('d', a => { a.pass(); arr[1].push('d'); }); @@ -208,12 +208,12 @@ test('before each with serial tests', t => { arr.push('b'); }); - runner.chain.serial(a => { + runner.chain.serial('c', a => { a.pass(); arr.push('c'); }); - runner.chain.serial(a => { + runner.chain.serial('d', a => { a.pass(); arr.push('d'); }); @@ -235,7 +235,7 @@ test('fail if beforeEach hook fails', t => { a.fail(); }); - runner.chain.test(a => { + runner.chain.test('test', a => { arr.push('b'); a.pass(); }); @@ -264,12 +264,12 @@ test('after each with concurrent tests', t => { arr[k++].push('b'); }); - runner.chain.test(a => { + runner.chain.test('c', a => { a.pass(); arr[0].push('c'); }); - runner.chain.test(a => { + runner.chain.test('d', a => { a.pass(); arr[1].push('d'); }); @@ -294,12 +294,12 @@ test('after each with serial tests', t => { arr.push('b'); }); - runner.chain.serial(a => { + runner.chain.serial('c', a => { a.pass(); arr.push('c'); }); - runner.chain.serial(a => { + runner.chain.serial('d', a => { a.pass(); arr.push('d'); }); @@ -320,7 +320,7 @@ test('afterEach not run if concurrent tests failed', t => { arr.push('a'); }); - runner.chain.test(() => { + runner.chain.test('test', () => { throw new Error('something went wrong'); }); @@ -340,7 +340,7 @@ test('afterEach not run if serial tests failed', t => { arr.push('a'); }); - runner.chain.serial(() => { + runner.chain.serial('test', () => { throw new Error('something went wrong'); }); @@ -360,7 +360,7 @@ test('afterEach.always run even if concurrent tests failed', t => { arr.push('a'); }); - runner.chain.test(() => { + runner.chain.test('test', () => { throw new Error('something went wrong'); }); @@ -380,7 +380,7 @@ test('afterEach.always run even if serial tests failed', t => { arr.push('a'); }); - runner.chain.serial(() => { + runner.chain.serial('test', () => { throw new Error('something went wrong'); }); @@ -400,7 +400,7 @@ test('afterEach.always run even if beforeEach failed', t => { throw new Error('something went wrong'); }); - runner.chain.test(a => { + runner.chain.test('test', a => { a.pass(); arr.push('a'); }); @@ -437,7 +437,7 @@ test('ensure hooks run only around tests', t => { arr.push('after'); }); - runner.chain.test(a => { + runner.chain.test('test', a => { a.pass(); arr.push('test'); }); @@ -465,7 +465,7 @@ test('shared context', t => { a.context.arr = ['a']; }); - runner.chain.test(a => { + runner.chain.test('test', a => { a.pass(); a.context.arr.push('b'); a.deepEqual(a.context.arr, ['a', 'b']); @@ -492,7 +492,7 @@ test('shared context of any type', t => { a.context = 'foo'; }); - runner.chain.test(a => { + runner.chain.test('test', a => { a.pass(); a.is(a.context, 'foo'); }); @@ -525,7 +525,7 @@ test('display hook title if it failed', t => { .run({}) .on('test', test => { t.is(test.error.name, 'AssertionError'); - t.is(test.title, 'fail for pass'); + t.is(test.title, 'beforeEach hook for pass'); }) .then(() => { t.end(); diff --git a/test/runner.js b/test/runner.js index 30ac551e3..91e1411af 100644 --- a/test/runner.js +++ b/test/runner.js @@ -10,7 +10,7 @@ test('nested tests and hooks aren\'t allowed', t => { const runner = new Runner(); - runner.chain.test(a => { + runner.chain.test('test', a => { t.throws(() => { runner.chain.test(noop); }, {message: 'All tests and hooks must be declared synchronously in your test file, and cannot be nested within other tests or hooks.'}); @@ -27,7 +27,7 @@ test('tests must be declared synchronously', t => { const runner = new Runner(); - runner.chain.test(a => { + runner.chain.test('test', a => { a.pass(); return Promise.resolve(); }); @@ -62,17 +62,17 @@ test('run serial tests before concurrent ones', t => { const runner = new Runner(); const arr = []; - runner.chain.test(a => { + runner.chain.test('test', a => { arr.push('c'); a.end(); }); - runner.chain.serial(a => { + runner.chain.serial('serial', a => { arr.push('a'); a.end(); }); - runner.chain.serial(a => { + runner.chain.serial('serial 2', a => { arr.push('b'); a.end(); }); @@ -106,11 +106,11 @@ test('anything can be skipped', t => { runner.chain.beforeEach(pusher('beforeEach')); runner.chain.beforeEach.skip(pusher('beforeEach.skip')); - runner.chain.test(pusher('concurrent')); - runner.chain.test.skip(pusher('concurrent.skip')); + runner.chain.test('concurrent', pusher('concurrent')); + runner.chain.test.skip('concurrent.skip', pusher('concurrent.skip')); - runner.chain.serial(pusher('serial')); - runner.chain.serial.skip(pusher('serial.skip')); + runner.chain.serial('serial', pusher('serial')); + runner.chain.serial.skip('serial.skip', pusher('serial.skip')); runner.run({}).then(() => { // Note that afterEach and beforeEach run twice because there are two actual tests - "serial" and "concurrent" @@ -188,17 +188,14 @@ test('test types and titles', t => { runner.chain.afterEach(named); runner.chain.test('test', fn); - // See https://github.com/avajs/ava/issues/1027 - const supportsFunctionNames = noop.name === 'noop'; - const tests = [ { type: 'before', - title: 'named' + title: 'before hook' }, { type: 'beforeEach', - title: supportsFunctionNames ? 'fn for test' : 'beforeEach for test' + title: 'beforeEach hook for test' }, { type: 'test', @@ -206,11 +203,11 @@ test('test types and titles', t => { }, { type: 'afterEach', - title: 'named for test' + title: 'afterEach hook for test' }, { type: 'after', - title: supportsFunctionNames ? 'fn' : 'after' + title: 'after hook' } ]; @@ -229,12 +226,12 @@ test('skip test', t => { const runner = new Runner(); const arr = []; - runner.chain.test(a => { + runner.chain.test('test', a => { arr.push('a'); a.pass(); }); - runner.chain.skip(() => { + runner.chain.skip('skip', () => { arr.push('b'); }); @@ -268,7 +265,7 @@ test('todo test', t => { const runner = new Runner(); const arr = []; - runner.chain.test(a => { + runner.chain.test('test', a => { arr.push('a'); a.pass(); }); @@ -299,12 +296,12 @@ test('only test', t => { const runner = new Runner(); const arr = []; - runner.chain.test(a => { + runner.chain.test('test', a => { arr.push('a'); a.pass(); }); - runner.chain.only(a => { + runner.chain.only('only', a => { arr.push('b'); a.pass(); }); @@ -495,7 +492,7 @@ test('runOnlyExclusive option test', t => { const options = {runOnlyExclusive: true}; const arr = []; - runner.chain.test(() => { + runner.chain.test('test', () => { arr.push('a'); }); @@ -511,7 +508,7 @@ test('options.serial forces all tests to be serial', t => { const runner = new Runner({serial: true}); const arr = []; - runner.chain.cb(a => { + runner.chain.cb('cb', a => { setTimeout(() => { arr.push(1); a.end(); @@ -519,7 +516,7 @@ test('options.serial forces all tests to be serial', t => { a.pass(); }); - runner.chain.cb(a => { + runner.chain.cb('cb 2', a => { setTimeout(() => { arr.push(2); a.end(); @@ -527,7 +524,7 @@ test('options.serial forces all tests to be serial', t => { a.pass(); }); - runner.chain.test(a => { + runner.chain.test('test', a => { a.pass(); t.strictDeepEqual(arr, [1, 2]); t.end(); @@ -541,12 +538,12 @@ test('options.bail will bail out', t => { const runner = new Runner({bail: true}); - runner.chain.test(a => { + runner.chain.test('test', a => { t.pass(); a.fail(); }); - runner.chain.test(() => { + runner.chain.test('test 2', () => { t.fail(); }); @@ -561,7 +558,7 @@ test('options.bail will bail out (async)', t => { const runner = new Runner({bail: true}); const tests = []; - runner.chain.cb(a => { + runner.chain.cb('cb', a => { setTimeout(() => { tests.push(1); a.fail(); @@ -570,7 +567,7 @@ test('options.bail will bail out (async)', t => { a.pass(); }); - runner.chain.cb(a => { + runner.chain.cb('cb 2', a => { setTimeout(() => { tests.push(2); a.end(); @@ -598,7 +595,7 @@ test('options.bail + serial - tests will never happen (async)', t => { }); const tests = []; - runner.chain.cb(a => { + runner.chain.cb('cb', a => { setTimeout(() => { tests.push(1); a.fail(); @@ -606,7 +603,7 @@ test('options.bail + serial - tests will never happen (async)', t => { }, 100); }); - runner.chain.cb(a => { + runner.chain.cb('cb 2', a => { setTimeout(() => { tests.push(2); a.end(); @@ -644,7 +641,7 @@ test('options.match will not run tests with non-matching titles', t => { a.pass(); }); - runner.chain.test(a => { + runner.chain.test('test', a => { t.fail(); a.pass(); }); @@ -711,32 +708,6 @@ test('options.match overrides .only', t => { }); }); -test('options.match includes anonymous tests in negative matches', t => { - t.plan(4); - - const runner = new Runner({ - match: ['!*oo'] - }); - - runner.chain.test('foo', a => { - t.fail(); - a.pass(); - }); - - runner.chain.test(a => { - t.pass(); - a.pass(); - }); - - runner.run({}).then(() => { - const stats = runner.buildStats(); - t.is(stats.skipCount, 0); - t.is(stats.passCount, 1); - t.is(stats.testCount, 1); - t.end(); - }); -}); - test('macros: Additional args will be spread as additional args on implementation function', t => { t.plan(3); @@ -848,10 +819,10 @@ test('arrays of macros', t => { const runner = new Runner(); - runner.chain.test([macroFnA, macroFnB], 'A'); - runner.chain.test([macroFnA, macroFnB], 'B'); - runner.chain.test(macroFnA, 'C'); - runner.chain.test(macroFnB, 'D'); + runner.chain.test('A', [macroFnA, macroFnB], 'A'); + runner.chain.test('B', [macroFnA, macroFnB], 'B'); + runner.chain.test('C', macroFnA, 'C'); + runner.chain.test('D', macroFnB, 'D'); runner.run({}).then(() => { const stats = runner.buildStats(); diff --git a/test/test-collection.js b/test/test-collection.js index b6ee23732..fd933feb6 100644 --- a/test/test-collection.js +++ b/test/test-collection.js @@ -113,7 +113,7 @@ test('throws if you try to set a before hook as always', t => { test('throws if you try to set a test as always', t => { const collection = new TestCollection({}); t.throws(() => { - collection.add(mockTest({always: true})); + collection.add(mockTest({always: true}, 'test')); }, {message: '"always" can only be used with after and afterEach hooks'}); t.end(); }); diff --git a/test/ts-types/regression-1347.ts b/test/ts-types/regression-1347.ts index 4a864bbe6..b72932b8e 100644 --- a/test/ts-types/regression-1347.ts +++ b/test/ts-types/regression-1347.ts @@ -1,5 +1,5 @@ import test from '../..' -test.cb(t => { +test.cb('test', t => { t.end() }) diff --git a/types/base.d.ts b/types/base.d.ts index 774db3fa1..6e6cfa9c3 100644 --- a/types/base.d.ts +++ b/types/base.d.ts @@ -125,16 +125,14 @@ export interface Macro { export type Macros = Macro | Macro[]; interface RegisterBase { - (name: string, run: GenericTest): void; - (run: GenericTest): void; - (name: string, run: Macros>, ...args: any[]): void; + (title: string, run: GenericTest): void; + (title: string, run: Macros>, ...args: any[]): void; (run: Macros>, ...args: any[]): void; } interface CallbackRegisterBase { - (name: string, run: GenericCallbackTest): void; - (run: GenericCallbackTest): void; - (name: string, run: Macros>, ...args: any[]): void; + (title: string, run: GenericCallbackTest): void; + (title: string, run: Macros>, ...args: any[]): void; (run: Macros>, ...args: any[]): void; } From ed3682d93a53118b971e9b3ff34e0f840faba1c3 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Mon, 29 Jan 2018 14:25:00 +0000 Subject: [PATCH 2/2] Require test titles to be unique Fixes #1207. --- lib/test-collection.js | 9 +++++++++ readme.md | 2 +- test/runner.js | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/test-collection.js b/lib/test-collection.js index 1d1c50fde..a0bb9e76f 100644 --- a/lib/test-collection.js +++ b/lib/test-collection.js @@ -29,6 +29,7 @@ class TestCollection extends EventEmitter { }; this.pendingTestInstances = new Set(); + this.uniqueTestTitles = new Set(); this._emitTestResult = this._emitTestResult.bind(this); } @@ -49,6 +50,14 @@ class TestCollection extends EventEmitter { } } + if (type === 'test') { + if (this.uniqueTestTitles.has(test.title)) { + throw new Error(`Duplicate test title: ${test.title}`); + } else { + this.uniqueTestTitles.add(test.title); + } + } + if (metadata.always && type !== 'after' && type !== 'afterEach') { throw new Error('"always" can only be used with after and afterEach hooks'); } diff --git a/readme.md b/readme.md index 80d5c5231..ed1e1e487 100644 --- a/readme.md +++ b/readme.md @@ -313,7 +313,7 @@ AVA tries to run test files with their current working directory set to the dire ### Creating tests -To create a test you call the `test` function you imported from AVA. Provide the required title and implementation function. The function will be called when your test is run. It's passed an [execution object](#t) as its first argument. +To create a test you call the `test` function you imported from AVA. Provide the required title and implementation function. Titles must be unique within each test file. The function will be called when your test is run. It's passed an [execution object](#t) as its first argument. **Note:** In order for the [enhanced assertion messages](#enhanced-assertion-messages) to behave correctly, the first argument **must** be named `t`. diff --git a/test/runner.js b/test/runner.js index 91e1411af..be267c579 100644 --- a/test/runner.js +++ b/test/runner.js @@ -811,11 +811,13 @@ test('arrays of macros', t => { t.deepEqual(slice.call(arguments, 1), expectedArgsA.shift()); a.pass(); } + macroFnA.title = prefix => `${prefix}.A`; function macroFnB(a) { t.deepEqual(slice.call(arguments, 1), expectedArgsB.shift()); a.pass(); } + macroFnB.title = prefix => `${prefix}.B`; const runner = new Runner(); @@ -853,7 +855,7 @@ test('match applies to arrays of macros', t => { t.fail(); a.pass(); } - bazMacro.title = firstArg => `${firstArg}baz`; + bazMacro.title = (title, firstArg) => `${firstArg}baz`; const runner = new Runner({ match: ['foobar']