Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
259 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -1,7 +1,7 @@ | ||
{ | ||
"all": true, | ||
"exclude": [ | ||
"{coverage,media,test-d,test-tap}/**", | ||
"{coverage,media,test,test-d,test-tap}/**", | ||
"*.config.js", | ||
"index.d.ts" | ||
], | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -1,2 +1,5 @@ | ||
node_modules | ||
coverage | ||
/coverage | ||
/media/**/node_modules/ | ||
/node_modules/ | ||
/test-tap/**/node_modules/ | ||
/test/**/fixtures/**/node_modules/*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,4 @@ | ||
export default { | ||
files: ['test/**', '!test/**/{fixtures,helpers}/**'], | ||
ignoredByWatcher: ['{coverage,docs,media,test-d,test-tap}/**'] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,7 @@ | ||
# Self-hosted tests | ||
|
||
This directory contains tests that are run using a stable version of AVA. You can run them using `npx test-ava`. | ||
|
||
Tests should be placed in their own directory, grouped by area of responsibility. Use the `exec.fixture()` helper to launch the AVA version that is in the repository to run tests. Place these in a nested `fixtures` directory. Add a relative dependency in `package.json`. You can then import from `ava`. | ||
|
||
Prefer snapshotting the test results. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,29 @@ | ||
const test = require('ava'); | ||
|
||
const passes = async (t, assertion, ...args) => { | ||
await t[assertion](...args); | ||
}; | ||
|
||
passes.title = (_, assertion, ...args) => `t.${assertion}(${args.map(v => JSON.stringify(v)).join(', ')}) passes`; | ||
|
||
test(passes, 'pass'); | ||
test(passes, 'is', 1, 1); | ||
test(passes, 'not', 1, 2); | ||
test(passes, 'deepEqual', {foo: 'bar'}, {foo: 'bar'}); | ||
test(passes, 'notDeepEqual', {foo: 'bar'}, {foo: 'baz'}); | ||
test(passes, 'throws', () => { | ||
throw new Error('error'); | ||
}); | ||
test(passes, 'throwsAsync', async () => { | ||
throw new Error('error'); | ||
}); | ||
test(passes, 'notThrows', () => {}); | ||
test(passes, 'notThrowsAsync', async () => {}); | ||
test(passes, 'snapshot', {foo: 'bar'}); | ||
test(passes, 'truthy', 1); | ||
test(passes, 'falsy', ''); | ||
test(passes, 'true', true); | ||
test(passes, 'false', false); | ||
test(passes, 'regex', 'foo', /foo/); | ||
test(passes, 'notRegex', 'bar', /foo/); | ||
test(passes, 'assert', 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,13 @@ | ||
# Snapshot report for `happy-path.js` | ||
|
||
The actual snapshot is saved in `happy-path.js.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## t.snapshot({"foo":"bar"}) passes | ||
|
||
> Snapshot 1 | ||
{ | ||
foo: 'bar', | ||
} |
BIN
+144 Bytes
test/assertions/fixtures/happy-path.js.snap
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,10 @@ | ||
{ | ||
"ava": { | ||
"files": [ | ||
"*.js" | ||
] | ||
}, | ||
"dependencies": { | ||
"ava": "file:../../.." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,29 @@ | ||
# Snapshot report for `test/assertions/test.js` | ||
|
||
The actual snapshot is saved in `test.js.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## happy path | ||
|
||
> Snapshot 1 | ||
[ | ||
't.assert(1) passes', | ||
't.deepEqual({"foo":"bar"}, {"foo":"bar"}) passes', | ||
't.false(false) passes', | ||
't.falsy("") passes', | ||
't.is(1, 1) passes', | ||
't.not(1, 2) passes', | ||
't.notDeepEqual({"foo":"bar"}, {"foo":"baz"}) passes', | ||
't.notRegex("bar", {}) passes', | ||
't.notThrows() passes', | ||
't.notThrowsAsync() passes', | ||
't.pass() passes', | ||
't.regex("foo", {}) passes', | ||
't.snapshot({"foo":"bar"}) passes', | ||
't.throws() passes', | ||
't.throwsAsync() passes', | ||
't.true(true) passes', | ||
't.truthy(1) passes', | ||
] |
BIN
+415 Bytes
test/assertions/snapshots/test.js.snap
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,7 @@ | ||
const test = require('@ava/test'); | ||
const exec = require('../helpers/exec'); | ||
|
||
test('happy path', async t => { | ||
const result = await exec.fixture('happy-path.js'); | ||
t.snapshot(result.stats.passed.map(({title}) => title)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,65 @@ | ||
const path = require('path'); | ||
const v8 = require('v8'); | ||
|
||
const test = require('@ava/test'); | ||
const execa = require('execa'); | ||
|
||
const cliPath = path.resolve(__dirname, '../../cli.js'); | ||
const serialization = process.versions.node >= '12.16.0' ? 'advanced' : 'json'; | ||
|
||
exports.fixture = async (...args) => { | ||
const cwd = path.join(path.dirname(test.meta.file), 'fixtures'); | ||
const running = execa.node(cliPath, args, { | ||
env: { | ||
AVA_EMIT_RUN_STATUS_OVER_IPC: 'I\'ll find a payphone baby / Take some time to talk to you' | ||
}, | ||
cwd, | ||
serialization | ||
}); | ||
|
||
const stats = { | ||
passed: [] | ||
}; | ||
|
||
running.on('message', message => { | ||
if (serialization === 'json') { | ||
message = v8.deserialize(Uint8Array.from(message)); | ||
} | ||
|
||
switch (message.type) { | ||
case 'test-passed': { | ||
const {title, testFile} = message; | ||
stats.passed.push({title, file: path.posix.relative(cwd, testFile)}); | ||
break; | ||
} | ||
|
||
default: | ||
break; | ||
} | ||
}); | ||
|
||
try { | ||
return { | ||
stats, | ||
...await running | ||
}; | ||
} catch (error) { | ||
throw Object.assign(error, {stats}); | ||
} finally { | ||
stats.passed.sort((a, b) => { | ||
if (a.file < b.file) { | ||
return -1; | ||
} | ||
|
||
if (a.file > b.file) { | ||
return 1; | ||
} | ||
|
||
if (a.title < b.title) { | ||
return -1; | ||
} | ||
|
||
return 1; | ||
}); | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more.
Oops, something went wrong.