Skip to content

Upgrading ava 2 to 3

Breaking2.4.0 โ†’ 3.15.0Breaking25Platform3Deprecated2New27Changed18Fixed14Other13

BreakingUpgrade verdict

22 breaking changes and 3 platform requirement changes.

  • AVA no longer transpiles your test code by itself. If you need Babel, install the separate @ava/babel package and turn it on in your config.
  • The stage-4 preset now comes from @ava/babel. The old @ava/babel-preset-transform-test-files and @ava/babel-preset-stage-4 packages are no longer maintained or bundled.
  • Config files written as .js can only use export default. If your config has dependencies, write it as a .cjs file instead.
  • The helpers setting is gone. Make sure your files patterns exclude helper files, or configure Babel to compile additional files.
Top 5 of 27 that need code or config changes

Node.js requirement changed in 3.14.0: >=8.9.4 <9 || >=10.0.0 <11 || >=12.0.0 โ†’ >=10.18.0 <11 || >=12.14.0 <12.17.0 || >=12.17.0 <13 || >=14.0.0 <15 || >=15.

Adds acorn ^8.0.4, acorn-walk ^8.0.0, arrgv ^1.0.2, callsites ^3.1.0, ci-info ^2.0.0, mem ^8.0.0, p-event ^4.2.0, p-map ^4.0.0, picomatch ^2.2.2, read-pkg ^5.2.0, temp-dir ^2.0.0, yargs ^16.2.0.

Drops @ava/babel-preset-stage-4, @ava/babel-preset-transform-test-files, @babel/core, @babel/generator, ansi-escapes, arr-flatten, array-union, array-uniq, bluebird, clean-stack, dot-prop, empower-core, escape-string-regexp, esm, find-up, get-port, is-ci, is-observable, loud-rejection, make-dir, meow, micromatch, observable-to-promise, package-hash, require-precompiled, strip-bom-buf, supports-color, trim-right, unique-temp-dir.

Installs 275 packages in all (was 448).

Also installs @types/normalize-package-data, aggregate-error, base64-js, bl, buffer, cliui, escape-goat, get-caller-file, ieee754, is-interactive, is-unicode-supported, json-parse-even-better-errors, lines-and-columns, map-age-cleaner, p-defer and 9 more.

No longer installs @ava/babel-plugin-throws-helper, @babel/compat-data, @babel/helper-annotate-as-pure, @babel/helper-compilation-targets, @babel/helper-create-regexp-features-plugin, @babel/helper-environment-visitor, @babel/helper-globals, @babel/helper-module-imports, @babel/helper-module-transforms, @babel/helper-plugin-utils, @babel/helper-remap-async-to-generator, @babel/helper-string-parser, @babel/helper-validator-option, @babel/helper-wrap-function, @babel/helpers and 120 more.

Moves ansi-regex 3.0.1, 4.1.1, 5.0.1 โ†’ 5.0.1, ansi-styles 3.2.1, 4.3.0 โ†’ 4.3.0, 5.2.0, array-union 1.0.2, 2.1.0 โ†’ 2.1.0, balanced-match 1.0.2, 4.0.4 โ†’ 1.0.2, boxen 3.2.0 โ†’ 5.1.2, brace-expansion 1.1.21, 5.0.12 โ†’ 1.1.21, camelcase 4.1.0, 5.3.1 โ†’ 6.3.0, chalk 2.4.2 โ†’ 4.1.2, chunkd 1.0.0 โ†’ 2.0.1, cli-cursor 2.1.0, 3.1.0 โ†’ 3.1.0, code-excerpt 2.1.1 โ†’ 3.0.0, color-convert 1.9.3, 2.0.1 โ†’ 2.0.1, color-name 1.1.3, 1.1.4 โ†’ 1.1.4, common-path-prefix 1.0.0 โ†’ 3.0.0, concordance 4.0.0 โ†’ 5.0.4 and 63 more. Your build may pick other versions.

