From 33172dc2275835c5259a10ca6559b96c0b7f7491 Mon Sep 17 00:00:00 2001 From: Jonathan Samines Date: Wed, 9 Sep 2020 01:27:25 -0600 Subject: [PATCH] Convert integration tests to be self-hosted * Reconfigure xo and eslint to purposely ignore bad configurations * Rewrite expectations to use snapshots * Fix trailing symbols strip functionality for output cleanup * Use posix path relative resolution on tests filename snapshots * Normalize posix paths on test snapshots --- .../environment-variables/ava.config.js | 3 - .../dir-a-wrapper/dir-a/dir-a-wrapper-3.js | 5 - .../dir-a-wrapper/dir-a/dir-a-wrapper-4.js | 5 - .../resolve-dir/dir-a/dir-a-base-1.js | 5 - .../resolve-dir/dir-a/dir-a-base-2.js | 5 - .../fixture/pkg-conf/resolve-dir/package.json | 7 - test-tap/integration/concurrency.js | 42 ------ test-tap/integration/config.js | 54 -------- test-tap/integration/environment-variables.js | 35 ----- test-tap/integration/extensions.js | 22 --- test-tap/integration/globs.js | 30 ----- test-tap/integration/line-numbers.js | 108 --------------- test-tap/integration/node-arguments.js | 24 ---- .../concurrency/fixtures/concurrency.js | 2 +- test/concurrency/fixtures/package.json | 7 + test/concurrency/snapshots/test.js.md | 29 ++++ test/concurrency/snapshots/test.js.snap | Bin 0 -> 238 bytes test/concurrency/test.js | 30 +++++ .../fixtures/config-errors/ava.config.js | 1 + .../fixtures/config-errors}/package.json | 0 test/config/fixtures/config-errors/test.js | 5 + .../dir-a-wrapper/dir-a/dir-a-wrapper-3.js | 6 + .../dir-a-wrapper/dir-a/dir-a-wrapper-4.js | 6 + .../resolve-pkg-dir/dir-a/dir-a-base-1.js | 5 + .../resolve-pkg-dir/dir-a/dir-a-base-2.js | 5 + .../fixtures/resolve-pkg-dir/package.json | 7 + test/config/snapshots/test.js.md | 46 +++++++ test/config/snapshots/test.js.snap | Bin 0 -> 351 bytes test/config/test.js | 57 ++++++++ .../experimental.js | 4 +- .../invalid-configurations.js | 10 +- .../snapshots/invalid-configurations.js.snap | Bin 270 -> 275 bytes .../environment-variables/ava.config.js | 4 + .../environment-variables.js | 2 +- .../environment-variables/package.json | 1 + .../package.json | 0 .../snapshots/test.js.md | 33 +++++ .../snapshots/test.js.snap | Bin 0 -> 334 bytes test/environment-variables/test.js | 35 +++++ .../fixtures}/shared-duplicates/package.json | 0 .../top-level-duplicates/package.json | 0 .../fixtures}/top-level/package.json | 0 test/extensions/snapshots/test.js.md | 17 +++ test/extensions/snapshots/test.js.snap | Bin 0 -> 178 bytes test/extensions/test.js | 17 +++ .../globs/fixtures}/files/package.json | 0 .../fixtures}/ignored-by-watcher/package.json | 0 test/globs/snapshots/test.js.md | 17 +++ test/globs/snapshots/test.js.snap | Bin 0 -> 208 bytes test/globs/test.js | 22 +++ test/helpers/exec.js | 16 ++- .../line-numbers/fixtures}/line-numbers.js | 6 +- test/line-numbers/fixtures/package.json | 7 + test/line-numbers/snapshots/test.js.md | 126 ++++++++++++++++++ test/line-numbers/snapshots/test.js.snap | Bin 0 -> 582 bytes test/line-numbers/test.js | 62 +++++++++ .../node-arguments-from-config.js | 2 +- .../node-arguments-from-config}/package.json | 3 + .../node-arguments-from-config}/setup.js | 0 .../node-arguments}/node-arguments.js | 2 +- .../fixtures/node-arguments/package.json | 7 + test/node-arguments/snapshots/test.js.md | 33 +++++ test/node-arguments/snapshots/test.js.snap | Bin 0 -> 418 bytes test/node-arguments/test.js | 32 +++++ test/snapshot-updates/snapshots/test.js.snap | Bin 454 -> 453 bytes test/snapshot-updates/test.js | 6 +- xo.config.js | 1 + 67 files changed, 649 insertions(+), 367 deletions(-) delete mode 100644 test-tap/fixture/environment-variables/ava.config.js delete mode 100644 test-tap/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-3.js delete mode 100644 test-tap/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-4.js delete mode 100644 test-tap/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-1.js delete mode 100644 test-tap/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-2.js delete mode 100644 test-tap/fixture/pkg-conf/resolve-dir/package.json delete mode 100644 test-tap/integration/concurrency.js delete mode 100644 test-tap/integration/config.js delete mode 100644 test-tap/integration/environment-variables.js delete mode 100644 test-tap/integration/extensions.js delete mode 100644 test-tap/integration/globs.js delete mode 100644 test-tap/integration/line-numbers.js delete mode 100644 test-tap/integration/node-arguments.js rename test-tap/fixture/concurrency/test.js => test/concurrency/fixtures/concurrency.js (52%) create mode 100644 test/concurrency/fixtures/package.json create mode 100644 test/concurrency/snapshots/test.js.md create mode 100644 test/concurrency/snapshots/test.js.snap create mode 100644 test/concurrency/test.js create mode 100644 test/config/fixtures/config-errors/ava.config.js rename {test-tap/fixture/environment-variables => test/config/fixtures/config-errors}/package.json (100%) create mode 100644 test/config/fixtures/config-errors/test.js create mode 100644 test/config/fixtures/resolve-pkg-dir/dir-a-wrapper/dir-a/dir-a-wrapper-3.js create mode 100644 test/config/fixtures/resolve-pkg-dir/dir-a-wrapper/dir-a/dir-a-wrapper-4.js create mode 100644 test/config/fixtures/resolve-pkg-dir/dir-a/dir-a-base-1.js create mode 100644 test/config/fixtures/resolve-pkg-dir/dir-a/dir-a-base-2.js create mode 100644 test/config/fixtures/resolve-pkg-dir/package.json create mode 100644 test/config/snapshots/test.js.md create mode 100644 test/config/snapshots/test.js.snap create mode 100644 test/config/test.js create mode 100644 test/environment-variables/fixtures/environment-variables/ava.config.js rename test-tap/fixture/environment-variables/test.js => test/environment-variables/fixtures/environment-variables/environment-variables.js (71%) create mode 100644 test/environment-variables/fixtures/environment-variables/package.json rename {test-tap/fixture => test/environment-variables/fixtures}/invalid-environment-variables/package.json (100%) create mode 100644 test/environment-variables/snapshots/test.js.md create mode 100644 test/environment-variables/snapshots/test.js.snap create mode 100644 test/environment-variables/test.js rename {test-tap/fixture/invalid-extensions => test/extensions/fixtures}/shared-duplicates/package.json (100%) rename {test-tap/fixture/invalid-extensions => test/extensions/fixtures}/top-level-duplicates/package.json (100%) rename {test-tap/fixture/invalid-extensions => test/extensions/fixtures}/top-level/package.json (100%) create mode 100644 test/extensions/snapshots/test.js.md create mode 100644 test/extensions/snapshots/test.js.snap create mode 100644 test/extensions/test.js rename {test-tap/fixture/invalid-globs => test/globs/fixtures}/files/package.json (100%) rename {test-tap/fixture/invalid-globs => test/globs/fixtures}/ignored-by-watcher/package.json (100%) create mode 100644 test/globs/snapshots/test.js.md create mode 100644 test/globs/snapshots/test.js.snap create mode 100644 test/globs/test.js rename {test-tap/fixture => test/line-numbers/fixtures}/line-numbers.js (60%) create mode 100644 test/line-numbers/fixtures/package.json create mode 100644 test/line-numbers/snapshots/test.js.md create mode 100644 test/line-numbers/snapshots/test.js.snap create mode 100644 test/line-numbers/test.js rename test-tap/fixture/node-arguments/test.js => test/node-arguments/fixtures/node-arguments-from-config/node-arguments-from-config.js (84%) rename {test-tap/fixture/node-arguments => test/node-arguments/fixtures/node-arguments-from-config}/package.json (72%) rename {test-tap/fixture/node-arguments => test/node-arguments/fixtures/node-arguments-from-config}/setup.js (100%) rename {test-tap/fixture => test/node-arguments/fixtures/node-arguments}/node-arguments.js (87%) create mode 100644 test/node-arguments/fixtures/node-arguments/package.json create mode 100644 test/node-arguments/snapshots/test.js.md create mode 100644 test/node-arguments/snapshots/test.js.snap create mode 100644 test/node-arguments/test.js diff --git a/test-tap/fixture/environment-variables/ava.config.js b/test-tap/fixture/environment-variables/ava.config.js deleted file mode 100644 index e64b98605..000000000 --- a/test-tap/fixture/environment-variables/ava.config.js +++ /dev/null @@ -1,3 +0,0 @@ -export default { - environmentVariables: {MY_ENVIRONMENT_VARIABLE: 'some value'} -}; diff --git a/test-tap/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-3.js b/test-tap/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-3.js deleted file mode 100644 index 91dbe5b2c..000000000 --- a/test-tap/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-3.js +++ /dev/null @@ -1,5 +0,0 @@ -const test = require('../../../../../..'); - -test('test', t => { - t.pass(); -}); diff --git a/test-tap/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-4.js b/test-tap/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-4.js deleted file mode 100644 index 91dbe5b2c..000000000 --- a/test-tap/fixture/pkg-conf/resolve-dir/dir-a-wrapper/dir-a/dir-a-wrapper-4.js +++ /dev/null @@ -1,5 +0,0 @@ -const test = require('../../../../../..'); - -test('test', t => { - t.pass(); -}); diff --git a/test-tap/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-1.js b/test-tap/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-1.js deleted file mode 100644 index ce4a7c0bd..000000000 --- a/test-tap/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-1.js +++ /dev/null @@ -1,5 +0,0 @@ -const test = require('../../../../..'); - -test('test', t => { - t.pass(); -}); diff --git a/test-tap/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-2.js b/test-tap/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-2.js deleted file mode 100644 index ce4a7c0bd..000000000 --- a/test-tap/fixture/pkg-conf/resolve-dir/dir-a/dir-a-base-2.js +++ /dev/null @@ -1,5 +0,0 @@ -const test = require('../../../../..'); - -test('test', t => { - t.pass(); -}); diff --git a/test-tap/fixture/pkg-conf/resolve-dir/package.json b/test-tap/fixture/pkg-conf/resolve-dir/package.json deleted file mode 100644 index 2e6f0c272..000000000 --- a/test-tap/fixture/pkg-conf/resolve-dir/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "application-name", - "version": "0.0.1", - "ava": { - "files": ["dir-a/*.js"] - } -} diff --git a/test-tap/integration/concurrency.js b/test-tap/integration/concurrency.js deleted file mode 100644 index e4c1177ad..000000000 --- a/test-tap/integration/concurrency.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; -const {test} = require('tap'); -const {execCli} = require('../helper/cli'); - -test('bails when --concurrency is provided without value', t => { - execCli(['--concurrency', 'test.js'], {dirname: 'fixture/concurrency'}, (err, stdout, stderr) => { - t.is(err.code, 1); - t.match(stderr, 'The --concurrency or -c flag must be provided with a nonnegative integer.'); - t.end(); - }); -}); - -test('bails when --concurrency is provided with an input that is a string', t => { - execCli(['--concurrency=foo', 'test.js'], {dirname: 'fixture/concurrency'}, (err, stdout, stderr) => { - t.is(err.code, 1); - t.match(stderr, 'The --concurrency or -c flag must be provided with a nonnegative integer.'); - t.end(); - }); -}); - -test('bails when --concurrency is provided with an input that is a float', t => { - execCli(['--concurrency=4.7', 'test.js'], {dirname: 'fixture/concurrency'}, (err, stdout, stderr) => { - t.is(err.code, 1); - t.match(stderr, 'The --concurrency or -c flag must be provided with a nonnegative integer.'); - t.end(); - }); -}); - -test('bails when --concurrency is provided with an input that is negative', t => { - execCli(['--concurrency=-1', 'test.js'], {dirname: 'fixture/concurrency'}, (err, stdout, stderr) => { - t.is(err.code, 1); - t.match(stderr, 'The --concurrency or -c flag must be provided with a nonnegative integer.'); - t.end(); - }); -}); - -test('works when --concurrency is provided with a value', t => { - execCli(['--concurrency=1', 'test.js'], {dirname: 'fixture/concurrency'}, err => { - t.ifError(err); - t.end(); - }); -}); diff --git a/test-tap/integration/config.js b/test-tap/integration/config.js deleted file mode 100644 index 25df91996..000000000 --- a/test-tap/integration/config.js +++ /dev/null @@ -1,54 +0,0 @@ -'use strict'; -const fs = require('fs'); -const path = require('path'); -const {test} = require('tap'); -const execa = require('execa'); -const tempy = require('tempy'); -const {execCli} = require('../helper/cli'); - -test('formats errors from ava.config.js', t => { - execCli(['es2015.js'], {dirname: 'fixture/load-config/throws'}, (err, stdout, stderr) => { - t.ok(err); - - const lines = stderr.split('\n'); - t.is(lines[0], ''); - t.match(lines[1], /Error loading ava\.config\.js:/); - t.is(lines[2], ''); - t.match(lines[3], /ava\.config\.js/); - t.match(lines[4], /foo/); - t.end(); - }); -}); - -test('pkg-conf(resolve-dir): works as expected when run from the package.json directory', t => { - execCli(['--verbose'], {dirname: 'fixture/pkg-conf/resolve-dir'}, (err, stdout) => { - t.ifError(err); - t.match(stdout, /dir-a-base-1/); - t.match(stdout, /dir-a-base-2/); - t.notMatch(stdout, /dir-a-wrapper/); - t.notMatch(stdout, /dir-a-wrapper/); - t.end(); - }); -}); - -test('pkg-conf(resolve-dir): resolves tests from the package.json dir if none are specified on cli', t => { - execCli(['--verbose'], {dirname: 'fixture/pkg-conf/resolve-dir/dir-a-wrapper'}, (err, stdout) => { - t.ifError(err); - t.match(stdout, /dir-a-base-1/); - t.match(stdout, /dir-a-base-2/); - t.notMatch(stdout, /dir-a-wrapper/); - t.notMatch(stdout, /dir-a-wrapper/); - t.end(); - }); -}); - -test('use current working directory if `package.json` is not found', () => { - const cwd = tempy.directory(); - const testFilePath = path.join(cwd, 'test.js'); - const cliPath = require.resolve('../../cli.js'); - const avaPath = require.resolve('../../'); - - fs.writeFileSync(testFilePath, `const test = require(${JSON.stringify(avaPath)});\ntest('test', t => { t.pass(); });`); - - return execa(process.execPath, [cliPath], {cwd, env: {AVA_FORCE_CI: 'ci'}}); -}); diff --git a/test-tap/integration/environment-variables.js b/test-tap/integration/environment-variables.js deleted file mode 100644 index fc06a97a3..000000000 --- a/test-tap/integration/environment-variables.js +++ /dev/null @@ -1,35 +0,0 @@ -'use strict'; -const {test} = require('tap'); -const figures = require('figures'); -const {execCli} = require('../helper/cli'); - -test('sets default environment variables from the config', t => { - execCli(['test.js'], {dirname: 'fixture/environment-variables'}, (err, stdout) => { - t.ifError(err); - t.match(stdout, /1 test passed/); - t.end(); - }); -}); - -test('overrides environment variables provided through the CLI', t => { - const env = {MY_ENVIRONMENT_VARIABLE: 'some value (updated)'}; - - execCli(['test.js'], {dirname: 'fixture/environment-variables', env}, (err, stdout) => { - t.ifError(err); - t.match(stdout, /1 test passed/); - t.end(); - }); -}); - -test('errors if environment variables are not string values', t => { - execCli(['es2015.js'], {dirname: 'fixture/invalid-environment-variables'}, (err, stdout, stderr) => { - t.ok(err); - - let expectedOutput = '\n '; - expectedOutput += figures.cross + ' The ’environmentVariables’ configuration must be an object containing string values.'; - expectedOutput += '\n'; - - t.is(stderr, expectedOutput); - t.end(); - }); -}); diff --git a/test-tap/integration/extensions.js b/test-tap/integration/extensions.js deleted file mode 100644 index d670c47cc..000000000 --- a/test-tap/integration/extensions.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; -const {test} = require('tap'); -const figures = require('figures'); -const {execCli} = require('../helper/cli'); - -for (const [where, which, message = '’js’, ’jsx’'] of [ - ['top-level', 'top-level-duplicates'], - ['top-level and babel', 'shared-duplicates', '’jsx’'] -]) { - test(`errors if ${where} extensions include duplicates`, t => { - execCli(['es2015.js'], {dirname: `fixture/invalid-extensions/${which}`}, (err, stdout, stderr) => { - t.ok(err); - - let expectedOutput = '\n '; - expectedOutput += figures.cross + ` Unexpected duplicate extensions in options: ${message}.`; - expectedOutput += '\n'; - - t.is(stderr, expectedOutput); - t.end(); - }); - }); -} diff --git a/test-tap/integration/globs.js b/test-tap/integration/globs.js deleted file mode 100644 index 64c3b6ad4..000000000 --- a/test-tap/integration/globs.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; -const {test} = require('tap'); -const figures = require('figures'); -const {execCli} = require('../helper/cli'); - -test('errors if top-level files is an empty array', t => { - execCli(['es2015.js'], {dirname: 'fixture/invalid-globs/files'}, (err, stdout, stderr) => { - t.ok(err); - - let expectedOutput = '\n '; - expectedOutput += figures.cross + ' The ’files’ configuration must be an array containing glob patterns.'; - expectedOutput += '\n'; - - t.is(stderr, expectedOutput); - t.end(); - }); -}); - -test('errors if top-level ignoredByWatcher is an empty array', t => { - execCli(['es2015.js'], {dirname: 'fixture/invalid-globs/ignored-by-watcher'}, (err, stdout, stderr) => { - t.ok(err); - - let expectedOutput = '\n '; - expectedOutput += figures.cross + ' The ’ignoredByWatcher’ configuration must be an array containing glob patterns.'; - expectedOutput += '\n'; - - t.is(stderr, expectedOutput); - t.end(); - }); -}); diff --git a/test-tap/integration/line-numbers.js b/test-tap/integration/line-numbers.js deleted file mode 100644 index 899dbbf2a..000000000 --- a/test-tap/integration/line-numbers.js +++ /dev/null @@ -1,108 +0,0 @@ -'use strict'; -const {test} = require('tap'); -const {execCli} = require('../helper/cli'); - -test('select test by line number', t => { - execCli([ - 'line-numbers.js', - 'line-numbers.js:3' - ], (error, stdout) => { - t.ifError(error); - t.match(stdout, /unicorn/); - t.match(stdout, /1 test passed/); - t.notMatch(stdout, /todo/); - t.end(); - }); -}); - -test('select serial test by line number', t => { - execCli([ - 'line-numbers.js:11' - ], (error, stdout) => { - t.ifError(error); - t.match(stdout, /cat/); - t.match(stdout, /1 test passed/); - t.notMatch(stdout, /todo/); - t.end(); - }); -}); - -test('select todo test by line number', t => { - execCli([ - 'line-numbers.js:15' - ], (error, stdout) => { - t.ifError(error); - t.match(stdout, /dog/); - t.match(stdout, /1 test todo/); - t.end(); - }); -}); - -test('select tests by line number range', t => { - execCli([ - 'line-numbers.js:5-7' - ], (error, stdout) => { - t.ifError(error); - t.match(stdout, /unicorn/); - t.match(stdout, /rainbow/); - t.match(stdout, /2 tests passed/); - t.notMatch(stdout, /todo/); - t.end(); - }); -}); - -test('select two tests declared on same line', t => { - execCli([ - 'line-numbers.js:18' - ], (error, stdout) => { - t.ifError(error); - t.match(stdout, /sun/); - t.match(stdout, /moon/); - t.match(stdout, /2 tests passed/); - t.notMatch(stdout, /todo/); - t.end(); - }); -}); - -test('select only one of two tests declared on same line', t => { - execCli([ - 'line-numbers.js:19' - ], (error, stdout) => { - t.ifError(error); - t.match(stdout, /moon/); - t.match(stdout, /1 test passed/); - t.notMatch(stdout, /todo/); - t.end(); - }); -}); - -test('no test selected by line number', t => { - execCli([ - 'line-numbers.js:6' - ], (error, stdout) => { - t.ok(error); - t.match(stdout, /Line numbers for line-numbers\.js did not match any tests/); - t.end(); - }); -}); - -test('parent call is not selected', t => { - execCli([ - 'line-numbers.js:23' - ], (error, stdout) => { - t.ok(error); - t.match(stdout, /Line numbers for line-numbers\.js did not match any tests/); - t.end(); - }); -}); - -test('nested call is selected', t => { - execCli([ - 'line-numbers.js:24' - ], (error, stdout) => { - t.ifError(error); - t.match(stdout, /nested/); - t.match(stdout, /1 test passed/); - t.end(); - }); -}); diff --git a/test-tap/integration/node-arguments.js b/test-tap/integration/node-arguments.js deleted file mode 100644 index b807808e8..000000000 --- a/test-tap/integration/node-arguments.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; -const {test} = require('tap'); -const {execCli} = require('../helper/cli'); - -test('passes node arguments to workers', t => { - t.plan(1); - execCli(['--node-arguments="--throw-deprecation --zero-fill-buffers"', 'node-arguments.js'], - (err, stdout, stderr) => t.ifError(err, null, {stdout, stderr})); -}); - -test('reads node arguments from config', t => { - t.plan(1); - execCli(['test.js'], { - dirname: 'fixture/node-arguments' - }, (err, stdout, stderr) => t.ifError(err, null, {stdout, stderr})); -}); - -test('detects incomplete --node-arguments', t => { - t.plan(2); - execCli(['--node-arguments="--foo=\'bar"', 'node-arguments.js'], (err, stdout, stderr) => { - t.ok(err); - t.match(stderr, /Could not parse `--node-arguments` value. Make sure all strings are closed and backslashes are used correctly./); - }); -}); diff --git a/test-tap/fixture/concurrency/test.js b/test/concurrency/fixtures/concurrency.js similarity index 52% rename from test-tap/fixture/concurrency/test.js rename to test/concurrency/fixtures/concurrency.js index 5743bf4e2..d4747061d 100644 --- a/test-tap/fixture/concurrency/test.js +++ b/test/concurrency/fixtures/concurrency.js @@ -1,4 +1,4 @@ -const test = require('../../..'); +const test = require('ava'); test('works', t => { t.pass(); diff --git a/test/concurrency/fixtures/package.json b/test/concurrency/fixtures/package.json new file mode 100644 index 000000000..a0befd106 --- /dev/null +++ b/test/concurrency/fixtures/package.json @@ -0,0 +1,7 @@ +{ + "ava": { + "files": [ + "*.js" + ] + } +} diff --git a/test/concurrency/snapshots/test.js.md b/test/concurrency/snapshots/test.js.md new file mode 100644 index 000000000..16c01cfbe --- /dev/null +++ b/test/concurrency/snapshots/test.js.md @@ -0,0 +1,29 @@ +# Snapshot report for `test/concurrency/test.js` + +The actual snapshot is saved in `test.js.snap`. + +Generated by [AVA](https://avajs.dev). + +## bails when --concurrency is provided with an input that is a float + +> fails with message + + 'The --concurrency or -c flag must be provided with a nonnegative integer.' + +## bails when --concurrency is provided with an input that is a string + +> fails with message + + 'The --concurrency or -c flag must be provided with a nonnegative integer.' + +## bails when --concurrency is provided with an input that is negative + +> fails with message + + 'The --concurrency or -c flag must be provided with a nonnegative integer.' + +## bails when --concurrency is provided without value + +> fails with message + + 'The --concurrency or -c flag must be provided with a nonnegative integer.' diff --git a/test/concurrency/snapshots/test.js.snap b/test/concurrency/snapshots/test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..816ed91000a2c81c6bdb9517cdb731b1ddbe0310 GIT binary patch literal 238 zcmV-gMr0iW*>_P00000000Ba zV_;xlVYqoT!{+F1xk)U2tS3!n3b}+^2N}Vl>wx&k zf@xWapE4f)R$dbC$yYFk5iH6I)EfTq&F39CaiP{C&exn6|A;e!MPq=NnSmW_G9xR4 zAfsnUMyi6YZgPHJa%oXfYF=`sLVl5gZn8pJPGY)3ZfS9eLQ<+iK~a8LW=d*`LV0FM ohC-r3UVdI)YI { + const result = await t.throwsAsync(exec.fixture(['--concurrency', 'concurrency.js'])); + + t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); +}); + +test('bails when --concurrency is provided with an input that is a string', async t => { + const result = await t.throwsAsync(exec.fixture(['--concurrency=foo', 'concurrency.js'])); + + t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); +}); + +test('bails when --concurrency is provided with an input that is a float', async t => { + const result = await t.throwsAsync(exec.fixture(['--concurrency=4.7', 'concurrency.js'])); + + t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); +}); + +test('bails when --concurrency is provided with an input that is negative', async t => { + const result = await t.throwsAsync(exec.fixture(['--concurrency=-1', 'concurrency.js'])); + + t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); +}); + +test('works when --concurrency is provided with a value', async t => { + await t.notThrowsAsync(exec.fixture(['--concurrency=1', 'concurrency.js'])); +}); diff --git a/test/config/fixtures/config-errors/ava.config.js b/test/config/fixtures/config-errors/ava.config.js new file mode 100644 index 000000000..cd8e188c7 --- /dev/null +++ b/test/config/fixtures/config-errors/ava.config.js @@ -0,0 +1 @@ +throw new Error('foo'); diff --git a/test-tap/fixture/environment-variables/package.json b/test/config/fixtures/config-errors/package.json similarity index 100% rename from test-tap/fixture/environment-variables/package.json rename to test/config/fixtures/config-errors/package.json diff --git a/test/config/fixtures/config-errors/test.js b/test/config/fixtures/config-errors/test.js new file mode 100644 index 000000000..5ca41efa1 --- /dev/null +++ b/test/config/fixtures/config-errors/test.js @@ -0,0 +1,5 @@ +const test = require('ava'); + +test('test', t => { + t.pass(); +}); diff --git a/test/config/fixtures/resolve-pkg-dir/dir-a-wrapper/dir-a/dir-a-wrapper-3.js b/test/config/fixtures/resolve-pkg-dir/dir-a-wrapper/dir-a/dir-a-wrapper-3.js new file mode 100644 index 000000000..159662d3d --- /dev/null +++ b/test/config/fixtures/resolve-pkg-dir/dir-a-wrapper/dir-a/dir-a-wrapper-3.js @@ -0,0 +1,6 @@ +// eslint-disable-next-line ava/no-ignored-test-files +const test = require('ava'); + +test('test', t => { + t.pass(); +}); diff --git a/test/config/fixtures/resolve-pkg-dir/dir-a-wrapper/dir-a/dir-a-wrapper-4.js b/test/config/fixtures/resolve-pkg-dir/dir-a-wrapper/dir-a/dir-a-wrapper-4.js new file mode 100644 index 000000000..159662d3d --- /dev/null +++ b/test/config/fixtures/resolve-pkg-dir/dir-a-wrapper/dir-a/dir-a-wrapper-4.js @@ -0,0 +1,6 @@ +// eslint-disable-next-line ava/no-ignored-test-files +const test = require('ava'); + +test('test', t => { + t.pass(); +}); diff --git a/test/config/fixtures/resolve-pkg-dir/dir-a/dir-a-base-1.js b/test/config/fixtures/resolve-pkg-dir/dir-a/dir-a-base-1.js new file mode 100644 index 000000000..5ca41efa1 --- /dev/null +++ b/test/config/fixtures/resolve-pkg-dir/dir-a/dir-a-base-1.js @@ -0,0 +1,5 @@ +const test = require('ava'); + +test('test', t => { + t.pass(); +}); diff --git a/test/config/fixtures/resolve-pkg-dir/dir-a/dir-a-base-2.js b/test/config/fixtures/resolve-pkg-dir/dir-a/dir-a-base-2.js new file mode 100644 index 000000000..5ca41efa1 --- /dev/null +++ b/test/config/fixtures/resolve-pkg-dir/dir-a/dir-a-base-2.js @@ -0,0 +1,5 @@ +const test = require('ava'); + +test('test', t => { + t.pass(); +}); diff --git a/test/config/fixtures/resolve-pkg-dir/package.json b/test/config/fixtures/resolve-pkg-dir/package.json new file mode 100644 index 000000000..4cc2f3b9c --- /dev/null +++ b/test/config/fixtures/resolve-pkg-dir/package.json @@ -0,0 +1,7 @@ +{ + "name": "application-name", + "version": "0.0.1", + "ava": { + "files": ["dir-a/*.js"] + } + } diff --git a/test/config/snapshots/test.js.md b/test/config/snapshots/test.js.md new file mode 100644 index 000000000..4115fcb77 --- /dev/null +++ b/test/config/snapshots/test.js.md @@ -0,0 +1,46 @@ +# Snapshot report for `test/config/test.js` + +The actual snapshot is saved in `test.js.snap`. + +Generated by [AVA](https://avajs.dev). + +## pkg-conf(resolve-dir): resolves tests from the package.json dir if none are specified on cli + +> resolves test files from configuration + + [ + { + file: '../dir-a/dir-a-base-1.js', + title: 'test', + }, + { + file: '../dir-a/dir-a-base-2.js', + title: 'test', + }, + ] + +## pkg-conf(resolve-dir): works as expected when run from the package.json directory + +> resolves test files from configuration + + [ + { + file: 'dir-a/dir-a-base-1.js', + title: 'test', + }, + { + file: 'dir-a/dir-a-base-2.js', + title: 'test', + }, + ] + +## use current working directory if `package.json` is not found + +> resolves test files without configuration + + [ + { + file: 'test.js', + title: 'test name', + }, + ] diff --git a/test/config/snapshots/test.js.snap b/test/config/snapshots/test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..4c31532feab9da2d1363b3aef742ace3f204bb09 GIT binary patch literal 351 zcmV-l0igatRzV2P3lqkTwHi2Ot(^WD{g$bu21MtYl<_ zvH1D<85p@37?~ItxfvO~AsT_KG7!xOHe(@>xg3aZ!pvavPs&P7E@5PXGX(?$z)F8Z zbTJq+qA6uYRmuytkRPaqNraJ^fss{^ktHoNCl$sKP01|MP1FaIx=D$}sk(-GS;c5N zSW7ZX5L#GDQj1H-G1-VHlaT_INe4(95eiU7a4_1yV { + const options = { + cwd: exec.cwd('config-errors') + }; + + const result = await t.throwsAsync(exec.fixture(['test.js'], options)); + + const lines = result.stderr.split('\n'); + + t.is(lines[0], ''); + t.regex(lines[1], /Error loading ava\.config\.js:/); + t.is(lines[2], ''); + t.regex(lines[3], /ava\.config\.js/); + t.regex(lines[4], /foo/); +}); + +test('pkg-conf(resolve-dir): works as expected when run from the package.json directory', async t => { + const options = { + cwd: exec.cwd('resolve-pkg-dir') + }; + + const result = await exec.fixture([], options); + + t.snapshot(result.stats.passed, 'resolves test files from configuration'); +}); + +test('pkg-conf(resolve-dir): resolves tests from the package.json dir if none are specified on cli', async t => { + const options = { + cwd: exec.cwd('resolve-pkg-dir/dir-a-wrapper') + }; + + const result = await exec.fixture(['--verbose'], options); + + t.snapshot(result.stats.passed, 'resolves test files from configuration'); +}); + +test('use current working directory if `package.json` is not found', async t => { + const cwd = tempy.directory(); + const testFilePath = path.join(cwd, 'test.js'); + const avaPath = require.resolve('../../'); + + fs.writeFileSync(testFilePath, `const test = require(${JSON.stringify(avaPath)});\ntest('test name', t => { t.pass(); });`); + + const options = { + cwd + }; + + const result = await exec.fixture([], options); + + t.snapshot(result.stats.passed, 'resolves test files without configuration'); +}); diff --git a/test/configurable-module-format/experimental.js b/test/configurable-module-format/experimental.js index 37d297028..d12c2ae52 100644 --- a/test/configurable-module-format/experimental.js +++ b/test/configurable-module-format/experimental.js @@ -1,10 +1,8 @@ const test = require('@ava/test'); const exec = require('../helpers/exec'); -const stripLeadingFigures = string => string.replace(/^\W+/, ''); - test('opt-in is required', async t => { const result = await t.throwsAsync(exec.fixture(['--config', 'not-enabled.config.js'])); t.is(result.exitCode, 1); - t.snapshot(stripLeadingFigures(result.stderr.trim())); + t.snapshot(exec.cleanOutput(result.stderr)); }); diff --git a/test/configurable-module-format/invalid-configurations.js b/test/configurable-module-format/invalid-configurations.js index a780e13db..1df36e353 100644 --- a/test/configurable-module-format/invalid-configurations.js +++ b/test/configurable-module-format/invalid-configurations.js @@ -1,24 +1,22 @@ const test = require('@ava/test'); const exec = require('../helpers/exec'); -const stripLeadingFigures = string => string.replace(/^\W+/, ''); - test('cannot configure how js extensions should be loaded', async t => { const result = await t.throwsAsync(exec.fixture(['--config', 'change-js-loading.config.js'])); - t.snapshot(stripLeadingFigures(result.stderr.trim())); + t.snapshot(exec.cleanOutput(result.stderr)); }); test('cannot configure how cjs extensions should be loaded', async t => { const result = await t.throwsAsync(exec.fixture(['--config', 'change-cjs-loading.config.js'])); - t.snapshot(stripLeadingFigures(result.stderr.trim())); + t.snapshot(exec.cleanOutput(result.stderr)); }); test('cannot configure how mjs extensions should be loaded', async t => { const result = await t.throwsAsync(exec.fixture(['--config', 'change-mjs-loading.config.js'])); - t.snapshot(stripLeadingFigures(result.stderr.trim())); + t.snapshot(exec.cleanOutput(result.stderr)); }); test('custom extensions must be either commonjs or module', async t => { const result = await t.throwsAsync(exec.fixture(['--config', 'bad-custom-type.config.js'])); - t.snapshot(stripLeadingFigures(result.stderr.trim())); + t.snapshot(exec.cleanOutput(result.stderr)); }); diff --git a/test/configurable-module-format/snapshots/invalid-configurations.js.snap b/test/configurable-module-format/snapshots/invalid-configurations.js.snap index 100a0f7b99b72642dcc572f0d41bdb3fd21465c8..a26ad210bc11bc14d7b918ed0bcbe47f3c1c0619 100644 GIT binary patch delta 194 zcmV;z06qVX0+RxNK~_N^Q*L2!b7*gLAa*he0sxtM{YQlFx4sD^Ah&Ow;}IW=2mk;8 z00003%VS_*U||U3Wt-3}agIyDcZJxB8n3^M3?PsW#GMh<;ZhZMMN$rNOzLa@j9^h|pw{40KDBKJw53-Fq+7>^7j5rjk%wC`F^VhlBUscFsI@bqI$Wyau1LxVA+E`*=Uh)@i4Z= r-WOpk%%l>qhTPKP5{0Bxu+jOsx%qhzb0A6}jsY?N^0Jh3@Bsh-G}2N_ diff --git a/test/environment-variables/fixtures/environment-variables/ava.config.js b/test/environment-variables/fixtures/environment-variables/ava.config.js new file mode 100644 index 000000000..ebbfe1444 --- /dev/null +++ b/test/environment-variables/fixtures/environment-variables/ava.config.js @@ -0,0 +1,4 @@ +export default { + environmentVariables: {MY_ENVIRONMENT_VARIABLE: 'some value'}, + files: ['*.js'] +}; diff --git a/test-tap/fixture/environment-variables/test.js b/test/environment-variables/fixtures/environment-variables/environment-variables.js similarity index 71% rename from test-tap/fixture/environment-variables/test.js rename to test/environment-variables/fixtures/environment-variables/environment-variables.js index 9ff79c537..096d09ac7 100644 --- a/test-tap/fixture/environment-variables/test.js +++ b/test/environment-variables/fixtures/environment-variables/environment-variables.js @@ -1,4 +1,4 @@ -const test = require('../../..'); +const test = require('ava'); test('works', t => { t.is(process.env.MY_ENVIRONMENT_VARIABLE, 'some value'); diff --git a/test/environment-variables/fixtures/environment-variables/package.json b/test/environment-variables/fixtures/environment-variables/package.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/test/environment-variables/fixtures/environment-variables/package.json @@ -0,0 +1 @@ +{} diff --git a/test-tap/fixture/invalid-environment-variables/package.json b/test/environment-variables/fixtures/invalid-environment-variables/package.json similarity index 100% rename from test-tap/fixture/invalid-environment-variables/package.json rename to test/environment-variables/fixtures/invalid-environment-variables/package.json diff --git a/test/environment-variables/snapshots/test.js.md b/test/environment-variables/snapshots/test.js.md new file mode 100644 index 000000000..138d60426 --- /dev/null +++ b/test/environment-variables/snapshots/test.js.md @@ -0,0 +1,33 @@ +# Snapshot report for `test/environment-variables/test.js` + +The actual snapshot is saved in `test.js.snap`. + +Generated by [AVA](https://avajs.dev). + +## errors if environment variables are not string values + +> fails with message + + 'The ’environmentVariables’ configuration must be an object containing string values.' + +## overrides environment variables provided through the CLI + +> tests pass + + [ + { + file: 'environment-variables.js', + title: 'works', + }, + ] + +## sets default environment variables from the config + +> tests pass + + [ + { + file: 'environment-variables.js', + title: 'works', + }, + ] diff --git a/test/environment-variables/snapshots/test.js.snap b/test/environment-variables/snapshots/test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..43f12dabab1f70b6e8a86a7a1942f4205949874b GIT binary patch literal 334 zcmV-U0kQr;RzVp>&WggBfOM!0j~|N&000000009E zVPIfjX2^4xm&Kt`ILjl8Yw`ra1%8YSAaE3jBOALTc+5|pG4B_bII-kPG9y^D3#i~? zSns_hX61L<1HS&-#lQ3oBUtnUBgi~Q zKLaBd10y2?BR35AR|j!W=<-MBaxa{mRXdamz$bbqFa_&l$n^6lUl5oRg9*IwIs6yp^LRVzbLzS zczJ@AL69*bBqLSfQNv6m^TJ@p0fiNk^YhX&(@TpIOEUBG6mm<8OB9k)6%z9l^1+S; g$(JN%=4IxkD-@R$fvB>?oKm1u0KgUsl0*Uk07>VD_5c6? literal 0 HcmV?d00001 diff --git a/test/environment-variables/test.js b/test/environment-variables/test.js new file mode 100644 index 000000000..0cb91f851 --- /dev/null +++ b/test/environment-variables/test.js @@ -0,0 +1,35 @@ +const test = require('@ava/test'); +const exec = require('../helpers/exec'); + +test('sets default environment variables from the config', async t => { + const options = { + cwd: exec.cwd('environment-variables') + }; + + const results = await exec.fixture(['environment-variables.js'], options); + + t.snapshot(results.stats.passed, 'tests pass'); +}); + +test('overrides environment variables provided through the CLI', async t => { + const options = { + cwd: exec.cwd('environment-variables'), + env: { + MY_ENVIRONMENT_VARIABLE: 'some value (updated)' + } + }; + + const results = await exec.fixture(['environment-variables.js'], options); + + t.snapshot(results.stats.passed, 'tests pass'); +}); + +test('errors if environment variables are not string values', async t => { + const options = { + cwd: exec.cwd('invalid-environment-variables') + }; + + const result = await t.throwsAsync(exec.fixture(['environment-variables.js'], options)); + + t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); +}); diff --git a/test-tap/fixture/invalid-extensions/shared-duplicates/package.json b/test/extensions/fixtures/shared-duplicates/package.json similarity index 100% rename from test-tap/fixture/invalid-extensions/shared-duplicates/package.json rename to test/extensions/fixtures/shared-duplicates/package.json diff --git a/test-tap/fixture/invalid-extensions/top-level-duplicates/package.json b/test/extensions/fixtures/top-level-duplicates/package.json similarity index 100% rename from test-tap/fixture/invalid-extensions/top-level-duplicates/package.json rename to test/extensions/fixtures/top-level-duplicates/package.json diff --git a/test-tap/fixture/invalid-extensions/top-level/package.json b/test/extensions/fixtures/top-level/package.json similarity index 100% rename from test-tap/fixture/invalid-extensions/top-level/package.json rename to test/extensions/fixtures/top-level/package.json diff --git a/test/extensions/snapshots/test.js.md b/test/extensions/snapshots/test.js.md new file mode 100644 index 000000000..693d6a568 --- /dev/null +++ b/test/extensions/snapshots/test.js.md @@ -0,0 +1,17 @@ +# Snapshot report for `test/extensions/test.js` + +The actual snapshot is saved in `test.js.snap`. + +Generated by [AVA](https://avajs.dev). + +## errors if top-level and babel extensions include duplicates + +> fails with message + + 'Unexpected duplicate extensions in options: ’jsx’.' + +## errors if top-level extensions include duplicates + +> fails with message + + 'Unexpected duplicate extensions in options: ’js’, ’jsx’.' diff --git a/test/extensions/snapshots/test.js.snap b/test/extensions/snapshots/test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..58e5b89be2c662344d22c7b5303c308b5c118ce2 GIT binary patch literal 178 zcmV;j08RfvRzVcNRGxPI`6*BV_@(W5pOe=*) g4KuTffrJi(RRJXRP)su;*)*^j0N1;n4$J@m057LTi~s-t literal 0 HcmV?d00001 diff --git a/test/extensions/test.js b/test/extensions/test.js new file mode 100644 index 000000000..1a908d98e --- /dev/null +++ b/test/extensions/test.js @@ -0,0 +1,17 @@ +const test = require('@ava/test'); +const exec = require('../helpers/exec'); + +for (const [where, which] of [ + ['top-level', 'top-level-duplicates'], + ['top-level and babel', 'shared-duplicates'] +]) { + test(`errors if ${where} extensions include duplicates`, async t => { + const options = { + cwd: exec.cwd(which) + }; + + const result = await t.throwsAsync(exec.fixture([], options)); + + t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); + }); +} diff --git a/test-tap/fixture/invalid-globs/files/package.json b/test/globs/fixtures/files/package.json similarity index 100% rename from test-tap/fixture/invalid-globs/files/package.json rename to test/globs/fixtures/files/package.json diff --git a/test-tap/fixture/invalid-globs/ignored-by-watcher/package.json b/test/globs/fixtures/ignored-by-watcher/package.json similarity index 100% rename from test-tap/fixture/invalid-globs/ignored-by-watcher/package.json rename to test/globs/fixtures/ignored-by-watcher/package.json diff --git a/test/globs/snapshots/test.js.md b/test/globs/snapshots/test.js.md new file mode 100644 index 000000000..33110a7fa --- /dev/null +++ b/test/globs/snapshots/test.js.md @@ -0,0 +1,17 @@ +# Snapshot report for `test/globs/test.js` + +The actual snapshot is saved in `test.js.snap`. + +Generated by [AVA](https://avajs.dev). + +## errors if top-level files is an empty array + +> fails with message + + 'The ’files’ configuration must be an array containing glob patterns.' + +## errors if top-level ignoredByWatcher is an empty array + +> fails with message + + 'The ’ignoredByWatcher’ configuration must be an array containing glob patterns.' diff --git a/test/globs/snapshots/test.js.snap b/test/globs/snapshots/test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..9b11766cc2e4fd343011f0ced7dd11e1676690fb GIT binary patch literal 208 zcmV;>05AVRRzVYpRiuF)T4ThSUnVy$ll$zpH8J<{@oRL~Yi3I@c KWB&p10001Qqf%o4 literal 0 HcmV?d00001 diff --git a/test/globs/test.js b/test/globs/test.js new file mode 100644 index 000000000..229f97e5b --- /dev/null +++ b/test/globs/test.js @@ -0,0 +1,22 @@ +const test = require('@ava/test'); +const exec = require('../helpers/exec'); + +test('errors if top-level files is an empty array', async t => { + const options = { + cwd: exec.cwd('files') + }; + + const result = await t.throwsAsync(exec.fixture([], options)); + + t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); +}); + +test('errors if top-level ignoredByWatcher is an empty array', async t => { + const options = { + cwd: exec.cwd('ignored-by-watcher') + }; + + const result = await t.throwsAsync(exec.fixture([], options)); + + t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); +}); diff --git a/test/helpers/exec.js b/test/helpers/exec.js index cc85c1761..4834a0fb5 100644 --- a/test/helpers/exec.js +++ b/test/helpers/exec.js @@ -4,13 +4,15 @@ const v8 = require('v8'); const test = require('@ava/test'); const execa = require('execa'); const defaultsDeep = require('lodash/defaultsDeep'); +const replaceString = require('replace-string'); const cliPath = path.resolve(__dirname, '../../cli.js'); const ttySimulator = path.join(__dirname, './simulate-tty.js'); const serialization = process.versions.node >= '12.16.0' ? 'advanced' : 'json'; -const normalizePath = (root, file) => path.posix.normalize(path.relative(root, file)); +const normalizePosixPath = string => replaceString(string, '\\', '/'); +const normalizePath = (root, file) => normalizePosixPath(path.posix.normalize(path.relative(root, file))); const compareStatObjects = (a, b) => { if (a.file < b.file) { @@ -28,8 +30,11 @@ const compareStatObjects = (a, b) => { return 1; }; +exports.cwd = (...paths) => path.join(path.dirname(test.meta.file), 'fixtures', ...paths); +exports.cleanOutput = string => string.replace(/^\W+/, '').replace(/\W+\n+$/g, '').trim(); + exports.fixture = async (args, options = {}) => { - const cwd = path.join(path.dirname(test.meta.file), 'fixtures'); + const cwd = options.cwd || exports.cwd(); const running = execa.node(cliPath, args, defaultsDeep({ env: { AVA_EMIT_RUN_STATUS_OVER_IPC: 'I\'ll find a payphone baby / Take some time to talk to you' @@ -51,6 +56,7 @@ exports.fixture = async (args, options = {}) => { failedHooks: [], passed: [], skipped: [], + todo: [], uncaughtExceptions: [], unsavedSnapshots: [], getError(statObject) { @@ -78,6 +84,11 @@ exports.fixture = async (args, options = {}) => { stats.skipped.push({title, file: normalizePath(cwd, testFile)}); } + if (statusEvent.todo) { + const {title, testFile} = statusEvent; + stats.todo.push({title, file: normalizePath(cwd, testFile)}); + } + break; } @@ -124,6 +135,7 @@ exports.fixture = async (args, options = {}) => { stats.failedHooks.sort(compareStatObjects); stats.passed.sort(compareStatObjects); stats.skipped.sort(compareStatObjects); + stats.todo.sort(compareStatObjects); stats.unsavedSnapshots.sort(compareStatObjects); } }; diff --git a/test-tap/fixture/line-numbers.js b/test/line-numbers/fixtures/line-numbers.js similarity index 60% rename from test-tap/fixture/line-numbers.js rename to test/line-numbers/fixtures/line-numbers.js index a1a2a58d1..cc165dec7 100644 --- a/test-tap/fixture/line-numbers.js +++ b/test/line-numbers/fixtures/line-numbers.js @@ -1,4 +1,4 @@ -const test = require('../..'); +const test = require('ava'); test('unicorn', t => { t.pass(); @@ -14,11 +14,11 @@ test.serial('cat', t => { test.todo('dog'); -/* eslint-disable max-statements-per-line */ +/* eslint-disable max-statements-per-line, ava/no-inline-assertions */ test('sun', t => t.pass()); test('moon', t => { t.pass(); }); -/* eslint-enable max-statements-per-line */ +/* eslint-enable max-statements-per-line, ava/no-inline-assertions */ (() => { test('nested call', t => { diff --git a/test/line-numbers/fixtures/package.json b/test/line-numbers/fixtures/package.json new file mode 100644 index 000000000..a0befd106 --- /dev/null +++ b/test/line-numbers/fixtures/package.json @@ -0,0 +1,7 @@ +{ + "ava": { + "files": [ + "*.js" + ] + } +} diff --git a/test/line-numbers/snapshots/test.js.md b/test/line-numbers/snapshots/test.js.md new file mode 100644 index 000000000..eff67de3a --- /dev/null +++ b/test/line-numbers/snapshots/test.js.md @@ -0,0 +1,126 @@ +# Snapshot report for `test/line-numbers/test.js` + +The actual snapshot is saved in `test.js.snap`. + +Generated by [AVA](https://avajs.dev). + +## nested call is selected + +> no todo tests are selected + + [] + +> selected tests pass + + [ + { + file: 'line-numbers.js', + title: 'nested call', + }, + ] + +## no test selected by line number + +> fails with message + + 'Line numbers for line-numbers.js did not match any tests' + +## parent call is not selected + +> fails with message + + 'Line numbers for line-numbers.js did not match any tests' + +## select only one of two tests declared on same line + +> no todo tests are selected + + [] + +> selected tests pass + + [ + { + file: 'line-numbers.js', + title: 'moon', + }, + ] + +## select serial test by line number + +> no todo tests are selected + + [] + +> selected tests pass + + [ + { + file: 'line-numbers.js', + title: 'cat', + }, + ] + +## select test by line number + +> no todo tests are selected + + [] + +> selected tests pass + + [ + { + file: 'line-numbers.js', + title: 'unicorn', + }, + ] + +## select tests by line number range + +> no todo tests are selected + + [] + +> selected tests pass + + [ + { + file: 'line-numbers.js', + title: 'rainbow', + }, + { + file: 'line-numbers.js', + title: 'unicorn', + }, + ] + +## select todo test by line number + +> selected todo test passes + + [ + { + file: 'line-numbers.js', + title: 'dog', + }, + ] + +## select two tests declared on same line + +> no todo tests are selected + + [] + +> selected tests pass + + [ + { + file: 'line-numbers.js', + title: 'moon', + }, + { + file: 'line-numbers.js', + title: 'sun', + }, + ] diff --git a/test/line-numbers/snapshots/test.js.snap b/test/line-numbers/snapshots/test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..4ed4624c95adaec351c6db3ef4fee90c59ec6eb6 GIT binary patch literal 582 zcmV-M0=fM`RzVqf00000000A1 zU}Rw6WT=pMq!rLn8-C*Kq1~|+*+NVVAfODzML;ztOiom|yeT+;Y4L^C^2>`ZFo8v< zLa{$k! zF)-Ybl#;&S<@VHE=<4*|2&O%ZV9{D2_FF!E*RrsEp=|fB-dSw;SDz6qdKieiF3#-f z*>|k&jF@Vgl7Gz%Ca~x;C|<(Oz`)GF4h{=O4hCUHHbF*K$D*RdN=8N)i=Uq#p@fmy z07#nwu>%m}QqRE1#lXnKz{t(W=nc^bWR-zvMz9$Rfz0JVd>Lj2n}1SPYH|r96Pzg^ zAOKeS1E}O55Nk1_DP=}g$_uuTAE<^&gprwnkyVh9B`q^26~^Ju$;?aD%`44KN-ZkZ z%PK}w%UY6If>6v}l$e>9lwVG5V@vZglkDVQd4BrgR{k3&b-C z1Tj@T$ef&5GHgA^otIi%lA5BBoS2g{Y(2@6o1dRIG@Z_zlAk`f%d)RPCBK1Kot|YG zI7X=*)WxNUM8e7-$Y|jM)U5#3t&o;qq=06eLP} { + const result = await exec.fixture(['line-numbers.js', 'line-numbers.js:3']); + + t.snapshot(result.stats.todo, 'no todo tests are selected'); + t.snapshot(result.stats.passed, 'selected tests pass'); +}); + +test('select serial test by line number', async t => { + const result = await exec.fixture(['line-numbers.js:11']); + + t.snapshot(result.stats.todo, 'no todo tests are selected'); + t.snapshot(result.stats.passed, 'selected tests pass'); +}); + +test('select todo test by line number', async t => { + const result = await exec.fixture(['line-numbers.js:15']); + + t.snapshot(result.stats.todo, 'selected todo test passes'); +}); + +test('select tests by line number range', async t => { + const result = await exec.fixture(['line-numbers.js:5-7']); + + t.snapshot(result.stats.todo, 'no todo tests are selected'); + t.snapshot(result.stats.passed, 'selected tests pass'); +}); + +test('select two tests declared on same line', async t => { + const result = await exec.fixture(['line-numbers.js:18']); + + t.snapshot(result.stats.todo, 'no todo tests are selected'); + t.snapshot(result.stats.passed, 'selected tests pass'); +}); + +test('select only one of two tests declared on same line', async t => { + const result = await exec.fixture(['line-numbers.js:19']); + + t.snapshot(result.stats.todo, 'no todo tests are selected'); + t.snapshot(result.stats.passed, 'selected tests pass'); +}); + +test('no test selected by line number', async t => { + const result = await t.throwsAsync(exec.fixture(['line-numbers.js:6'])); + + t.snapshot(exec.cleanOutput(result.stdout), 'fails with message'); +}); + +test('parent call is not selected', async t => { + const result = await t.throwsAsync(exec.fixture(['line-numbers.js:23'])); + + t.snapshot(exec.cleanOutput(result.stdout), 'fails with message'); +}); + +test('nested call is selected', async t => { + const result = await exec.fixture(['line-numbers.js:24']); + + t.snapshot(result.stats.todo, 'no todo tests are selected'); + t.snapshot(result.stats.passed, 'selected tests pass'); +}); diff --git a/test-tap/fixture/node-arguments/test.js b/test/node-arguments/fixtures/node-arguments-from-config/node-arguments-from-config.js similarity index 84% rename from test-tap/fixture/node-arguments/test.js rename to test/node-arguments/fixtures/node-arguments-from-config/node-arguments-from-config.js index 3ec80ebb8..61a4c5feb 100644 --- a/test-tap/fixture/node-arguments/test.js +++ b/test/node-arguments/fixtures/node-arguments-from-config/node-arguments-from-config.js @@ -1,4 +1,4 @@ -const test = require('../../..'); +const test = require('ava'); test('works', t => { t.plan(2); diff --git a/test-tap/fixture/node-arguments/package.json b/test/node-arguments/fixtures/node-arguments-from-config/package.json similarity index 72% rename from test-tap/fixture/node-arguments/package.json rename to test/node-arguments/fixtures/node-arguments-from-config/package.json index eef55b831..83d37be0f 100644 --- a/test-tap/fixture/node-arguments/package.json +++ b/test/node-arguments/fixtures/node-arguments-from-config/package.json @@ -1,5 +1,8 @@ { "ava": { + "files": [ + "*.js" + ], "nodeArguments": [ "--require", "./setup.js" diff --git a/test-tap/fixture/node-arguments/setup.js b/test/node-arguments/fixtures/node-arguments-from-config/setup.js similarity index 100% rename from test-tap/fixture/node-arguments/setup.js rename to test/node-arguments/fixtures/node-arguments-from-config/setup.js diff --git a/test-tap/fixture/node-arguments.js b/test/node-arguments/fixtures/node-arguments/node-arguments.js similarity index 87% rename from test-tap/fixture/node-arguments.js rename to test/node-arguments/fixtures/node-arguments/node-arguments.js index 781743abf..765f9531c 100644 --- a/test-tap/fixture/node-arguments.js +++ b/test/node-arguments/fixtures/node-arguments/node-arguments.js @@ -1,4 +1,4 @@ -const test = require('../..'); +const test = require('ava'); test('exec arguments includes --throw-deprecation and --zero-fill-buffers', t => { t.plan(2); diff --git a/test/node-arguments/fixtures/node-arguments/package.json b/test/node-arguments/fixtures/node-arguments/package.json new file mode 100644 index 000000000..a0befd106 --- /dev/null +++ b/test/node-arguments/fixtures/node-arguments/package.json @@ -0,0 +1,7 @@ +{ + "ava": { + "files": [ + "*.js" + ] + } +} diff --git a/test/node-arguments/snapshots/test.js.md b/test/node-arguments/snapshots/test.js.md new file mode 100644 index 000000000..b44239fd0 --- /dev/null +++ b/test/node-arguments/snapshots/test.js.md @@ -0,0 +1,33 @@ +# Snapshot report for `test/node-arguments/test.js` + +The actual snapshot is saved in `test.js.snap`. + +Generated by [AVA](https://avajs.dev). + +## detects incomplete --node-arguments + +> fails with message + + 'Could not parse `--node-arguments` value. Make sure all strings are closed and backslashes are used correctly.' + +## passed node arguments to workers + +> tests pass + + [ + { + file: 'node-arguments.js', + title: 'exec arguments includes --throw-deprecation and --zero-fill-buffers', + }, + ] + +## reads node arguments from config + +> tests pass + + [ + { + file: 'node-arguments-from-config.js', + title: 'works', + }, + ] diff --git a/test/node-arguments/snapshots/test.js.snap b/test/node-arguments/snapshots/test.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..1e47c193a702c24bb4054d2b35ee4e10c1e867ef GIT binary patch literal 418 zcmV;T0bTw~7R8O)wtxnyLLlWKv>%HI00000000B6 zQ9VloK@i=!crhq)ISgW>Y_FTbRt3F)o!Dq$m(AT?a>-^l?A{p@()bgsgPkBY_VEM3 z!q)#Ff~{C8h?__vv9ZvFVZPp**~jc6gi>g+!*7kPY*S8aSy2fI(_rz-foZT zm(A9-Z+qSOrQTyN1B0q(_2*3v_+TR!L_sDzz(U5jL6v5> zNQjUDBUF`>Iuo%j;seSPmdD$)#;{Hl!<2KZV-<*48VaSyJ M1SK}&&XxiI0Pi)$v;Y7A literal 0 HcmV?d00001 diff --git a/test/node-arguments/test.js b/test/node-arguments/test.js new file mode 100644 index 000000000..bbf928366 --- /dev/null +++ b/test/node-arguments/test.js @@ -0,0 +1,32 @@ +const test = require('@ava/test'); +const exec = require('../helpers/exec'); + +test('passed node arguments to workers', async t => { + const options = { + cwd: exec.cwd('node-arguments') + }; + + const result = await exec.fixture(['--node-arguments="--throw-deprecation --zero-fill-buffers"', 'node-arguments.js'], options); + + t.snapshot(result.stats.passed, 'tests pass'); +}); + +test('detects incomplete --node-arguments', async t => { + const options = { + cwd: exec.cwd('node-arguments') + }; + + const result = await t.throwsAsync(exec.fixture(['--node-arguments="--foo=\'bar"', 'node-arguments.js'], options)); + + t.snapshot(exec.cleanOutput(result.stderr), 'fails with message'); +}); + +test('reads node arguments from config', async t => { + const options = { + cwd: exec.cwd('node-arguments-from-config') + }; + + const result = await exec.fixture(['node-arguments-from-config.js'], options); + + t.snapshot(result.stats.passed, 'tests pass'); +}); diff --git a/test/snapshot-updates/snapshots/test.js.snap b/test/snapshot-updates/snapshots/test.js.snap index 1891e9e1f527fc6fa10adb5dab9ae40a1e60811d..fd04d3f956cd3d8b10f2bd5f51ba46fb61780c7a 100644 GIT binary patch delta 268 zcmV+n0rURG1H}VcK~_N^Q*L2!b7*gLAa*he0syvncWu&U54a?NdgkdOO4}cc2mk;8 z00003>tkSGU}0Flto3@=;wu(i?;2Ojhn1)?GJrrV5JwAe2HVFysgT?-3VEfuNvTD8 zD27`SG(0!4Bsl}qY=kkB1OYZ0{$ON+GX(?$7#MjO7?~It`GIPfL>QTY&K8qY0WL&+ z1@-?B^$rh6Q2{WnK#@YJADEJXbS7ctkSGU}1;y1L;h{?q?*){Rmg#bj% { t.snapshot(result.stats.unsavedSnapshots, 'files where snapshots could not be updated'); }); -const stripLeadingFigures = string => string.replace(/^\W+/, ''); - test('cannot update snapshots when matching test titles', async t => { const result = await t.throwsAsync(exec.fixture(['contains-skip.js', '-u', '-m=snapshot'])); - t.snapshot(stripLeadingFigures(result.stderr.trim())); + t.snapshot(exec.cleanOutput(result.stderr)); }); test('cannot update snapshots when selecting tests by line number', async t => { const result = await t.throwsAsync(exec.fixture(['contains-skip.js:4', '-u'])); - t.snapshot(stripLeadingFigures(result.stderr.trim())); + t.snapshot(exec.cleanOutput(result.stderr)); }); diff --git a/xo.config.js b/xo.config.js index bb009d6c6..44f42e795 100644 --- a/xo.config.js +++ b/xo.config.js @@ -1,6 +1,7 @@ module.exports = { ignores: [ 'media/**', + 'test/config/fixtures/config-errors/test.js', 'test-tap/fixture/ava-paths/target/test.js', 'test-tap/fixture/{source-map-initial,syntax-error}.js', 'test-tap/fixture/snapshots/test-sourcemaps/build/**',