Skip to content

Commit

Permalink
Extract jest-each type defs to global
Browse files Browse the repository at this point in the history
  • Loading branch information
mattphillips committed Mar 1, 2019
1 parent 2d882fc commit 1bdd67c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
23 changes: 11 additions & 12 deletions packages/jest-each/src/bind.ts
Expand Up @@ -6,29 +6,28 @@
*
*/

import {DoneFn, ItBase} from '@jest/types/build/Global';
import {
DoneFn,
EachTable,
TemplateData,
EachTestFn,
ArrayTable,
} from '@jest/types/build/Global';
import {ErrorWithStack} from 'jest-util';

import convertArrayTable from './table/array';
import convertTemplateTable from './table/template';
import {validateArrayTable, validateTemplateTableHeadings} from './validation';

type EachTestFn = (...args: any[]) => Promise<any> | void | undefined;

export type Col = unknown;
export type Row = Array<Col>;
export type Table = Array<Row>;
export type ArrayTable = Table | Row;
type TemplateTable = TemplateStringsArray;
export type TemplateData = Array<unknown>;
export type EachTable = ArrayTable | TemplateTable;

export type EachTests = Array<{
title: string;
arguments: Array<unknown>;
}>;

export default (cb: ItBase, supportsDone: boolean = true) => (
type TestFn = (done?: DoneFn) => Promise<any> | void | undefined;
type GlobalCallback = (testName: string, fn: TestFn, timeout?: number) => void;

export default (cb: GlobalCallback, supportsDone: boolean = true) => (
table: EachTable,
...taggedTemplateData: TemplateData
) =>
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-each/src/index.ts
Expand Up @@ -6,8 +6,8 @@
*
*/

import {TestFn} from '@jest/types/build/Global';
import bind, {EachTable, TemplateData} from './bind';
import {TestFn, EachTable, TemplateData} from '@jest/types/build/Global';
import bind from './bind';

type Global = NodeJS.Global;

Expand Down
3 changes: 2 additions & 1 deletion packages/jest-each/src/table/array.ts
@@ -1,7 +1,8 @@
import util from 'util';
import pretty from 'pretty-format';

import {ArrayTable, Col, EachTests, Row, Table} from '../bind';
import {ArrayTable, Table, Row, Col} from '@jest/types/build/Global';
import {EachTests} from '../bind';

const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp%]/g;
const PRETTY_PLACEHOLDER = '%p';
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-each/src/table/template.ts
@@ -1,6 +1,7 @@
import pretty from 'pretty-format';
import {isPrimitive} from 'jest-get-type';
import {EachTests, Row, Table} from '../bind';
import {Row, Table} from '@jest/types/build/Global';
import {EachTests} from '../bind';

type Template = {[key: string]: unknown};
type Templates = Array<Template>;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/src/validation.ts
@@ -1,6 +1,6 @@
import chalk from 'chalk';
import pretty from 'pretty-format';
import {TemplateData} from './bind';
import {TemplateData} from '@jest/types/build/Global';

const EXPECTED_COLOR = chalk.green;
const RECEIVED_COLOR = chalk.red;
Expand Down
15 changes: 13 additions & 2 deletions packages/jest-types/src/Global.ts
Expand Up @@ -16,8 +16,19 @@ export type BlockName = string;
// TODO: Get rid of this at some point
type JasmineType = {_DEFAULT_TIMEOUT_INTERVAL?: number; addMatchers: Function};

// TODO Replace with actual type when `jest-each` is ready
type Each = () => void;
export type Col = unknown;
export type Row = Array<Col>;
export type Table = Array<Row>;
export type ArrayTable = Table | Row;
export type TemplateTable = TemplateStringsArray;
export type TemplateData = Array<unknown>;
export type EachTable = ArrayTable | TemplateTable;
export type EachTestFn = (...args: any[]) => Promise<any> | void | undefined;

type Each = (
table: EachTable,
...taggedTemplateData: Array<unknown>
) => (title: string, test: EachTestFn, timeout?: number) => void;

export interface ItBase {
(testName: TestName, fn: TestFn, timeout?: number): void;
Expand Down

0 comments on commit 1bdd67c

Please sign in to comment.