Breaking22
Removes built-in Babel support from AVA; use the @ava/babel package and set babel: true in configuration.
@ava/babelbabel
Moves the ava/stage-4 preset to @ava/babel/stage-4; old Babel preset packages are no longer maintained or installed.
ava/stage-4@ava/babel/stage-4@ava/babel-preset-transform-test-files@ava/babel-preset-stage-4
ava.config.js files now only support export default; no import or __filename, and dependencies require a .cjs file.
ava.config.jsexport defaultimport__filename.cjs
Removes the helpers configuration; use files patterns to exclude helper files instead.
helpersfiles
Removes the sources configuration; use ignoredByWatcher instead, without negation.
sourcesignoredByWatcher
Removes support for old esm versions.
esm
The NODE_PATH environment variable is no longer rewritten to absolute paths.
NODE_PATH
AVA no longer fakes the TTY in worker processes.
Removes built-in Babel support; use the @ava/babel package and set babel: true in the AVA configuration instead.
@ava/babelbabel
Moves compileEnhancements into the babel configuration; t.assert() details and t.throws() checks now require Babel.
compileEnhancementsbabelt.assert()t.throws()
Default file selection no longer matches helper and fixture glob patterns under __tests__, test and tests directories.
Configuration files can only have .cjs, .js and .mjs extensions.
.cjs.js.mjs
Does not yet treat .js files as ECMAScript Modules when package.json has type: module.
type
Replaces the --reset-cache argument with a reset-cache command.
--reset-cachereset-cache
Adds npx ava reset-cache command to reset the cache.
reset-cache
The second argument to t.throws() and t.throwsAsync() must now be an expectation object.
t.throws()t.throwsAsync()
Sets a default test timeout of 10 seconds, after which worker processes are forced to quit.
Ignores likely non-test files in fixture or helper directories and in underscore-prefixed directories.
CLI glob patterns now filter the test files AVA already selected rather than adding files.
CLI again accepts glob patterns, filtering the test files already selected by configuration.
Files whose parent directory starts with a single underscore can never be test files.
test.js files are only selected next to package.json or inside top-level src and source directories.
test.jspackage.jsonsrcsource
Platform3
Removes end-of-life Node.js 13 from the test matrix and supported version list.
AVA now officially supports Node.js 14.
Supports Node.js 10, 12 and 13 with minimum versions 10.18.0, 12.14.0 and 13.5.0 respectively.
Deprecated2
Passing null as the expectation for t.throws() and t.throwsAsync() will be disallowed in AVA 4; opt in early with the disableNullExpectations experiment.
t.throws()t.throwsAsync()disableNullExpectations
Deprecates t.snapshot() in hooks, to be removed in AVA 4, behind the disableSnapshotsInHooks experiment.
t.snapshot()disableSnapshotsInHooks

