Remove Babel support, and therefore enhanced assertions

This removes support for @ava/babel. Since enhanced assertions (power assert)
are provided through that package this also removes support for those. Same for
improper throws detection.

@ava/babel has seen no meaningful contributions since it was released at the
start of 2020. It's not clear how we'd make it work with ESM. It's clearer if we
can recommend tools like @babel/register and otherwise focus on plain Node.js &
TypeScript support.
This commit is contained in:
Mark Wubben 2021-09-18 20:32:41 +02:00
parent 6d9c4d700d
commit 678f9caf22
57 changed files with 248 additions and 1964 deletions

View file

@ -5,4 +5,4 @@ contact_links:
about: Questions? Ideas? Something to share?
- name: Babel
url: https://github.com/avajs/babel/issues
about: Report a bug with AVA's Babel integration
about: Report a bug with AVA 3's Babel integration

View file

@ -77,7 +77,7 @@ test('skip assertion', t => {
## Enhanced assertion messages
Enabling [Babel](./recipes/babel.md) will also enable [`power-assert`](https://github.com/power-assert-js/power-assert), giving you more descriptive assertion messages.
With AVA 3, enabling [Babel](./recipes/babel.md) will also enable [`power-assert`](https://github.com/power-assert-js/power-assert), giving you more descriptive assertion messages.
Let's take this example, using Node's standard [`assert` library](https://nodejs.org/api/assert.html):

View file

@ -11,7 +11,8 @@ Commands:
ava [<pattern>...] Run tests [default]
ava debug [<pattern>...] Activate Node.js inspector and run a single test
file
ava reset-cache Reset AVA's compilation cache and exit
ava reset-cache Delete any temporary files and state kept by AVA,
then exit
Positionals:
pattern Glob patterns to select what test files to run. Leave empty if you
@ -162,7 +163,7 @@ AVA lets you run tests exclusively by referring to their line numbers. Target a
The format is a comma-separated list of `[X|Y-Z]` where `X`, `Y` and `Z` are integers between `1` and the last line number of the file.
This feature is only available from the command line. It won't work if you use tools like `ts-node/register` or `@babel/register`, and it does not currently work with `@ava/babel` and `@ava/typescript`.
This feature is only available from the command line. It won't work if you use tools like `ts-node/register` or `@babel/register`, and it does not currently work with `@ava/babel` (available for AVA 3) and `@ava/typescript`.
### Running a single test
@ -218,7 +219,7 @@ When running a file with and without line numbers, line numbers take precedence.
## Resetting AVA's cache
AVA itself does not cache files unless used with our [`@ava/babel`](https://github.com/avajs/babel) provider. If it seems like your latest changes aren't being picked up by AVA you can try resetting the cache by running:
AVA 3 itself does not cache files unless used with our [`@ava/babel`](https://github.com/avajs/babel) provider. If it seems like your latest changes aren't being picked up by AVA you can try resetting the cache by running:
```console
npx ava reset-cache

View file

@ -61,7 +61,7 @@ Arguments passed to the CLI will always take precedence over the CLI options con
Note that providing files on the CLI overrides the `files` option.
Provide the `babel` option (and install [`@ava/babel`](https://github.com/avajs/babel) as an additional dependency) to enable Babel compilation.
When using AVA 3, provide the `babel` option (and install [`@ava/babel`](https://github.com/avajs/babel) as an additional dependency) to enable Babel compilation.
Provide the `typescript` option (and install [`@ava/typescript`](https://github.com/avajs/typescript) as an additional dependency) to enable (rudimentary) TypeScript support.

View file

@ -56,6 +56,8 @@ AVA [can't trace uncaught exceptions](https://github.com/avajs/ava/issues/214) b
## Why are the enhanced assertion messages not shown?
Enhanced assertion messages are no longer supported in AVA 4.
Ensure that the first parameter passed into your test is named `t`. This is a requirement of [`power-assert`](https://github.com/power-assert-js/power-assert), the library that provides the [enhanced messages](./03-assertions.md#enhanced-assertion-messages).
```js

View file

@ -2,6 +2,8 @@
Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/docs/recipes/babel.md)
This is no longer available in AVA 4.
You can enable Babel support by installing `@ava/babel`, and then in AVA's configuration setting `babel` to `true`:
**`package.json`:**

View file

@ -4,7 +4,7 @@ Translations: [Español](https://github.com/avajs/ava-docs/blob/master/es_ES/doc
## Setting up Babel
When you [enable Babel](https://github.com/avajs/babel), AVA will automatically extend your regular (project-level) Babel configuration. You should be able to use React in your test files without any additional configuration.
When you [enable Babel](https://github.com/avajs/babel), AVA 3 will automatically extend your regular (project-level) Babel configuration. You should be able to use React in your test files without any additional configuration.
However if you want to set it up explicitly, add the preset to the test options in AVA's Babel pipeline by modifying your `package.json` or `ava.config.*` file.

View file

@ -53,7 +53,7 @@ hooks(['vue', 'js']).exclude(({filename}) => filename.match(/\/node_modules\//))
**Note:** If you are using _babel-plugin-webpack-alias-7_, you must also exclude your webpack file - e.g. `filename.includes(/\/node_modules\//) || filename.includes('webpack.config.test.js')`
You can find more information about setting up Babel with AVA in [`@ava/babel`](https://github.com/avajs/babel).
You can find more information about setting up Babel with AVA 3 in [`@ava/babel`](https://github.com/avajs/babel).
## Sample snapshot test

View file

@ -25,10 +25,6 @@ function formatWithLabel(label, value) {
return formatDescriptorWithLabel(label, concordance.describe(value, concordanceOptions));
}
function formatPowerAssertValue(value) {
return concordance.format(value, concordanceOptions);
}
const hasOwnProperty = (object, prop) => Object.prototype.hasOwnProperty.call(object, prop);
const noop = () => {};
const notImplemented = () => {
@ -52,9 +48,6 @@ export class AssertionError extends Error {
// use the values for custom diff views
this.raw = options.raw;
// Reserved for power-assert statements
this.statements = [];
this.savedError = options.savedError ? options.savedError : getErrorWithLongStackTrace();
}
}
@ -258,7 +251,6 @@ export class Assertions {
fail = notImplemented,
skip = notImplemented,
compareWithSnapshot = notImplemented,
powerAssert,
experiments = {},
disableSnapshots = false,
} = {}) {
@ -267,35 +259,12 @@ export class Assertions {
return assertionFn;
};
// When adding new enhanced functions with new patterns, don't forget to
// enable the pattern in the power-assert compilation step in @ava/babel.
const withPowerAssert = (pattern, assertionFn) => powerAssert.empower(assertionFn, {
onError: event => {
if (event.powerAssertContext) {
event.error.statements = powerAssert.format(event.powerAssertContext, formatPowerAssertValue);
}
fail(event.error);
return false;
},
onSuccess: () => {
pass();
return true;
},
bindReceiver: false,
patterns: [pattern],
});
const checkMessage = (assertion, message, powerAssert = false) => {
const checkMessage = (assertion, message) => {
const result = checkAssertionMessage(assertion, message);
if (result === true) {
return true;
}
if (powerAssert) {
throw result;
}
fail(result);
return false;
};
@ -948,41 +917,23 @@ export class Assertions {
return true;
});
if (powerAssert === undefined) {
this.assert = withSkip((actual, message) => {
if (!checkMessage('assert', message)) {
return false;
}
this.assert = withSkip((actual, message) => {
if (!checkMessage('assert', message)) {
return false;
}
if (!actual) {
fail(new AssertionError({
assertion: 'assert',
message,
operator: '!!',
values: [formatWithLabel('Value is not truthy:', actual)],
}));
return false;
}
if (!actual) {
fail(new AssertionError({
assertion: 'assert',
message,
operator: '!!',
values: [formatWithLabel('Value is not truthy:', actual)],
}));
return false;
}
pass();
return true;
});
} else {
this.assert = withSkip(withPowerAssert(
'assert(value, [message])',
(actual, message) => {
checkMessage('assert', message, true);
if (!actual) {
throw new AssertionError({
assertion: 'assert',
message,
operator: '!!',
values: [formatWithLabel('Value is not truthy:', actual)],
});
}
}),
);
}
pass();
return true;
});
}
}

View file

@ -199,7 +199,7 @@ export default async function loadCli() { // eslint-disable-line complexity
})
.command(
'reset-cache',
'Reset AVA’s compilation cache and exit',
'Delete any temporary files and state kept by AVA, then exit',
yargs => yargs,
() => {
resetCache = true;
@ -295,6 +295,10 @@ export default async function loadCli() { // eslint-disable-line complexity
console.log(chalk.magenta(` ${figures.warning} Experiments are enabled. These are unsupported and may change or be removed at any time.`));
}
if (Reflect.has(conf, 'babel')) {
exit('Built-in Babel support has been removed.');
}
if (Reflect.has(conf, 'compileEnhancements')) {
exit('Enhancement compilation must be configured in AVA’s Babel options.');
}
@ -319,19 +323,6 @@ export default async function loadCli() { // eslint-disable-line complexity
const {type: defaultModuleType = 'commonjs'} = pkg || {};
const providers = [];
if (Reflect.has(conf, 'babel')) {
try {
const {level, main} = await providerManager.babel(projectDir);
providers.push({
level,
main: main({config: conf.babel}),
type: 'babel',
});
} catch (error) {
exit(error.message);
}
}
if (Reflect.has(conf, 'typescript')) {
try {
const {level, main} = await providerManager.typescript(projectDir);

View file

@ -12,15 +12,6 @@ const configCache = new Map();
const collectProviders = async ({conf, projectDir}) => {
const providers = [];
if (Reflect.has(conf, 'babel')) {
const {level, main} = await providerManager.babel(projectDir);
providers.push({
level,
main: main({config: conf.babel}),
type: 'babel',
});
}
if (Reflect.has(conf, 'typescript')) {
const {level, main} = await providerManager.typescript(projectDir);
providers.push({

View file

@ -51,9 +51,6 @@ async function load(providerModule, projectDir) {
const providerManager = {
levels,
async babel(projectDir) {
return load('@ava/babel', projectDir);
},
async typescript(projectDir) {
return load('@ava/typescript', projectDir);
},

View file

@ -2,12 +2,8 @@ import StackUtils from 'stack-utils';
const stackUtils = new StackUtils({
ignoredPackages: [
'@ava/babel',
'@ava/require-precompiled',
'@ava/typescript',
'append-transform',
'ava',
'empower-core',
'nyc',
],
internals: [

View file

@ -1,11 +1,9 @@
import {chalk} from '../chalk.js';
export default function formatSerializedError(error) {
const printMessage = error.values.length === 0
? Boolean(error.message)
: !error.values[0].label.startsWith(error.message);
if (error.statements.length === 0 && error.values.length === 0) {
if (error.values.length === 0) {
return {formatted: null, printMessage};
}
@ -14,9 +12,5 @@ export default function formatSerializedError(error) {
formatted += `${value.label}\n\n${value.formatted}\n\n`;
}
for (const statement of error.statements) {
formatted += `${statement[0]}\n${chalk.grey('=>')} ${statement[1]}\n\n`;
}
return {formatted: formatted.trim(), printMessage};
}

View file

@ -23,7 +23,6 @@ export default class Runner extends Emittery {
this.file = options.file;
this.checkSelectedByLineNumbers = options.checkSelectedByLineNumbers;
this.match = options.match || [];
this.powerAssert = undefined; // Assigned later.
this.projectDir = options.projectDir;
this.recordNewSnapshots = options.recordNewSnapshots === true;
this.runOnlyExclusive = options.runOnlyExclusive === true;
@ -224,16 +223,6 @@ export default class Runner extends Emittery {
this.activeRunnables.delete(runnable);
}
attributeLeakedError(error) {
for (const runnable of this.activeRunnables) {
if (runnable.attributeLeakedError(error)) {
return true;
}
}
return false;
}
beforeExitHandler() {
for (const runnable of this.activeRunnables) {
runnable.finishDueToInactivity();
@ -299,7 +288,6 @@ export default class Runner extends Emittery {
skipSnapshot: this.boundSkipSnapshot,
updateSnapshots: this.updateSnapshots,
metadata: task.metadata,
powerAssert: this.powerAssert,
title: `${task.title}${titleSuffix || ''}`,
isHook: true,
testPassed,
@ -352,7 +340,6 @@ export default class Runner extends Emittery {
skipSnapshot: this.boundSkipSnapshot,
updateSnapshots: this.updateSnapshots,
metadata: task.metadata,
powerAssert: this.powerAssert,
title: task.title,
registerUniqueTitle: this.registerUniqueTitle,
notifyTimeoutUpdate: this.notifyTimeoutUpdate,

View file

@ -89,7 +89,6 @@ function trySerializeError(error, shouldBeautifyStack, testFile) {
retval.improperUsage = error.improperUsage;
retval.message = error.message;
retval.name = error.name;
retval.statements = error.statements;
retval.values = error.values;
if (error.fixedSource) {

View file

@ -37,7 +37,6 @@ class ExecutionContext extends Assertions {
test.countPassedAssertion();
},
compareWithSnapshot: options => test.compareWithSnapshot(options),
powerAssert: test.powerAssert,
experiments: test.experiments,
disableSnapshots: test.isHook === true,
});
@ -176,14 +175,6 @@ class ExecutionContext extends Assertions {
const test = testMap.get(this);
return test.isHook ? test.testPassed : !test.assertError;
}
_throwsArgStart(assertion, file, line) {
testMap.get(this).trackThrows({assertion, file, line});
}
_throwsArgEnd() {
testMap.get(this).trackThrows(null);
}
}
export default class Test {
@ -194,7 +185,6 @@ export default class Test {
this.fn = options.fn;
this.isHook = options.isHook === true;
this.metadata = options.metadata;
this.powerAssert = options.powerAssert;
this.title = options.title;
this.testPassed = options.testPassed;
this.registerUniqueTitle = options.registerUniqueTitle;
@ -278,13 +268,11 @@ export default class Test {
this.attemptCount = 0;
this.calledEnd = false;
this.duration = null;
this.finishDueToAttributedError = null;
this.finishDueToInactivity = null;
this.finishDueToTimeout = null;
this.finishing = false;
this.pendingAssertionCount = 0;
this.pendingAttemptCount = 0;
this.pendingThrowsAssertion = null;
this.planCount = null;
this.startedAt = 0;
this.timeoutMs = 0;
@ -512,60 +500,6 @@ export default class Test {
}
}
trackThrows(pending) {
this.pendingThrowsAssertion = pending;
}
detectImproperThrows(error) {
if (!this.pendingThrowsAssertion) {
return false;
}
const pending = this.pendingThrowsAssertion;
this.pendingThrowsAssertion = null;
const values = [];
if (error) {
values.push(formatErrorValue(`The following error was thrown, possibly before \`t.${pending.assertion}()\` could be called:`, error));
}
this.saveFirstError(new AssertionError({
assertion: pending.assertion,
fixedSource: {file: pending.file, line: pending.line},
improperUsage: true,
message: `Improper usage of \`t.${pending.assertion}()\` detected`,
savedError: error instanceof Error && error,
values,
}));
return true;
}
waitForPendingThrowsAssertion() {
return new Promise(resolve => {
this.finishDueToAttributedError = () => {
resolve(this.finish());
};
this.finishDueToInactivity = () => {
this.detectImproperThrows();
resolve(this.finish());
};
// Wait up to a second to see if an error can be attributed to the
// pending assertion.
nowAndTimers.setTimeout(() => this.finishDueToInactivity(), 1000).unref();
});
}
attributeLeakedError(error) {
if (!this.detectImproperThrows(error)) {
return false;
}
this.finishDueToAttributedError();
return true;
}
callFn() {
try {
return {
@ -585,13 +519,11 @@ export default class Test {
const result = this.callFn();
if (!result.ok) {
if (!this.detectImproperThrows(result.error)) {
this.saveFirstError(new AssertionError({
message: 'Error thrown in test',
savedError: result.error instanceof Error && result.error,
values: [formatErrorValue('Error thrown in test:', result.error)],
}));
}
this.saveFirstError(new AssertionError({
message: 'Error thrown in test',
savedError: result.error instanceof Error && result.error,
values: [formatErrorValue('Error thrown in test:', result.error)],
}));
return this.finish();
}
@ -632,13 +564,11 @@ export default class Test {
promise
.catch(error => { // eslint-disable-line promise/prefer-await-to-then
if (!this.detectImproperThrows(error)) {
this.saveFirstError(new AssertionError({
message: 'Rejected promise returned by test',
savedError: error instanceof Error && error,
values: [formatErrorValue('Rejected promise returned by test. Reason:', error)],
}));
}
this.saveFirstError(new AssertionError({
message: 'Rejected promise returned by test',
savedError: error instanceof Error && error,
values: [formatErrorValue('Rejected promise returned by test. Reason:', error)],
}));
})
.then(() => resolve(this.finish())); // eslint-disable-line promise/prefer-await-to-then
});
@ -650,10 +580,6 @@ export default class Test {
async finish() {
this.finishing = true;
if (!this.assertError && this.pendingThrowsAssertion) {
return this.waitForPendingThrowsAssertion();
}
this.clearTimeout();
this.verifyPlan();
this.verifyAssertions();

View file

@ -73,13 +73,6 @@ const run = async options => {
runner.interrupt();
});
const attributedRejections = new Set();
process.on('unhandledRejection', (reason, promise) => {
if (runner.attributeLeakedError(reason)) {
attributedRejections.add(promise);
}
});
runner.on('dependency', dependencyTracking.track);
runner.on('stateChange', state => channel.send(state));
@ -109,7 +102,7 @@ const run = async options => {
}
nowAndTimers.setImmediate(() => {
for (const rejection of currentlyUnhandled().filter(rejection => !attributedRejections.has(rejection.promise))) {
for (const rejection of currentlyUnhandled()) {
channel.send({type: 'unhandled-rejection', err: serializeError('Unhandled rejection', true, rejection.reason, runner.file)});
}
@ -118,10 +111,6 @@ const run = async options => {
});
process.on('uncaughtException', error => {
if (runner.attributeLeakedError(error)) {
return;
}
channel.send({type: 'uncaught-exception', err: serializeError('Uncaught exception', true, error, runner.file)});
exit(1);
});
@ -137,12 +126,6 @@ const run = async options => {
// require configuration the *compiled* helper will be loaded.
const {projectDir, providerStates = []} = options;
const providers = (await Promise.all(providerStates.map(async ({type, state}) => {
if (type === 'babel') {
const provider = (await providerManager.babel(projectDir)).worker({extensionsToLoadAsModules, state});
runner.powerAssert = provider.powerAssert;
return provider;
}
if (type === 'typescript') {
return (await providerManager.typescript(projectDir)).worker({extensionsToLoadAsModules, state});
}

View file

@ -1,8 +0,0 @@
import test from 'ava';
test('power-assert', t => {
const a = /foo/;
const b = 'bar';
const c = 'baz';
t.assert(a.test(b) || b === c);
});

934
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -52,7 +52,6 @@
"tap",
"qunit",
"jasmine",
"babel",
"assert",
"assertion",
"promise",
@ -123,9 +122,8 @@
"yargs": "^17.1.1"
},
"devDependencies": {
"@ava/babel": "^2.0.0",
"@ava/test": "github:avajs/test",
"@babel/plugin-proposal-do-expressions": "^7.14.5",
"@ava/typescript": "^2.0.0",
"@sinonjs/fake-timers": "^7.1.2",
"ansi-escapes": "^5.0.0",
"c8": "^7.9.0",
@ -146,13 +144,9 @@
"zen-observable": "^0.8.15"
},
"peerDependencies": {
"@ava/babel": "*",
"@ava/typescript": "*"
},
"peerDependenciesMeta": {
"@ava/babel": {
"optional": true
},
"@ava/typescript": {
"optional": true
}

View file

@ -22,7 +22,6 @@ Translations: [Español](https://github.com/avajs/ava-docs/blob/master/es_ES/rea
- Includes TypeScript definitions
- [Magic assert](#magic-assert)
- [Isolated environment for each test file](./docs/01-writing-tests.md#process-isolation)
- [Write your tests using the latest JavaScript syntax](https://github.com/avajs/babel)
- [Promise support](./docs/01-writing-tests.md#promise-support)
- [Async function support](./docs/01-writing-tests.md#async-function-support)
- [Observable support](./docs/01-writing-tests.md#observable-support)
@ -148,7 +147,6 @@ We have a growing list of [common pitfalls](docs/08-common-pitfalls.md) you may
- [When to use `t.plan()`](docs/recipes/when-to-use-plan.md)
- [Browser testing](docs/recipes/browser-testing.md)
- [TypeScript](docs/recipes/typescript.md)
- [Configuring Babel](https://github.com/avajs/babel)
- [Using ES modules](docs/recipes/es-modules.md)
- [Passing arguments to your test files](docs/recipes/passing-arguments-to-your-test-files.md)
- [Testing React components](docs/recipes/react.md)
@ -190,7 +188,7 @@ It's the [Andromeda galaxy](https://simple.wikipedia.org/wiki/Andromeda_galaxy).
- [eslint-plugin-ava](https://github.com/avajs/eslint-plugin-ava) — Lint rules for AVA tests
- [@ava/typescript](https://github.com/avajs/typescript) — Test TypeScript projects
- [@ava/babel](https://github.com/avajs/babel) — Compile test files using Babel
- [@ava/babel](https://github.com/avajs/babel) — Compile test files using Babel, for AVA 3
- [@ava/cooperate](https://github.com/avajs/cooperate) — Low-level primitives to enable cooperation between test files
- [@ava/get-port](https://github.com/avajs/get-port) — Reserve a port while testing

View file

@ -7,20 +7,12 @@ import {test} from 'tap';
import Api from '../lib/api.js';
import {normalizeGlobs} from '../lib/globs.js';
import providerManager from '../lib/provider-manager.js';
const __dirname = fileURLToPath(new URL('.', import.meta.url));
const ROOT_DIR = path.join(__dirname, '..');
async function apiCreator(options = {}) {
options.projectDir = options.projectDir || ROOT_DIR;
if (options.babelConfig !== undefined) {
options.providers = [{
type: 'babel',
main: (await providerManager.babel(options.projectDir)).main({config: options.babelConfig}),
}];
}
options.chalkOptions = {level: 0};
options.concurrency = 2;
options.extensions = options.extensions || ['cjs'];
@ -330,56 +322,6 @@ for (const opt of opts) {
});
});
test(`enhanced assertion formatting necessary whitespace and empty strings - workerThreads: ${opt.workerThreads}`, async t => {
const expected = [
[
/foo === "" && "" === foo/,
/foo === ""/,
/foo/,
],
[
/!\(new Object\(foo\) instanceof Object\)/,
/new Object\(foo\) instanceof Object/,
/Object/,
/new Object\(foo\)/,
/foo/,
],
[
/\[foo].filter\(item => {\n\s+return item === "bar";\n}\).length > 0/,
/\[foo].filter\(item => {\n\s+return item === "bar";\n}\).length/,
/\[foo].filter\(item => {\n\s+return item === "bar";\n}\)/,
/\[foo]/,
/foo/,
],
];
t.plan(15);
const api = await apiCreator({
...opt,
files: ['test-tap/fixture/enhanced-assertion-formatting.cjs'],
babelConfig: true,
});
const errors = [];
api.on('run', plan => {
plan.status.on('stateChange', evt => {
if (evt.type === 'test-failed') {
errors.push(evt.err);
}
});
});
return api.run({files: [path.join(__dirname, 'fixture/enhanced-assertion-formatting.cjs')]})
.then(runStatus => {
t.equal(errors.length, 3);
t.equal(runStatus.stats.passedTests, 0);
for (const [errorIndex, error] of errors.entries()) {
for (const [statementIndex, statement] of error.statements.entries()) {
t.match(statement[0], expected[errorIndex][statementIndex]);
}
}
});
});
test(`absolute paths - workerThreads: ${opt.workerThreads}`, async t => {
const api = await apiCreator(opt);
@ -441,20 +383,17 @@ for (const opt of opts) {
const api = await apiCreator({
...opt,
babelConfig: true,
projectDir: path.join(__dirname, 'fixture/caching'),
});
return api.run({files: [path.join(__dirname, 'fixture/caching/test.cjs')]})
.then(() => {
const files = fs.readdirSync(path.join(__dirname, 'fixture/caching/node_modules/.cache/ava'));
t.equal(files.filter(x => x.endsWith('.cjs')).length, 1);
t.equal(files.filter(x => x.endsWith('.map')).length, 1);
if (files.length === 3) {
if (files.length === 1) {
// This file may be written locally, but not in CI.
t.equal(files.filter(x => x.startsWith('failing-tests.json')).length, 1);
} else {
t.equal(files.length, 2);
t.equal(files.length, 0);
}
});
});

View file

@ -53,16 +53,6 @@ function assertFailure(t, subset) {
t.equal(lastFailure.raw.actual, subset.raw.actual);
}
if (subset.statements) {
t.equal(lastFailure.statements.length, subset.statements.length);
for (const [i, s] of lastFailure.statements.entries()) {
t.equal(s[0], subset.statements[i][0]);
t.match(s[1], subset.statements[i][1]);
}
} else {
t.same(lastFailure.statements, []);
}
if (subset.values) {
t.equal(lastFailure.values.length, subset.values.length);
for (const [i, s] of lastFailure.values.entries()) {

View file

@ -1,23 +0,0 @@
const test = require('../../entrypoints/main.cjs');
const foo = 'foo';
test('fails with multiple empty string expressions and mixed quotes', t => {
// eslint-disable-next-line quotes, yoda
t.assert(foo === '' && "" === foo);
});
test('fails with "instanceof" expression', t => {
// eslint-disable-next-line no-new-object
t.assert(!(new Object(foo) instanceof Object));
});
test('fails with multiple lines', t => {
/* eslint-disable unicorn/prefer-array-some, arrow-body-style */
t.assert(
[foo].filter(item => {
return item === 'bar';
}).length > 0,
);
/* eslint-enable unicorn/prefer-array-some, arrow-body-style */
});

View file

@ -1,8 +1,11 @@
export default {
extensions: [],
files: ['tests/**/*'],
babel: {
compileAsTests: ['helpers/*'],
typescript: {
compile: false,
rewritePaths: {
'src/': 'build/',
},
extensions: ['foo'],
},
};

View file

@ -1,7 +1,10 @@
export default {
extensions: [],
babel: {
compileAsTests: ['build/helpers/*'],
typescript: {
rewritePaths: {
'src/': 'build/',
},
compile: false,
extensions: ['bar'],
},
files: ['build/tests/**/*'],

View file

@ -1,15 +0,0 @@
const test = require('../../../entrypoints/main.cjs');
test('test', t => {
try {
t.throws(throwSync());
} catch (error) {
setTimeout(() => {
throw error;
}, 500);
}
});
function throwSync() {
throw new Error('should be detected');
}

View file

@ -1,15 +0,0 @@
const test = require('../../../entrypoints/main.cjs');
test('test', t => {
try {
t.throws(throwSync());
} catch (error) {
setTimeout(() => {
throw error;
}, 1500);
}
});
function throwSync() {
throw new Error('should be detected');
}

View file

@ -1,15 +0,0 @@
const test = require('../../../entrypoints/main.cjs');
test('test', t => {
try {
t.throws(throwSync());
} catch (error) {
setImmediate(() => {
throw error;
});
}
});
function throwSync() {
throw new Error('should be detected');
}

View file

@ -1,11 +0,0 @@
const test = require('../../../entrypoints/main.cjs');
test('test', t => {
try {
t.throws(throwSync());
} catch {}
});
function throwSync() {
throw new Error('should be detected');
}

View file

@ -1,17 +0,0 @@
const test = require('../../../entrypoints/main.cjs');
test('test', t => {
try {
t.throws(throwSync());
} catch (error) {
setImmediate(() => {
throw error;
});
}
return new Promise(() => {});
});
function throwSync() {
throw new Error('should be detected');
}

View file

@ -1,6 +0,0 @@
{
"ava": {
"files": ["*.*"],
"babel": true
}
}

View file

@ -1,9 +0,0 @@
const test = require('../../../entrypoints/main.cjs');
test('test', t => Promise.resolve().then(() => {
t.throws(throwSync());
}));
function throwSync() {
throw new Error('should be detected');
}

View file

@ -1,9 +0,0 @@
const test = require('../../../entrypoints/main.cjs');
test('test', t => {
t.throws(throwSync());
});
function throwSync() {
throw new Error('should be detected');
}

View file

@ -1,16 +0,0 @@
const delay = require('delay');
const test = require('../../../entrypoints/main.cjs');
test('test', async t => {
Promise.resolve().then(() => {
t.throws(throwSync());
});
await delay(20);
t.pass();
});
function throwSync() {
throw new Error('should be detected');
}

View file

@ -22,27 +22,6 @@ test('formatted', t => {
t.deepEqual('foo', 'bar');
});
test('power-assert', t => {
const foo = '';
t.assert(foo);
});
test('bad throws', t => {
const fn = () => {
throw new Error('err');
};
t.throws(fn());
});
test('bad notThrows', t => {
const fn = () => {
throw new Error('err');
};
t.notThrows(fn());
});
test('implementation throws non-error', () => {
const error = null;
throw error;

View file

@ -9,7 +9,6 @@ import Api from '../../lib/api.js';
import {_testOnlyReplaceWorkerPath} from '../../lib/fork.js';
import {normalizeGlobs} from '../../lib/globs.js';
import pkg from '../../lib/pkg.cjs';
import providerManager from '../../lib/provider-manager.js';
_testOnlyReplaceWorkerPath(new URL('report-worker.js', import.meta.url));
@ -56,17 +55,7 @@ exports.projectDir = type => path.join(__dirname, '../fixture/report', type.toLo
const run = async (type, reporter, {match = [], filter} = {}) => {
const projectDir = exports.projectDir(type);
const providers = [{
type: 'babel',
level: 'ava-3',
main: (await providerManager.babel(projectDir)).main({
config: {
testOptions: {
plugins: ['@babel/plugin-proposal-do-expressions'],
},
},
}),
}];
const providers = [];
const options = {
extensions: ['cjs'],

View file

@ -1,83 +0,0 @@
import {test} from 'tap';
import {execCli} from '../helper/cli.js';
test('improper use of t.throws will be reported to the console', t => {
execCli('throws.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => {
t.ok(err);
t.match(stdout, /Improper usage of `t\.throws\(\)` detected/);
t.match(stdout, /should be detected/);
t.match(stdout, /Try wrapping the first argument/);
t.end();
});
});
test('improper use of t.throws from within a Promise will be reported to the console', t => {
execCli('promise.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => {
t.ok(err);
t.match(stdout, /Improper usage of `t\.throws\(\)` detected/);
t.match(stdout, /should be detected/);
t.match(stdout, /Try wrapping the first argument/);
t.end();
});
});
test('improper use of t.throws from within a pending promise, even if caught and rethrown immediately, will be reported to the console', t => {
execCli('leaked-from-promise.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => {
t.ok(err);
t.match(stdout, /Improper usage of `t\.throws\(\)` detected/);
t.match(stdout, /should be detected/);
t.match(stdout, /Try wrapping the first argument/);
t.end();
});
});
test('improper use of t.throws, swallowed as an unhandled rejection, will be reported to the console', t => {
execCli('unhandled-rejection.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => {
t.ok(err);
t.match(stdout, /Improper usage of `t\.throws\(\)` detected/);
t.match(stdout, /should be detected/);
t.match(stdout, /Try wrapping the first argument/);
t.end();
});
});
test('improper use of t.throws, even if caught, will be reported to the console', t => {
execCli('caught.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => {
t.ok(err);
t.match(stdout, /Improper usage of `t\.throws\(\)` detected/);
t.notMatch(stdout, /should be detected/);
t.match(stdout, /Try wrapping the first argument/);
t.end();
});
});
test('improper use of t.throws, even if caught and then rethrown immediately, will be reported to the console', t => {
execCli('caught-and-leaked.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => {
t.ok(err);
t.match(stdout, /Improper usage of `t\.throws\(\)` detected/);
t.match(stdout, /should be detected/);
t.match(stdout, /Try wrapping the first argument/);
t.end();
});
});
test('improper use of t.throws, even if caught and then later rethrown, will be reported to the console', t => {
execCli('caught-and-leaked-slowly.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => {
t.ok(err);
t.match(stdout, /Improper usage of `t\.throws\(\)` detected/);
t.match(stdout, /should be detected/);
t.match(stdout, /Try wrapping the first argument/);
t.end();
});
});
test('improper use of t.throws, even if caught and then rethrown too slowly, will be reported to the console', t => {
execCli('caught-and-leaked-too-slowly.cjs', {dirname: 'fixture/improper-t-throws'}, (err, stdout) => {
t.ok(err);
t.match(stdout, /Improper usage of `t\.throws\(\)` detected/);
t.notMatch(stdout, /should be detected/);
t.match(stdout, /Try wrapping the first argument/);
t.end();
});
});

View file

@ -2,7 +2,17 @@
---tty-stream-chunk-separator
⚠ Could not parse ast-syntax-error.cjs for line number selection
---tty-stream-chunk-separator
✖ Line numbers for ast-syntax-error.cjs did not match any tests
Uncaught exception in ast-syntax-error.cjs
~/test-tap/fixture/report/edgecases/ast-syntax-error.cjs:3
const fn = do {
^^
SyntaxError: Unexpected token 'do'
---tty-stream-chunk-separator
✖ ast-syntax-error.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
✖ No tests found in ava-import-no-test-declaration.cjs
---tty-stream-chunk-separator
@ -43,5 +53,5 @@
---tty-stream-chunk-separator
─
2 uncaught exceptions
3 uncaught exceptions
---tty-stream-chunk-separator

View file

@ -2,7 +2,13 @@
---tty-stream-chunk-separator
⚠ Could not parse ast-syntax-error.cjs for line number selection
---tty-stream-chunk-separator
✖ Line numbers for ast-syntax-error.cjs did not match any tests
Uncaught exception in ast-syntax-error.cjs
SyntaxError: Unexpected token 'do'
---tty-stream-chunk-separator
✖ ast-syntax-error.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
✖ No tests found in ava-import-no-test-declaration.cjs
---tty-stream-chunk-separator
@ -43,5 +49,5 @@
---tty-stream-chunk-separator
─
2 uncaught exceptions
3 uncaught exceptions
---tty-stream-chunk-separator

View file

@ -2,7 +2,13 @@
---tty-stream-chunk-separator
⚠ Could not parse ast-syntax-error.cjs for line number selection
---tty-stream-chunk-separator
✖ Line numbers for ast-syntax-error.cjs did not match any tests
Uncaught exception in ast-syntax-error.cjs
SyntaxError: Unexpected token 'do'
---tty-stream-chunk-separator
✖ ast-syntax-error.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
✖ No tests found in ava-import-no-test-declaration.cjs
---tty-stream-chunk-separator
@ -43,5 +49,5 @@
---tty-stream-chunk-separator
─
2 uncaught exceptions
3 uncaught exceptions
---tty-stream-chunk-separator

View file

@ -61,12 +61,6 @@
ℹ world
---tty-stream-chunk-separator
✖ test › formatted
---tty-stream-chunk-separator
✖ test › power-assert
---tty-stream-chunk-separator
✖ test › bad throws Improper usage of `t.throws()` detected
---tty-stream-chunk-separator
✖ test › bad notThrows Improper usage of `t.notThrows()` detected
---tty-stream-chunk-separator
✖ test › implementation throws non-error Error thrown in test
---tty-stream-chunk-separator
@ -243,83 +237,6 @@
test › power-assert
test.cjs:27
26: const foo = '';
 27: t.assert(foo); 
28: });
Value is not truthy:
''
foo
=> ''
› test-tap/fixture/report/regular/test.cjs:27:4
test › bad throws
test.cjs:35
34:
 35: t.throws(fn());
36: });
Improper usage of `t.throws()` detected
The following error was thrown, possibly before `t.throws()` could be called:
Error {
message: 'err',
}
Try wrapping the first argument to `t.throws()` in a function:
t.throws(() => { /* your code here */ })
Visit the following URL for more details:
https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message
› fn (test-tap/fixture/report/regular/test.cjs:32:9)
› test-tap/fixture/report/regular/test.cjs:35:11
test › bad notThrows
test.cjs:43
42:
 43: t.notThrows(fn());
44: });
Improper usage of `t.notThrows()` detected
The following error was thrown, possibly before `t.notThrows()` could be called:
Error {
message: 'err',
}
Try wrapping the first argument to `t.notThrows()` in a function:
t.notThrows(() => { /* your code here */ })
Visit the following URL for more details:
https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message
› fn (test-tap/fixture/report/regular/test.cjs:40:9)
› test-tap/fixture/report/regular/test.cjs:43:14
test › implementation throws non-error
Error thrown in test:
@ -347,7 +264,7 @@
Function TypeError {}
› throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8)
› test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17
› t.throws.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17)
› test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4
@ -435,7 +352,7 @@
─
16 tests failed
13 tests failed
1 known failure
1 test skipped
1 test todo

View file

@ -61,12 +61,6 @@
ℹ world
---tty-stream-chunk-separator
✖ test › formatted
---tty-stream-chunk-separator
✖ test › power-assert
---tty-stream-chunk-separator
✖ test › bad throws Improper usage of `t.throws()` detected
---tty-stream-chunk-separator
✖ test › bad notThrows Improper usage of `t.notThrows()` detected
---tty-stream-chunk-separator
✖ test › implementation throws non-error Error thrown in test
---tty-stream-chunk-separator
@ -243,83 +237,6 @@
test › power-assert
test.cjs:27
26: const foo = '';
 27: t.assert(foo); 
28: });
Value is not truthy:
''
foo
=> ''
› test-tap/fixture/report/regular/test.cjs:27:4
test › bad throws
test.cjs:35
34:
 35: t.throws(fn());
36: });
Improper usage of `t.throws()` detected
The following error was thrown, possibly before `t.throws()` could be called:
Error {
message: 'err',
}
Try wrapping the first argument to `t.throws()` in a function:
t.throws(() => { /* your code here */ })
Visit the following URL for more details:
https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message
› fn (test-tap/fixture/report/regular/test.cjs:32:9)
› test-tap/fixture/report/regular/test.cjs:35:11
test › bad notThrows
test.cjs:43
42:
 43: t.notThrows(fn());
44: });
Improper usage of `t.notThrows()` detected
The following error was thrown, possibly before `t.notThrows()` could be called:
Error {
message: 'err',
}
Try wrapping the first argument to `t.notThrows()` in a function:
t.notThrows(() => { /* your code here */ })
Visit the following URL for more details:
https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message
› fn (test-tap/fixture/report/regular/test.cjs:40:9)
› test-tap/fixture/report/regular/test.cjs:43:14
test › implementation throws non-error
Error thrown in test:
@ -347,7 +264,7 @@
Function TypeError {}
› throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8)
› test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17
› t.throws.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17)
› test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4
@ -435,7 +352,7 @@
─
16 tests failed
13 tests failed
1 known failure
1 test skipped
1 test todo

View file

@ -61,12 +61,6 @@
ℹ world
---tty-stream-chunk-separator
✖ test › formatted
---tty-stream-chunk-separator
✖ test › power-assert
---tty-stream-chunk-separator
✖ test › bad throws Improper usage of `t.throws()` detected
---tty-stream-chunk-separator
✖ test › bad notThrows Improper usage of `t.notThrows()` detected
---tty-stream-chunk-separator
✖ test › implementation throws non-error Error thrown in test
---tty-stream-chunk-separator
@ -243,83 +237,6 @@
test › power-assert
test.cjs:27
26: const foo = '';
 27: t.assert(foo); 
28: });
Value is not truthy:
''
foo
=> ''
› test-tap/fixture/report/regular/test.cjs:27:4
test › bad throws
test.cjs:35
34:
 35: t.throws(fn());
36: });
Improper usage of `t.throws()` detected
The following error was thrown, possibly before `t.throws()` could be called:
Error {
message: 'err',
}
Try wrapping the first argument to `t.throws()` in a function:
t.throws(() => { /* your code here */ })
Visit the following URL for more details:
https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message
› fn (test-tap/fixture/report/regular/test.cjs:32:9)
› test-tap/fixture/report/regular/test.cjs:35:11
test › bad notThrows
test.cjs:43
42:
 43: t.notThrows(fn());
44: });
Improper usage of `t.notThrows()` detected
The following error was thrown, possibly before `t.notThrows()` could be called:
Error {
message: 'err',
}
Try wrapping the first argument to `t.notThrows()` in a function:
t.notThrows(() => { /* your code here */ })
Visit the following URL for more details:
https://github.com/avajs/ava/blob/VERSION/docs/03-assertions.md#throwsfn-expected-message
› fn (test-tap/fixture/report/regular/test.cjs:40:9)
› test-tap/fixture/report/regular/test.cjs:43:14
test › implementation throws non-error
Error thrown in test:
@ -347,7 +264,7 @@
Function TypeError {}
› throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8)
› test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17
› t.throws.instanceOf (test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17)
› test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4
@ -435,7 +352,7 @@
─
16 tests failed
13 tests failed
1 known failure
1 test skipped
1 test todo

View file

@ -1,8 +1,21 @@
TAP version 13
---tty-stream-chunk-separator
not ok 1 - No tests found in ava-import-no-test-declaration.cjs
not ok 1 - ~/test-tap/fixture/report/edgecases/ast-syntax-error.cjs:3
const fn = do {
^^
SyntaxError: Unexpected token 'do'
---
name: SyntaxError
message: Unexpected token 'do'
at: ''
...
---tty-stream-chunk-separator
not ok 2 - TypeError: test is not a function
not ok 2 - ast-syntax-error.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
not ok 3 - No tests found in ava-import-no-test-declaration.cjs
---tty-stream-chunk-separator
not ok 4 - TypeError: test is not a function
---
name: TypeError
message: test is not a function
@ -11,23 +24,23 @@ not ok 2 - TypeError: test is not a function
(test-tap/fixture/report/edgecases/import-and-use-test-member.cjs:3:1)
...
---tty-stream-chunk-separator
not ok 3 - import-and-use-test-member.cjs exited with a non-zero exit code: 1
not ok 5 - import-and-use-test-member.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
not ok 4 - No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file
not ok 6 - No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file
---tty-stream-chunk-separator
not ok 5 - Error: throws
not ok 7 - Error: throws
---
name: Error
message: throws
at: 'Object.<anonymous> (test-tap/fixture/report/edgecases/throws.cjs:1:7)'
...
---tty-stream-chunk-separator
not ok 6 - throws.cjs exited with a non-zero exit code: 1
not ok 8 - throws.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
1..0
# tests 0
# pass 0
# fail 6
# fail 8
---tty-stream-chunk-separator

View file

@ -1,8 +1,17 @@
TAP version 13
---tty-stream-chunk-separator
not ok 1 - No tests found in ava-import-no-test-declaration.cjs
not ok 1 - SyntaxError: Unexpected token 'do'
---
name: SyntaxError
message: Unexpected token 'do'
at: ''
...
---tty-stream-chunk-separator
not ok 2 - TypeError: test is not a function
not ok 2 - ast-syntax-error.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
not ok 3 - No tests found in ava-import-no-test-declaration.cjs
---tty-stream-chunk-separator
not ok 4 - TypeError: test is not a function
---
name: TypeError
message: test is not a function
@ -11,23 +20,23 @@ not ok 2 - TypeError: test is not a function
(test-tap/fixture/report/edgecases/import-and-use-test-member.cjs:3:1)
...
---tty-stream-chunk-separator
not ok 3 - import-and-use-test-member.cjs exited with a non-zero exit code: 1
not ok 5 - import-and-use-test-member.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
not ok 4 - No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file
not ok 6 - No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file
---tty-stream-chunk-separator
not ok 5 - Error: throws
not ok 7 - Error: throws
---
name: Error
message: throws
at: 'Object.<anonymous> (test-tap/fixture/report/edgecases/throws.cjs:1:7)'
...
---tty-stream-chunk-separator
not ok 6 - throws.cjs exited with a non-zero exit code: 1
not ok 8 - throws.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
1..0
# tests 0
# pass 0
# fail 6
# fail 8
---tty-stream-chunk-separator

View file

@ -1,8 +1,17 @@
TAP version 13
---tty-stream-chunk-separator
not ok 1 - No tests found in ava-import-no-test-declaration.cjs
not ok 1 - SyntaxError: Unexpected token 'do'
---
name: SyntaxError
message: Unexpected token 'do'
at: ''
...
---tty-stream-chunk-separator
not ok 2 - TypeError: test is not a function
not ok 2 - ast-syntax-error.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
not ok 3 - No tests found in ava-import-no-test-declaration.cjs
---tty-stream-chunk-separator
not ok 4 - TypeError: test is not a function
---
name: TypeError
message: test is not a function
@ -11,23 +20,23 @@ not ok 2 - TypeError: test is not a function
(test-tap/fixture/report/edgecases/import-and-use-test-member.cjs:3:1)
...
---tty-stream-chunk-separator
not ok 3 - import-and-use-test-member.cjs exited with a non-zero exit code: 1
not ok 5 - import-and-use-test-member.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
not ok 4 - No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file
not ok 6 - No tests found in no-ava-import.cjs, make sure to import "ava" at the top of your test file
---tty-stream-chunk-separator
not ok 5 - Error: throws
not ok 7 - Error: throws
---
name: Error
message: throws
at: 'Object.<anonymous> (test-tap/fixture/report/edgecases/throws.cjs:1:7)'
...
---tty-stream-chunk-separator
not ok 6 - throws.cjs exited with a non-zero exit code: 1
not ok 8 - throws.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
1..0
# tests 0
# pass 0
# fail 6
# fail 8
---tty-stream-chunk-separator

View file

@ -135,47 +135,7 @@ not ok 14 - test › formatted
at: 'test-tap/fixture/report/regular/test.cjs:22:4'
...
---tty-stream-chunk-separator
not ok 15 - test › power-assert
---
name: AssertionError
assertion: assert
operator: '!!'
values:
'Value is not truthy:': ''''''
at: 'test-tap/fixture/report/regular/test.cjs:27:4'
...
---tty-stream-chunk-separator
not ok 16 - test › bad throws
---
name: AssertionError
message: Improper usage of `t.throws()` detected
assertion: throws
values:
'The following error was thrown, possibly before `t.throws()` could be called:': |-
Error {
message: 'err',
}
at: |-
fn (test-tap/fixture/report/regular/test.cjs:32:9)
test-tap/fixture/report/regular/test.cjs:35:11
...
---tty-stream-chunk-separator
not ok 17 - test › bad notThrows
---
name: AssertionError
message: Improper usage of `t.notThrows()` detected
assertion: notThrows
values:
'The following error was thrown, possibly before `t.notThrows()` could be called:': |-
Error {
message: 'err',
}
at: |-
fn (test-tap/fixture/report/regular/test.cjs:40:9)
test-tap/fixture/report/regular/test.cjs:43:14
...
---tty-stream-chunk-separator
not ok 18 - test › implementation throws non-error
not ok 15 - test › implementation throws non-error
---
name: AssertionError
message: Error thrown in test
@ -184,7 +144,7 @@ not ok 18 - test › implementation throws non-error
at: ''
...
---tty-stream-chunk-separator
not ok 19 - traces-in-t-throws › throws
not ok 16 - traces-in-t-throws › throws
---
name: AssertionError
assertion: throws
@ -194,13 +154,16 @@ not ok 19 - traces-in-t-throws › throws
message: 'uh-oh',
}
'Expected instance of:': 'Function TypeError {}'
at: |-
at: >-
throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8)
test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17
t.throws.instanceOf
(test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17)
test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4
...
---tty-stream-chunk-separator
not ok 20 - traces-in-t-throws › notThrows
not ok 17 - traces-in-t-throws › notThrows
---
name: AssertionError
assertion: notThrows
@ -215,7 +178,7 @@ not ok 20 - traces-in-t-throws › notThrows
test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:4
...
---tty-stream-chunk-separator
not ok 21 - traces-in-t-throws › notThrowsAsync
not ok 18 - traces-in-t-throws › notThrowsAsync
---
name: AssertionError
assertion: notThrowsAsync
@ -230,7 +193,7 @@ not ok 21 - traces-in-t-throws › notThrowsAsync
test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:4
...
---tty-stream-chunk-separator
not ok 22 - traces-in-t-throws › throwsAsync
not ok 19 - traces-in-t-throws › throwsAsync
---
name: AssertionError
assertion: throwsAsync
@ -248,7 +211,7 @@ not ok 22 - traces-in-t-throws › throwsAsync
test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:4
...
---tty-stream-chunk-separator
not ok 23 - traces-in-t-throws › throwsAsync different error
not ok 20 - traces-in-t-throws › throwsAsync different error
---
name: AssertionError
assertion: throwsAsync
@ -265,9 +228,9 @@ not ok 23 - traces-in-t-throws › throwsAsync different error
test-tap/fixture/report/regular/traces-in-t-throws.cjs:27:44
...
---tty-stream-chunk-separator
ok 24 - uncaught-exception › passes
ok 21 - uncaught-exception › passes
---tty-stream-chunk-separator
not ok 25 - Error: Can’t catch me
not ok 22 - Error: Can’t catch me
---
name: Error
message: Can’t catch me
@ -276,30 +239,30 @@ not ok 25 - Error: Can’t catch me
(test-tap/fixture/report/regular/uncaught-exception.cjs:5:9)
...
---tty-stream-chunk-separator
not ok 26 - uncaught-exception.cjs exited with a non-zero exit code: 1
not ok 23 - uncaught-exception.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
ok 27 - unhandled-rejection › passes
ok 24 - unhandled-rejection › passes
---tty-stream-chunk-separator
ok 28 - unhandled-rejection › unhandled non-error rejection
ok 25 - unhandled-rejection › unhandled non-error rejection
---tty-stream-chunk-separator
not ok 29 - Error: Can’t catch me
not ok 26 - Error: Can’t catch me
---
name: Error
message: Can’t catch me
at: 'passes (test-tap/fixture/report/regular/unhandled-rejection.cjs:4:17)'
...
---tty-stream-chunk-separator
not ok 30 - unhandled-rejection
not ok 27 - unhandled-rejection
---
message: Non-error object
formatted: 'null'
...
---tty-stream-chunk-separator
1..24
# tests 23
1..21
# tests 20
# pass 6
# skip 1
# fail 23
# fail 20
---tty-stream-chunk-separator

View file

@ -135,47 +135,7 @@ not ok 14 - test › formatted
at: 'test-tap/fixture/report/regular/test.cjs:22:4'
...
---tty-stream-chunk-separator
not ok 15 - test › power-assert
---
name: AssertionError
assertion: assert
operator: '!!'
values:
'Value is not truthy:': ''''''
at: 'test-tap/fixture/report/regular/test.cjs:27:4'
...
---tty-stream-chunk-separator
not ok 16 - test › bad throws
---
name: AssertionError
message: Improper usage of `t.throws()` detected
assertion: throws
values:
'The following error was thrown, possibly before `t.throws()` could be called:': |-
Error {
message: 'err',
}
at: |-
fn (test-tap/fixture/report/regular/test.cjs:32:9)
test-tap/fixture/report/regular/test.cjs:35:11
...
---tty-stream-chunk-separator
not ok 17 - test › bad notThrows
---
name: AssertionError
message: Improper usage of `t.notThrows()` detected
assertion: notThrows
values:
'The following error was thrown, possibly before `t.notThrows()` could be called:': |-
Error {
message: 'err',
}
at: |-
fn (test-tap/fixture/report/regular/test.cjs:40:9)
test-tap/fixture/report/regular/test.cjs:43:14
...
---tty-stream-chunk-separator
not ok 18 - test › implementation throws non-error
not ok 15 - test › implementation throws non-error
---
name: AssertionError
message: Error thrown in test
@ -184,7 +144,7 @@ not ok 18 - test › implementation throws non-error
at: ''
...
---tty-stream-chunk-separator
not ok 19 - traces-in-t-throws › throws
not ok 16 - traces-in-t-throws › throws
---
name: AssertionError
assertion: throws
@ -194,13 +154,16 @@ not ok 19 - traces-in-t-throws › throws
message: 'uh-oh',
}
'Expected instance of:': 'Function TypeError {}'
at: |-
at: >-
throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8)
test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17
t.throws.instanceOf
(test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17)
test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4
...
---tty-stream-chunk-separator
not ok 20 - traces-in-t-throws › notThrows
not ok 17 - traces-in-t-throws › notThrows
---
name: AssertionError
assertion: notThrows
@ -215,7 +178,7 @@ not ok 20 - traces-in-t-throws › notThrows
test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:4
...
---tty-stream-chunk-separator
not ok 21 - traces-in-t-throws › notThrowsAsync
not ok 18 - traces-in-t-throws › notThrowsAsync
---
name: AssertionError
assertion: notThrowsAsync
@ -230,7 +193,7 @@ not ok 21 - traces-in-t-throws › notThrowsAsync
test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:4
...
---tty-stream-chunk-separator
not ok 22 - traces-in-t-throws › throwsAsync
not ok 19 - traces-in-t-throws › throwsAsync
---
name: AssertionError
assertion: throwsAsync
@ -248,7 +211,7 @@ not ok 22 - traces-in-t-throws › throwsAsync
test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:4
...
---tty-stream-chunk-separator
not ok 23 - traces-in-t-throws › throwsAsync different error
not ok 20 - traces-in-t-throws › throwsAsync different error
---
name: AssertionError
assertion: throwsAsync
@ -265,9 +228,9 @@ not ok 23 - traces-in-t-throws › throwsAsync different error
test-tap/fixture/report/regular/traces-in-t-throws.cjs:27:44
...
---tty-stream-chunk-separator
ok 24 - uncaught-exception › passes
ok 21 - uncaught-exception › passes
---tty-stream-chunk-separator
not ok 25 - Error: Can’t catch me
not ok 22 - Error: Can’t catch me
---
name: Error
message: Can’t catch me
@ -276,30 +239,30 @@ not ok 25 - Error: Can’t catch me
(test-tap/fixture/report/regular/uncaught-exception.cjs:5:9)
...
---tty-stream-chunk-separator
not ok 26 - uncaught-exception.cjs exited with a non-zero exit code: 1
not ok 23 - uncaught-exception.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
ok 27 - unhandled-rejection › passes
ok 24 - unhandled-rejection › passes
---tty-stream-chunk-separator
ok 28 - unhandled-rejection › unhandled non-error rejection
ok 25 - unhandled-rejection › unhandled non-error rejection
---tty-stream-chunk-separator
not ok 29 - Error: Can’t catch me
not ok 26 - Error: Can’t catch me
---
name: Error
message: Can’t catch me
at: 'passes (test-tap/fixture/report/regular/unhandled-rejection.cjs:4:17)'
...
---tty-stream-chunk-separator
not ok 30 - unhandled-rejection
not ok 27 - unhandled-rejection
---
message: Non-error object
formatted: 'null'
...
---tty-stream-chunk-separator
1..24
# tests 23
1..21
# tests 20
# pass 6
# skip 1
# fail 23
# fail 20
---tty-stream-chunk-separator

View file

@ -135,47 +135,7 @@ not ok 14 - test › formatted
at: 'test-tap/fixture/report/regular/test.cjs:22:4'
...
---tty-stream-chunk-separator
not ok 15 - test › power-assert
---
name: AssertionError
assertion: assert
operator: '!!'
values:
'Value is not truthy:': ''''''
at: 'test-tap/fixture/report/regular/test.cjs:27:4'
...
---tty-stream-chunk-separator
not ok 16 - test › bad throws
---
name: AssertionError
message: Improper usage of `t.throws()` detected
assertion: throws
values:
'The following error was thrown, possibly before `t.throws()` could be called:': |-
Error {
message: 'err',
}
at: |-
fn (test-tap/fixture/report/regular/test.cjs:32:9)
test-tap/fixture/report/regular/test.cjs:35:11
...
---tty-stream-chunk-separator
not ok 17 - test › bad notThrows
---
name: AssertionError
message: Improper usage of `t.notThrows()` detected
assertion: notThrows
values:
'The following error was thrown, possibly before `t.notThrows()` could be called:': |-
Error {
message: 'err',
}
at: |-
fn (test-tap/fixture/report/regular/test.cjs:40:9)
test-tap/fixture/report/regular/test.cjs:43:14
...
---tty-stream-chunk-separator
not ok 18 - test › implementation throws non-error
not ok 15 - test › implementation throws non-error
---
name: AssertionError
message: Error thrown in test
@ -184,7 +144,7 @@ not ok 18 - test › implementation throws non-error
at: ''
...
---tty-stream-chunk-separator
not ok 19 - traces-in-t-throws › throws
not ok 16 - traces-in-t-throws › throws
---
name: AssertionError
assertion: throws
@ -194,13 +154,16 @@ not ok 19 - traces-in-t-throws › throws
message: 'uh-oh',
}
'Expected instance of:': 'Function TypeError {}'
at: |-
at: >-
throwError (test-tap/fixture/report/regular/traces-in-t-throws.cjs:4:8)
test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17
t.throws.instanceOf
(test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:17)
test-tap/fixture/report/regular/traces-in-t-throws.cjs:12:4
...
---tty-stream-chunk-separator
not ok 20 - traces-in-t-throws › notThrows
not ok 17 - traces-in-t-throws › notThrows
---
name: AssertionError
assertion: notThrows
@ -215,7 +178,7 @@ not ok 20 - traces-in-t-throws › notThrows
test-tap/fixture/report/regular/traces-in-t-throws.cjs:16:4
...
---tty-stream-chunk-separator
not ok 21 - traces-in-t-throws › notThrowsAsync
not ok 18 - traces-in-t-throws › notThrowsAsync
---
name: AssertionError
assertion: notThrowsAsync
@ -230,7 +193,7 @@ not ok 21 - traces-in-t-throws › notThrowsAsync
test-tap/fixture/report/regular/traces-in-t-throws.cjs:20:4
...
---tty-stream-chunk-separator
not ok 22 - traces-in-t-throws › throwsAsync
not ok 19 - traces-in-t-throws › throwsAsync
---
name: AssertionError
assertion: throwsAsync
@ -248,7 +211,7 @@ not ok 22 - traces-in-t-throws › throwsAsync
test-tap/fixture/report/regular/traces-in-t-throws.cjs:24:4
...
---tty-stream-chunk-separator
not ok 23 - traces-in-t-throws › throwsAsync different error
not ok 20 - traces-in-t-throws › throwsAsync different error
---
name: AssertionError
assertion: throwsAsync
@ -265,9 +228,9 @@ not ok 23 - traces-in-t-throws › throwsAsync different error
test-tap/fixture/report/regular/traces-in-t-throws.cjs:27:44
...
---tty-stream-chunk-separator
ok 24 - uncaught-exception › passes
ok 21 - uncaught-exception › passes
---tty-stream-chunk-separator
not ok 25 - Error: Can’t catch me
not ok 22 - Error: Can’t catch me
---
name: Error
message: Can’t catch me
@ -276,30 +239,30 @@ not ok 25 - Error: Can’t catch me
(test-tap/fixture/report/regular/uncaught-exception.cjs:5:9)
...
---tty-stream-chunk-separator
not ok 26 - uncaught-exception.cjs exited with a non-zero exit code: 1
not ok 23 - uncaught-exception.cjs exited with a non-zero exit code: 1
---tty-stream-chunk-separator
ok 27 - unhandled-rejection › passes
ok 24 - unhandled-rejection › passes
---tty-stream-chunk-separator
ok 28 - unhandled-rejection › unhandled non-error rejection
ok 25 - unhandled-rejection › unhandled non-error rejection
---tty-stream-chunk-separator
not ok 29 - Error: Can’t catch me
not ok 26 - Error: Can’t catch me
---
name: Error
message: Can’t catch me
at: 'passes (test-tap/fixture/report/regular/unhandled-rejection.cjs:4:17)'
...
---tty-stream-chunk-separator
not ok 30 - unhandled-rejection
not ok 27 - unhandled-rejection
---
message: Non-error object
formatted: 'null'
...
---tty-stream-chunk-separator
1..24
# tests 23
1..21
# tests 20
# pass 6
# skip 1
# fail 23
# fail 20
---tty-stream-chunk-separator

View file

@ -49,21 +49,6 @@ test('sets avaAssertionError to true if indeed an assertion error', t => {
t.end();
});
test('includes statements of assertion errors', t => {
const error = new avaAssert.AssertionError({
assertion: 'true',
});
error.statements = [
['actual.a[0]', '1'],
['actual.a', '[1]'],
['actual', '{a: [1]}'],
];
const serializedError = serialize(error);
t.equal(serializedError.statements, error.statements);
t.end();
});
test('includes values of assertion errors', t => {
const error = new avaAssert.AssertionError({
assertion: 'is',

View file

@ -1,14 +1,18 @@
{
"type": "module",
"ava": {
"babel": {
"typescript": {
"rewritePaths": {
"src/": "build/"
},
"compile": false,
"extensions": [
"js",
"jsx"
"ts",
"tsx"
]
},
"extensions": [
"jsx"
"tsx"
]
}
}

View file

@ -10,8 +10,8 @@ Generated by [AVA](https://avajs.dev).
'Unexpected duplicate extensions in options: ’js’, ’jsx’.'
## errors if top-level and babel extensions include duplicates
## errors if top-level and typescript extensions include duplicates
> fails with message
'Unexpected duplicate extensions in options: ’jsx’.'
'Unexpected duplicate extensions in options: ’tsx’.'

View file

@ -4,7 +4,7 @@ import {cleanOutput, cwd, fixture} from '../helpers/exec.js';
for (const [where, which] of [
['top-level', 'top-level-duplicates'],
['top-level and babel', 'shared-duplicates'],
['top-level and typescript', 'shared-duplicates'],
]) {
test(`errors if ${where} extensions include duplicates`, async t => {
const options = {

View file

@ -21,7 +21,7 @@ export type ThrowsExpectation = {
export interface Assertions {
/**
* Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
* indicating whether the assertion passed. Comes with power-assert.
* indicating whether the assertion passed.
*/
assert: AssertAssertion;
@ -123,7 +123,7 @@ export interface Assertions {
export interface AssertAssertion {
/**
* Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), returning a boolean
* indicating whether the assertion passed. Comes with power-assert.
* indicating whether the assertion passed.
*/
(actual: any, message?: string): boolean;