Skip to content

Commit

Permalink
Remove Babel support, and therefore enhanced assertions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
novemberborn committed Sep 19, 2021
1 parent 6d9c4d7 commit 678f9ca
Show file tree
Hide file tree
Showing 57 changed files with 249 additions and 1,965 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/03-assertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
7 changes: 4 additions & 3 deletions docs/05-command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/06-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions docs/08-common-pitfalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/recipes/babel.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:**
Expand Down
2 changes: 1 addition & 1 deletion docs/recipes/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion docs/recipes/vue.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
83 changes: 17 additions & 66 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -258,7 +251,6 @@ export class Assertions {
fail = notImplemented,
skip = notImplemented,
compareWithSnapshot = notImplemented,
powerAssert,
experiments = {},
disableSnapshots = false,
} = {}) {
Expand All @@ -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;
};
Expand Down Expand Up @@ -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;
});
}
}
19 changes: 5 additions & 14 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.');
}
Expand All @@ -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);
Expand Down
9 changes: 0 additions & 9 deletions lib/eslint-plugin-helper-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
3 changes: 0 additions & 3 deletions lib/provider-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down
4 changes: 0 additions & 4 deletions lib/reporters/beautify-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
8 changes: 1 addition & 7 deletions lib/reporters/format-serialized-error.js
Original file line number Diff line number Diff line change
@@ -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};
}

Expand All @@ -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};
}
13 changes: 0 additions & 13 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion lib/serialize-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 678f9ca

Please sign in to comment.