Generated by DepDelta from published .d.ts files. Not mixed with prose notes.

  • removed: call ThrowsAssertion<ThrownError extends Error>(fn: () => any, errorMessage: string, message?: string): ThrownError
  • removed: call ThrowsAssertion<ThrownError extends Error>(fn: () => any, expectations: ThrowsExpectation, message?: string): ThrownError
  • removed: call ThrowsAssertion<ThrownError extends Error>(fn: () => any, expectations?: null, message?: string): ThrownError
  • removed: call ThrowsAssertion<ThrownError extends Error>(fn: () => any, regex: RegExp, message?: string): ThrownError
  • removed: call ThrowsAsyncAssertion<ThrownError extends Error>(fn: () => PromiseLike<any>, constructor: Constructor, message?: string): Promise<ThrownError>
  • removed: call ThrowsAsyncAssertion<ThrownError extends Error>(fn: () => PromiseLike<any>, errorMessage: string, message?: string): Promise<ThrownError>
  • removed: call ThrowsAsyncAssertion<ThrownError extends Error>(fn: () => PromiseLike<any>, regex: RegExp, message?: string): Promise<ThrownError>
  • removed: call ThrowsAsyncAssertion<ThrownError extends Error>(promise: PromiseLike<any>, constructor: Constructor, message?: string): Promise<ThrownError>
  • removed: call ThrowsAsyncAssertion<ThrownError extends Error>(promise: PromiseLike<any>, errorMessage: string, message?: string): Promise<ThrownError>
  • removed: call ThrowsAsyncAssertion<ThrownError extends Error>(promise: PromiseLike<any>, regex: RegExp, message?: string): Promise<ThrownError>
  • removed: interface ObservableLike
  • removed: method ObservableLike.subscribe(observer: (value: unknown) => void): void
  • removed: method ObservableLike[Symbol.observable](): ObservableLike
  • changed: call LogFn(...values: Array<any>): void โ†’ call LogFn(...values: any[]): void
  • changed: call ThrowsAssertion<ThrownError extends Error>(fn: () => any, constructor: Constructor, message?: string): ThrownError โ†’ call ThrowsAssertion<ThrownError extends Error>(fn: () => any, expectations?: ThrowsExpectation | null, message?: string): ThrownError
  • changed: call TimeoutFn(ms: number): void โ†’ call TimeoutFn(ms: number, message?: string): void
  • changed: call TryFn<Args extends any[]>(fn: [EitherMacro<Args, Context>, ...EitherMacro<Args, Context>[]], ...args: Args): Promise<TryResult[]> โ†’ call TryFn<Args extends any[]>(fn: [EitherMacro<Args, Context>, ...Array<EitherMacro<Args, Context>>], ...args: Args): Promise<TryResult[]>
  • changed: call TryFn<Args extends any[]>(title: string, fn: [EitherMacro<Args, Context>, ...EitherMacro<Args, Context>[]], ...args: Args): Promise<TryResult[]> โ†’ call TryFn<Args extends any[]>(title: string, fn: [EitherMacro<Args, Context>, ...Array<EitherMacro<Args, Context>>], ...args: Args): Promise<TryResult[]>
  • changed: method LogFn.skip(...values: Array<any>): void โ†’ method LogFn.skip(...values: any[]): void
  • changed: type Constructor = (new (...args: Array<any>) => any) โ†’ type Constructor = (new (...args: any[]) => any)
  • changed: type ImplementationResult = PromiseLike<void> | ObservableLike | void โ†’ type ImplementationResult = PromiseLike<void> | Subscribable | void
  • changed: type OneOrMoreCbMacros<Args extends any[], Context> = EitherCbMacro<Args, Context> | [EitherCbMacro<Args, Context>, ...EitherCbMacro<Args, Context>[]] โ†’ type OneOrMoreCbMacros<Args extends any[], Context> = EitherCbMacro<Args, Context> | [EitherCbMacro<Args, Context>, ...Array<EitherCbMacro<Args, Context>>]
  • changed: type OneOrMoreMacros<Args extends any[], Context> = EitherMacro<Args, Context> | [EitherMacro<Args, Context>, ...EitherMacro<Args, Context>[]] โ†’ type OneOrMoreMacros<Args extends any[], Context> = EitherMacro<Args, Context> | [EitherMacro<Args, Context>, ...Array<EitherMacro<Args, Context>>]
  • added: call LikeAssertion(value: any, selector: Record<string, any>, message?: string): void
  • added: call TeardownFn(fn: () => void): void
  • added: interface LikeAssertion
  • added: interface Subscribable
  • added: interface TeardownFn
  • added: method LikeAssertion.skip(value: any, selector: any, message?: string): void
  • added: method Subscribable.subscribe(observer: { error(err: any): void; complete(): void }): void
  • added: property Assertions.like: LikeAssertion
  • added: property ExecutionContext.teardown: TeardownFn
  • added: property MetaInterface.snapshotDirectory: string
  • added: readonly property ExecutionContext.passed: boolean
  • added: function registerSharedWorker<Data = unknown>(options: SharedWorker.Plugin.RegistrationOptions<'experimental', Data>): SharedWorker.Plugin.Experimental.Protocol<Data>
  • added: namespace SharedWorker
  • added: namespace SharedWorker.Experimental
  • added: namespace SharedWorker.Plugin
  • added: namespace SharedWorker.Plugin.Experimental
  • added: type SharedWorker.Experimental.BroadcastMessage<Data = unknown> = { readonly id: string; replies: () => AsyncIterableIterator<ReceivedMessage<Data>> }
  • added: type SharedWorker.Experimental.Protocol<Data = unknown> = { readonly initialData: Data; readonly protocol: 'experimental'; broadcast: (data: Data) => BroadcastMessage<Data>; ready: () => Protocol<Data>; subscribe: ()โ€ฆ
  • added: type SharedWorker.Experimental.PublishedMessage<Data = unknown> = { readonly id: string; replies: () => AsyncIterableIterator<ReceivedMessage<Data>> }
  • added: type SharedWorker.Experimental.ReceivedMessage<Data = unknown> = { readonly data: Data; readonly id: string; readonly testWorker: TestWorker; reply: (data: Data) => PublishedMessage<Data> }
  • added: type SharedWorker.Experimental.TestWorker<Data = unknown> = { readonly id: string; readonly file: string; publish: (data: Data) => PublishedMessage<Data>; subscribe: () => AsyncIterableIterator<ReceivedMessage<Data>>; tโ€ฆ
  • added: type SharedWorker.Factory = (options: FactoryOptions) => void
  • added: type SharedWorker.FactoryOptions = { negotiateProtocol <Data = unknown>(supported: readonly ['experimental']): Experimental.Protocol<Data> }
  • added: type SharedWorker.Plugin.Experimental.Protocol<Data = unknown> = { readonly available: Promise<void>; readonly currentlyAvailable: boolean; readonly protocol: 'experimental'; publish: (data: Data) => PublishedMessage<Data>;โ€ฆ
  • added: type SharedWorker.Plugin.Experimental.PublishedMessage<Data = unknown> = { readonly id: string; replies: () => AsyncIterableIterator<ReceivedMessage<Data>> }
  • added: type SharedWorker.Plugin.Experimental.ReceivedMessage<Data = unknown> = { readonly data: Data; readonly id: string; reply: (data: Data) => PublishedMessage<Data> }
  • added: type SharedWorker.Plugin.RegistrationOptions<Identifier extends ProtocolIdentifier, Data = unknown> = { readonly filename: string; readonly initialData?: Data; readonly supportedProtocols: readonly Identifier[]; readonly teardown?: () => void }
  • added: type SharedWorker.ProtocolIdentifier = 'experimental'