diff --git a/docs/recipes/flow.md b/docs/recipes/flow.md index 6941e6479..29efaf046 100644 --- a/docs/recipes/flow.md +++ b/docs/recipes/flow.md @@ -2,7 +2,9 @@ Translations: [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/docs/recipes/flow.md) -AVA comes bundled with a Flow definition file. This allows developers to leverage Flow for writing tests. +Until [1.4.1](https://github.com/avajs/ava/releases/tag/v1.4.1) AVA came bundled with a Flow definition file. This allows developers to leverage Flow for writing tests. + +**We need some help publishing the type definitions outside of AVA. Please join us in https://github.com/avajs/flow-typed/issues/1 if you'd like to help out.** This guide assumes you've already set up Flow for your project. Note that AVA's definition as been tested with version 0.95.1. diff --git a/index.js.flow b/index.js.flow deleted file mode 100644 index cc31f065f..000000000 --- a/index.js.flow +++ /dev/null @@ -1,788 +0,0 @@ -// @flow -export interface PromiseLike { - then(onFulfill: null | void, onReject: null | void): Promise; - then( - onFulfill: null | void, - onReject: (error: any) => Promise | U - ): Promise; - then( - onFulfill: (value: R) => Promise | U, - onReject: null | void | ((error: any) => Promise | U) - ): Promise; -} - -export interface ObservableLike { - subscribe(observer: (value: any) => void): void; -} - -export type Constructor = Class<{constructor(...args: Array): any}>; - -/** Specify one or more expectations the thrown error must satisfy. */ -export type ThrowsExpectation = { - /** The thrown error must have a code that equals the given string or number. */ - code?: string | number; - - /** The thrown error must be an instance of this constructor. */ - instanceOf?: Constructor; - - /** The thrown error must be strictly equal to this value. */ - is?: Error; - - /** The thrown error must have a message that equals the given string, or matches the regular expression. */ - message?: string | RegExp; - - /** The thrown error must have a name that equals the given string. */ - name?: string; -}; - -/** Options that can be passed to the `t.snapshot()` assertion. */ -export type SnapshotOptions = { - /** If provided and not an empty string, used to select the snapshot to compare the `expected` value against. */ - id?: string; -}; - -export interface Assertions { - /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). Comes with power-assert. */ - assert: AssertAssertion; - - /** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */ - deepEqual: DeepEqualAssertion; - - /** Fail the test. */ - fail: FailAssertion; - - /** Assert that `actual` is strictly false. */ - false: FalseAssertion; - - /** Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */ - falsy: FalsyAssertion; - - /** - * Assert that `actual` is [the same - * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`. - */ - is: IsAssertion; - - /** - * Assert that `actual` is not [the same - * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`. - */ - not: NotAssertion; - - /** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */ - notDeepEqual: NotDeepEqualAssertion; - - /** Assert that `string` does not match the regular expression. */ - notRegex: NotRegexAssertion; - - /** Assert that the function does not throw. */ - notThrows: NotThrowsAssertion; - - /** Assert that the async function does not throw, or that the promise does not reject. Must be awaited. */ - notThrowsAsync: NotThrowsAsyncAssertion; - - /** Count a passing assertion. */ - pass: PassAssertion; - - /** Assert that `string` matches the regular expression. */ - regex: RegexAssertion; - - /** - * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a - * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if - * necessary record a new snapshot. - */ - snapshot: SnapshotAssertion; - - /** - * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value. - */ - throws: ThrowsAssertion; - - /** - * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error), or the promise rejects - * with one. If so, returns a promise for the error value, which must be awaited. - */ - throwsAsync: ThrowsAsyncAssertion; - - /** Assert that `actual` is strictly true. */ - true: TrueAssertion; - - /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */ - truthy: TruthyAssertion; -} - -export interface AssertAssertion { - /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). Comes with power-assert. */ - (actual: any, message?: string): void; - - /** Skip this assertion. */ - skip(actual: any, message?: string): void; -} - -export interface DeepEqualAssertion { - /** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */ - (actual: any, expected: any, message?: string): void; - - /** Skip this assertion. */ - skip(actual: any, expected: any, message?: string): void; -} - -export interface FailAssertion { - /** Fail the test. */ - (message?: string): void; - - /** Skip this assertion. */ - skip(message?: string): void; -} - -export interface FalseAssertion { - /** Assert that `actual` is strictly false. */ - (actual: any, message?: string): void; - - /** Skip this assertion. */ - skip(actual: any, message?: string): void; -} - -export interface FalsyAssertion { - /** Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */ - (actual: any, message?: string): void; - - /** Skip this assertion. */ - skip(actual: any, message?: string): void; -} - -export interface IsAssertion { - /** - * Assert that `actual` is [the same - * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`. - */ - (actual: any, expected: any, message?: string): void; - - /** Skip this assertion. */ - skip(actual: any, expected: any, message?: string): void; -} - -export interface NotAssertion { - /** - * Assert that `actual` is not [the same - * value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`. - */ - (actual: any, expected: any, message?: string): void; - - /** Skip this assertion. */ - skip(actual: any, expected: any, message?: string): void; -} - -export interface NotDeepEqualAssertion { - /** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */ - (actual: any, expected: any, message?: string): void; - - /** Skip this assertion. */ - skip(actual: any, expected: any, message?: string): void; -} - -export interface NotRegexAssertion { - /** Assert that `string` does not match the regular expression. */ - (string: string, regex: RegExp, message?: string): void; - - /** Skip this assertion. */ - skip(string: string, regex: RegExp, message?: string): void; -} - -export interface NotThrowsAssertion { - /** Assert that the function does not throw. */ - (fn: () => any, message?: string): void; - - /** Skip this assertion. */ - skip(fn: () => any, message?: string): void; -} - -export interface NotThrowsAsyncAssertion { - /** Assert that the async function does not throw. You must await the result. */ - (fn: () => PromiseLike, message?: string): Promise; - - /** Assert that the promise does not reject. You must await the result. */ - (promise: PromiseLike, message?: string): Promise; - - /** Skip this assertion. */ - skip(nonThrower: any, message?: string): void; -} - -export interface PassAssertion { - /** Count a passing assertion. */ - (message?: string): void; - - /** Skip this assertion. */ - skip(message?: string): void; -} - -export interface RegexAssertion { - /** Assert that `string` matches the regular expression. */ - (string: string, regex: RegExp, message?: string): void; - - /** Skip this assertion. */ - skip(string: string, regex: RegExp, message?: string): void; -} - -export interface SnapshotAssertion { - /** - * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a - * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details), or if - * necessary record a new snapshot. - */ - (expected: any, message?: string): void; - - /** - * Assert that `expected` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to a - * previously recorded [snapshot](https://github.com/concordancejs/concordance#serialization-details) (selected - * through `options.id` if provided), or if necessary record a new snapshot. - */ - (expected: any, options: SnapshotOptions, message?: string): void; - - /** Skip this assertion. */ - skip(expected: any, message?: string): void; - - /** Skip this assertion. */ - skip(expected: any, options: SnapshotOptions, message?: string): void; -} - -export interface ThrowsAssertion { - /** - * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value. - */ - (fn: () => any, expectations?: null, message?: string): ThrownError; - - /** - * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value. - * The error must be an instance of the given constructor. - */ - (fn: () => any, constructor: Constructor, message?: string): ThrownError; - - /** - * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value. - * The error must have a message that matches the regular expression. - */ - (fn: () => any, regex: RegExp, message?: string): ThrownError; - - /** - * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value. - * The error must have a message equal to `errorMessage`. - */ - (fn: () => any, errorMessage: string, message?: string): ThrownError; - - /** - * Assert that the function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error value. - * The error must satisfy all expectations. - */ - (fn: () => any, expectations: ThrowsExpectation, message?: string): ThrownError; - - /** Skip this assertion. */ - skip(fn: () => any, expectations?: any, message?: string): void; -} - -export interface ThrowsAsyncAssertion { - /** - * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error - * value. You must await the result. - */ - (fn: () => PromiseLike, expectations?: null, message?: string): Promise; - - /** - * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error - * value. You must await the result. The error must be an instance of the given constructor. - */ - (fn: () => PromiseLike, constructor: Constructor, message?: string): Promise; - - /** - * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error - * value. You must await the result. The error must have a message that matches the regular expression. - */ - (fn: () => PromiseLike, regex: RegExp, message?: string): Promise; - - /** - * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error - * value. You must await the result. The error must have a message equal to `errorMessage`. - */ - (fn: () => PromiseLike, errorMessage: string, message?: string): Promise; - - /** - * Assert that the async function throws [an error](https://www.npmjs.com/package/is-error). If so, returns the error - * value. You must await the result. The error must satisfy all expectations. - */ - (fn: () => PromiseLike, expectations: ThrowsExpectation, message?: string): Promise; - - /** - * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the - * rejection reason. You must await the result. - */ - (promise: PromiseLike, expectations?: null, message?: string): Promise; - - /** - * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the - * rejection reason. You must await the result. The error must be an instance of the given constructor. - */ - (promise: PromiseLike, constructor: Constructor, message?: string): Promise; - - /** - * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the - * rejection reason. You must await the result. The error must have a message that matches the regular expression. - */ - (promise: PromiseLike, regex: RegExp, message?: string): Promise; - - /** - * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the - * rejection reason. You must await the result. The error must have a message equal to `errorMessage`. - */ - (promise: PromiseLike, errorMessage: string, message?: string): Promise; - - /** - * Assert that the promise rejects with [an error](https://www.npmjs.com/package/is-error). If so, returns the - * rejection reason. You must await the result. The error must satisfy all expectations. - */ - (promise: PromiseLike, expectations: ThrowsExpectation, message?: string): Promise; - - /** Skip this assertion. */ - skip(thrower: any, expectations?: any, message?: string): void; -} - -export interface TrueAssertion { - /** Assert that `actual` is strictly true. */ - (actual: any, message?: string): void; - - /** Skip this assertion. */ - skip(actual: any, message?: string): void; -} - -export interface TruthyAssertion { - /** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */ - (actual: any, message?: string): void; - - /** Skip this assertion. */ - skip(actual: any, message?: string): void; -} - -/** The `t` value passed to test & hook implementations. */ -export interface ExecutionContext extends Assertions { - /** Test context, shared with hooks. */ - context: Context; - - /** Title of the test or hook. */ - +title: string; - - log: LogFn; - plan: PlanFn; - timeout: TimeoutFn; -} - -export interface LogFn { - /** Log one or more values. */ - (...values: Array): void; - - /** Skip logging. */ - skip(...values: Array): void; -} - -export interface PlanFn { - /** - * Plan how many assertion there are in the test. The test will fail if the actual assertion count doesn't match the - * number of planned assertions. See [assertion planning](https://github.com/avajs/ava#assertion-planning). - */ - (count: number): void; - - /** Don't plan assertions. */ - skip(count: number): void; -} - -export interface TimeoutFn { - /** - * Set a timeout for the test, in milliseconds. The test will fail if the timeout is exceeded. - * The timeout is reset each time an assertion is made. - */ - (ms: number): void; -} - -/** The `t` value passed to implementations for tests & hooks declared with the `.cb` modifier. */ -export interface CbExecutionContext extends ExecutionContext { - /** - * End the test. If `error` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy) the test or hook - * will fail. - */ - end(error?: any): void; -} - -export type ImplementationResult = PromiseLike | ObservableLike | void; -export type Implementation = (t: ExecutionContext) => ImplementationResult; -export type CbImplementation = (t: CbExecutionContext) => ImplementationResult; - -/** A reusable test or hook implementation. */ -export interface Macro { - (t: ExecutionContext, ...args: Array): ImplementationResult; - - /** - * Implement this function to generate a test (or hook) title whenever this macro is used. `providedTitle` contains - * the title provided when the test or hook was declared. Also receives the remaining test arguments. - */ - title?: (providedTitle: string | void, ...args: Array) => string; -} - -/** A reusable test or hook implementation, for tests & hooks declared with the `.cb` modifier. */ -export interface CbMacro { - (t: CbExecutionContext, ...args: Array): ImplementationResult; - title?: (providedTitle: string | void, ...args: Array) => string; -} - -export interface TestInterface { - /** Declare a concurrent test. */ - (title: string, implementation: Implementation | Macro): void; - - /** Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro. */ - (title: string, macro: Macro | Macro[], ...args: Array): void; - - /** - * Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro. The macro - * is responsible for generating a unique test title. - */ - (macro: Macro | Macro[], ...args: Array): void; - - /** Declare a hook that is run once, after all tests have passed. */ - after: AfterInterface; - - /** Declare a hook that is run after each passing test. */ - afterEach: AfterInterface; - - /** Declare a hook that is run once, before all tests. */ - before: BeforeInterface; - - /** Declare a hook that is run before each test. */ - beforeEach: BeforeInterface; - - /** Declare a test that must call `t.end()` when it's done. */ - cb: CbInterface; - - /** Declare a test that is expected to fail. */ - failing: FailingInterface; - - /** Declare tests and hooks that are run serially. */ - serial: SerialInterface; - - only: OnlyInterface; - skip: SkipInterface; - todo: TodoDeclaration; -} - -export interface AfterInterface { - /** Declare a hook that is run once, after all tests have passed. */ - (implementation: Implementation | Macro): void; - - /** Declare a hook that is run once, after all tests have passed. Additional argumens are passed to the macro. */ - (macro: Macro | Macro[], ...args: Array): void; - - /** Declare a hook that is run once, after all tests have passed. */ - (title: string, implementation: Implementation | Macro): void; - - /** Declare a hook that is run once, after all tests have passed. Additional argumens are passed to the macro. */ - (title: string, macro: Macro | Macro[], ...args: Array): void; - - /** Declare a hook that is run once, after all tests are done. */ - always: AlwaysInterface; - - /** Declare a hook that must call `t.end()` when it's done. */ - cb: HookCbInterface; - - skip: HookSkipInterface; -} - -export interface AlwaysInterface { - /** Declare a hook that is run once, after all tests are done. */ - (implementation: Implementation | Macro): void; - - /** Declare a hook that is run once, after all tests are done. Additional argumens are passed to the macro. */ - (macro: Macro | Macro[], ...args: Array): void; - - /** Declare a hook that is run once, after all tests are done. */ - (title: string, implementation: Implementation | Macro): void; - - /** Declare a hook that is run once, after all tests are done. Additional argumens are passed to the macro. */ - (title: string, macro: Macro | Macro[], ...args: Array): void; - - /** Declare a hook that must call `t.end()` when it's done. */ - cb: HookCbInterface; - - skip: HookSkipInterface; -} - -export interface BeforeInterface { - /** Declare a hook that is run once, before all tests. */ - (implementation: Implementation | Macro): void; - - /** Declare a hook that is run once, before all tests. Additional argumens are passed to the macro. */ - (macro: Macro | Macro[], ...args: Array): void; - - /** Declare a hook that is run once, before all tests. */ - (title: string, implementation: Implementation | Macro): void; - - /** Declare a hook that is run once, before all tests. Additional argumens are passed to the macro. */ - (title: string, macro: Macro | Macro[], ...args: Array): void; - - /** Declare a hook that must call `t.end()` when it's done. */ - cb: HookCbInterface; - - skip: HookSkipInterface; -} - -export interface CbInterface { - /** Declare a test that must call `t.end()` when it's done. */ - (title: string, implementation: CbImplementation | CbMacro): void; - - /** - * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done. - * Additional arguments are passed to the macro. - */ - (title: string, macro: CbMacro | CbMacro[], ...args: Array): void; - - /** - * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done. - * Additional arguments are passed to the macro. The macro is responsible for generating a unique test title. - */ - (macro: CbMacro | CbMacro[], ...args: Array): void; - - /** Declare a test that is expected to fail. */ - failing: CbFailingInterface; - - only: CbOnlyInterface; - skip: CbSkipInterface; -} - -export interface CbFailingInterface { - /** Declare a test that must call `t.end()` when it's done. The test is expected to fail. */ - (title: string, implementation: CbImplementation | CbMacro): void; - - /** - * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done. - * Additional arguments are passed to the macro. The test is expected to fail. - */ - (title: string, macro: CbMacro | CbMacro[], ...args: Array): void; - - /** - * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done. - * Additional arguments are passed to the macro. The macro is responsible for generating a unique test title. - * The test is expected to fail. - */ - (macro: CbMacro | CbMacro[], ...args: Array): void; - - only: CbOnlyInterface; - skip: CbSkipInterface; -} - -export interface CbOnlyInterface { - /** - * Declare a test that must call `t.end()` when it's done. Only this test and others declared with `.only()` are run. - */ - (title: string, implementation: CbImplementation | CbMacro): void; - - /** - * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done. - * Additional arguments are passed to the macro. Only this test and others declared with `.only()` are run. - */ - (title: string, macro: CbMacro | CbMacro[], ...args: Array): void; - - /** - * Declare a test that uses one or more macros. The macros must call `t.end()` when they're done. - * Additional arguments are passed to the macro. The macro is responsible for generating a unique test title. - * Only this test and others declared with `.only()` are run. - */ - (macro: CbMacro | CbMacro[], ...args: Array): void; -} - -export interface CbSkipInterface { - /** Skip this test. */ - (title: string, implementation: CbImplementation | CbMacro): void; - - /** Skip this test. */ - (title: string, macro: CbMacro | CbMacro[], ...args: Array): void; - - /** Skip this test. */ - (macro: CbMacro | CbMacro[], ...args: Array): void; -} - -export interface FailingInterface { - /** Declare a concurrent test. The test is expected to fail. */ - (title: string, implementation: Implementation | Macro): void; - - /** - * Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro. - * The test is expected to fail. - */ - (title: string, macro: Macro | Macro[], ...args: Array): void; - - /** - * Declare a concurrent test that uses one or more macros. Additional arguments are passed to the macro. The macro - * is responsible for generating a unique test title. The test is expected to fail. - */ - (macro: Macro | Macro[], ...args: Array): void; - - only: OnlyInterface; - skip: SkipInterface; -} - -export interface HookCbInterface { - /** Declare a hook that must call `t.end()` when it's done. */ - (implementation: CbImplementation | CbMacro): void; - - /** - * Declare a hook that uses one or more macros. The macros must call `t.end()` when they're done. - * Additional arguments are passed to the macro. - */ - (macro: CbMacro | CbMacro[], ...args: Array): void; - - /** Declare a hook that must call `t.end()` when it's done. */ - (title: string, implementation: CbImplementation | CbMacro): void; - - /** - * Declare a hook that uses one or more macros. The macros must call `t.end()` when they're done. - * Additional arguments are passed to the macro. - */ - (title: string, macro: CbMacro | CbMacro[], ...args: Array): void; - - skip: HookCbSkipInterface; -} - -export interface HookCbSkipInterface { - /** Skip this hook. */ - (implementation: CbImplementation | CbMacro): void; - - /** Skip this hook. */ - (macro: CbMacro | CbMacro[], ...args: Array): void; - - /** Skip this hook. */ - (title: string, implementation: CbImplementation | CbMacro): void; - - /** Skip this hook. */ - (title: string, macro: CbMacro | CbMacro[], ...args: Array): void; -} - -export interface HookSkipInterface { - /** Skip this hook. */ - (implementation: Implementation | Macro): void; - - /** Skip this hook. */ - (macro: Macro | Macro[], ...args: Array): void; - - /** Skip this hook. */ - (title: string, implementation: Implementation | Macro): void; - - /** Skip this hook. */ - (title: string, macro: Macro | Macro[], ...args: Array): void; -} - -export interface OnlyInterface { - /** Declare a test. Only this test and others declared with `.only()` are run. */ - (title: string, implementation: Implementation | Macro): void; - - /** - * Declare a test that uses one or more macros. Additional arguments are passed to the macro. - * Only this test and others declared with `.only()` are run. - */ - (title: string, macro: Macro | Macro[], ...args: Array): void; - - /** - * Declare a test that uses one or more macros. Additional arguments are passed to the macro. The macro - * is responsible for generating a unique test title. Only this test and others declared with `.only()` are run. - */ - (macro: Macro | Macro[], ...args: Array): void; -} - -export interface SerialInterface { - /** Declare a serial test. */ - (title: string, implementation: Implementation | Macro): void; - - /** Declare a serial test that uses one or more macros. Additional arguments are passed to the macro. */ - (title: string, macro: Macro | Macro[], ...args: Array): void; - - /** - * Declare a serial test that uses one or more macros. Additional arguments are passed to the macro. The macro - * is responsible for generating a unique test title. - */ - (macro: Macro | Macro[], ...args: Array): void; - - /** Declare a serial hook that is run once, after all tests have passed. */ - after: AfterInterface; - - /** Declare a serial hook that is run after each passing test. */ - afterEach: AfterInterface; - - /** Declare a serial hook that is run once, before all tests. */ - before: BeforeInterface; - - /** Declare a serial hook that is run before each test. */ - beforeEach: BeforeInterface; - - /** Declare a serial test that must call `t.end()` when it's done. */ - cb: CbInterface; - - /** Declare a serial test that is expected to fail. */ - failing: FailingInterface; - - only: OnlyInterface; - skip: SkipInterface; - todo: TodoDeclaration; - meta: MetaInterface; -} - -export interface SkipInterface { - /** Skip this test. */ - (title: string, implementation: Implementation | Macro): void; - - /** Skip this test. */ - (title: string, macro: Macro | Macro[], ...args: Array): void; - - /** Skip this test. */ - (macro: Macro | Macro[], ...args: Array): void; -} - -export interface TodoDeclaration { - /** Declare a test that should be implemented later. */ - (title: string): void; -} - -export interface MetaInterface { - /** Path to the test file being executed. */ - file: string; -} - -/** Call to declare a test, or chain to declare hooks or test modifiers */ -declare export default TestInterface<>; - -/** Call to declare a hook that is run after each passing test, or chain to declare modifiers. */ -declare export var after: AfterInterface<>; - -/** Call to declare a hook that is run once, before all tests, or chain to declare modifiers. */ -declare export var afterEach: AfterInterface<>; - -/** Call to declare a hook that is run before each test, or chain to declare modifiers. */ -declare export var before: BeforeInterface<>; - -/** Call to declare a test that must invoke `t.end()` when it's done, or chain to declare modifiers. */ -declare export var beforeEach: BeforeInterface<>; - -/** Call to declare a test that must invoke `t.end()` when it's done, or chain to declare modifiers. */ -declare export var cb: CbInterface<>; - -/** Call to declare a test that is expected to fail, or chain to declare modifiers. */ -declare export var failing: FailingInterface<>; - -/** Call to declare a test that is run exclusively, along with other tests declared with `.only()`. */ -declare export var only: OnlyInterface<>; - -/** Call to declare a serial test, or chain to declare serial hooks or test modifiers. */ -declare export var serial: SerialInterface<>; - -/** Skip this test. */ -declare export var skip: SkipInterface<>; - -/** Declare a test that should be implemented later. */ -declare export var todo: TodoDeclaration; - -/** Meta data associated with the current process. */ -declare export var meta: MetaInterface; diff --git a/package-lock.json b/package-lock.json index b91320636..7bbf03c39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3086,12 +3086,6 @@ "integrity": "sha512-R+H8IZclI8AAkSBRQJLVOsxwAoHd6WC40b4QTNWIjzAa6BXOBfQcM587MXDTVPeYaopFNWHUFLx7eNmHDSxMWg==", "dev": true }, - "flow-bin": { - "version": "0.95.1", - "resolved": "https://registry.npmjs.org/flow-bin/-/flow-bin-0.95.1.tgz", - "integrity": "sha512-06IOC/pqPMNRYtC6AMZEWYR9Fi6UdBC7gImGinPuNUpPZFnP5E9/0cBCl3DWrH4zz/gSM2HdDilU7vPGpYIr2w==", - "dev": true - }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", diff --git a/package.json b/package.json index 0e2d2d543..f0e1eb218 100644 --- a/package.json +++ b/package.json @@ -11,15 +11,13 @@ }, "scripts": { "lint": "xo", - "test:flow": "flow check test/flow-types", "test:tap": "tap --no-esm --no-cov --reporter=classic --timeout=300 --jobs=2 test/*.js test/reporters/*.js test/integration/*.js", "test:typescript": "tsc --noEmit -p test/ts-types", - "test": "npm run lint && npm run test:flow && npm run test:typescript && nyc npm run test:tap" + "test": "npm run lint && npm run test:typescript && nyc npm run test:tap" }, "files": [ "lib", "*.js", - "*.js.flow", "index.d.ts" ], "keywords": [ @@ -56,8 +54,7 @@ "unit", "snapshot", "expect", - "typescript", - "flow" + "typescript" ], "dependencies": { "@ava/babel-preset-stage-4": "^2.0.0", @@ -147,7 +144,6 @@ "codecov": "^3.2.0", "delay": "^4.1.0", "execa": "^1.0.0", - "flow-bin": "^0.95.1", "get-stream": "^4.1.0", "git-branch": "^2.0.1", "has-ansi": "^3.0.0", diff --git a/test/flow-types/.flowconfig b/test/flow-types/.flowconfig deleted file mode 100644 index 23066fc9c..000000000 --- a/test/flow-types/.flowconfig +++ /dev/null @@ -1,6 +0,0 @@ -[include] -../../*.js.flow$ - -[options] -emoji=true -suppress_comment=\\(.\\|\n\\)*\\$ExpectError diff --git a/test/flow-types/log.js b/test/flow-types/log.js deleted file mode 100644 index 83d6a0645..000000000 --- a/test/flow-types/log.js +++ /dev/null @@ -1,7 +0,0 @@ -// @flow -import test from '../../index.js.flow'; - -test('log', t => { - t.pass(); - t.log({object: true}, 42, ['array'], false, new Date(), new Map()); -}); diff --git a/test/flow-types/regression-1114.js b/test/flow-types/regression-1114.js deleted file mode 100644 index 7459cae90..000000000 --- a/test/flow-types/regression-1114.js +++ /dev/null @@ -1,45 +0,0 @@ -// @flow -import test from '../../index.js.flow'; - -test('Named test', t => { - t.pass('Success'); - // $ExpectError: Unknown method "unknownAssertion" - t.unknownAssertion('Whoops'); - // $ExpectError: Unknown method "end" - t.end(); -}); - -test('test', t => { - t.pass('Success'); - // $ExpectError: Unknown method "unknownAssertion" - t.unknownAssertion('Whoops'); - // $ExpectError: Unknown method "end" - t.end(); -}); - -test.cb('test', t => { - t.pass('Success'); - t.end(); -}); - -function macro(t, input, expected) { - t.is(eval(input), expected); // eslint-disable-line no-eval -} -macro.title = (title, input) => title || input; - -function macro2(t, input, expected) { - t.is(eval(input), expected); // eslint-disable-line no-eval -} - -test('2 + 2 === 4', macro, '2 + 2', 4); -test(macro, '2 * 3', 6); - -test('2 + 2 === 4', [macro, macro2], '2 + 2', 4); -test([macro, macro2], '2 * 3', 6); - -function macroBadTitle(t, input, expected) { - t.is(eval(input), expected); // eslint-disable-line no-eval -} -macroBadTitle.title = 'Not a function'; -// $ExpectError: Macro "title" is not a function -test('2 + 2 === 4', macroBadTitle, '2 + 2', 4); diff --git a/test/flow-types/regression-1148.js.flow b/test/flow-types/regression-1148.js.flow deleted file mode 100644 index 7bb5b4664..000000000 --- a/test/flow-types/regression-1148.js.flow +++ /dev/null @@ -1,16 +0,0 @@ -// @flow -import test from '../../index.js.flow'; - -test('test', async t => { - t.throws(() => { throw new Error(); }); - await t.throwsAsync(Promise.reject(new Error())); - - t.notThrows(() => { return; }); - await t.notThrowsAsync(Promise.resolve('Success')); - - const error = t.throws(() => { throw new Error(); }); - const message: string = error.message; - - const errorAsync = await t.throwsAsync(Promise.reject(new Error())); - const messageAsync: string = errorAsync.message; -}); diff --git a/test/flow-types/regression-1500.js b/test/flow-types/regression-1500.js deleted file mode 100644 index 1d0a92019..000000000 --- a/test/flow-types/regression-1500.js +++ /dev/null @@ -1,16 +0,0 @@ -// @flow -import test from '../../index.js.flow'; - -test('test', t => { - t.snapshot({}); - t.snapshot({}, 'a message'); - t.snapshot({}, {id: 'snapshot-id'}); - t.snapshot({}, {id: 'snapshot-id'}, 'a message'); - - // $ExpectError Message should be a string - t.snapshot({}, 1); - // $ExpectError unknownOption is an unknown options attribute - t.snapshot({}, {unknownOption: true}); - // $ExpectError Message should be a string - t.snapshot({}, {id: 'snapshot-id'}, 1); -}); diff --git a/test/flow-types/throws.js b/test/flow-types/throws.js deleted file mode 100644 index f274ca360..000000000 --- a/test/flow-types/throws.js +++ /dev/null @@ -1,27 +0,0 @@ -// @flow -import test from '../../index.js.flow'; - -class CustomError extends Error { - foo: string; - - constructor() { - super(); - this.foo = 'foo'; - } -} - -test('throws', t => { - const err1: Error = t.throws(() => {}); - // t.is(err1.foo, 'foo'); - const err2: CustomError = t.throws(() => {}); - t.is(err2.foo, 'foo'); - const err3 = t.throws(() => {}); - t.is(err3.foo, 'foo'); -}); - -test('throwsAsync', async t => { - const err1: Error = await t.throwsAsync(Promise.reject()); - // t.is(err1.foo, 'foo'); - const err2 = await t.throwsAsync(Promise.reject()); - t.is(err2.foo, 'foo'); -});