import { World } from 'cucumber'; import { EventEmitter } from 'events'; import { JestEnvironment } from '@jest/environment'; import { SerializableError, TestResult } from '@jest/test-result'; import { Config } from '@jest/types'; import SnapshotState from 'jest-snapshot/build/State'; import HasteMap, { FS as HasteFS, ModuleMap } from 'jest-haste-map'; import { Jasmine } from 'jest-jasmine2/build/types'; import JsApiReporter from 'jest-jasmine2/build/jasmine/JsApiReporter'; import HasteResolver from 'jest-resolve'; import Worker from 'jest-worker'; import { Plugin } from 'pretty-format'; import { worker } from './testWorker'; export type JestSetupGlobals = { default: (config: { config: Config.ProjectConfig; globalConfig: Config.GlobalConfig; localRequire: (moduleName: string) => Plugin; testPath: Config.Path; }) => SnapshotState } export type SerializableResolver = { config: Config.ProjectConfig; serializableModuleMap: HasteMap.SerializableModuleMap; }; export type ErrorWithCode = Error & { code?: string }; export type Test = { context: Context; duration?: number; path: Config.Path; tmpPath?: Config.Path; }; export type Context = { config: Config.ProjectConfig; hasteFS: HasteFS; moduleMap: ModuleMap; resolver: HasteResolver; }; export type OnTestStart = (test: Test) => Promise; export type OnTestFailure = (test: Test, serializableError: SerializableError) => Promise; export type OnTestSuccess = (test: Test, testResult: TestResult) => Promise; export type TestRunnerOptions = { serial: boolean; }; // make sure all props here are present in the type below it as well export type TestRunnerContext = { changedFiles?: Set; sourcesRelatedToTestsInChangedFiles?: Set; }; // export type TestRunnerContext = { // changedFiles?: Set; // }; export type TestRunnerSerializedContext = { changedFiles?: Array; sourcesRelatedToTestsInChangedFiles?: Set; }; export type WatcherState = { interrupted: boolean; }; export interface TestWatcher extends EventEmitter { state: WatcherState; new({isWatchMode}: { isWatchMode: boolean }): TestWatcher; setState(state: WatcherState): void; isInterrupted(): boolean; isWatchMode(): boolean; } export type WorkerData = { config: Config.ProjectConfig; globalConfig: Config.GlobalConfig; path: Config.Path; test: Test context?: TestRunnerSerializedContext; }; export interface WorkerInterface extends Worker { worker: typeof worker; } // export type RunTestInternalResult = { // leakDetector: LeakDetector | null; // result: TestResult; // }; // type Background = { // description?: (string | null); // keyword?: (string | null); // location?: (Location | null); // name?: (string | null); // steps?: (IStep[] | null); // }; // type DateTable = { // location?: (Location | null); // rows?: (TableRow[] | null); // }; // // type DocString = { // content?: (string | null); // delimiter?: (string | null); // location?: (Location | null); // mediaType?: (string | null); // }; // type Examples = { // description?: (string | null); // keyword?: (string | null); // location?: (Location | null); // name?: (string | null); // tableBody?: (TableRow[] | null); // tableHeader?: (TableRow | null); // tags?: (Tag[] | null); // }; // type FeatureChild = { // background?: (Background | null); // rule?: (Rule | null); // scenario?: (Scenario | null); // }; type Location = { column?: (number | null); line?: (number | null); }; // type Rule = { // children?: (RuleChild[] | null); // description?: (string | null); // keyword?: (string | null); // location?: (Location | null); // name?: (string | null); // }; // // type RuleChild = { // background?: (Background | null); // scenario?: (Scenario | null); // }; // type Scenario = { // description?: (string | null); // id?: (string | null); // examples?: (Examples[] | null); // keyword?: (string | null); // location?: (Location | null); // name?: (string | null); // steps?: (IStep[] | null); // tags?: (Tag[] | null); // }; // type IStep = { // dataTable?: (DateTable | null); // docString?: (DocString | null); // id?: (string | null); // keyword?: (string | null); // location?: (Location | null); // text?: (string | null); // }; // // type TableCell = { // location?: (Location | null); // value?: (string | null); // }; // type TableRow = { // cells?: (TableCell[] | null); // id?: (string | null); // location?: (Location | null); // }; // type Tag = { // id?: (string | null); // location?: (Location | null); // name?: (string | null); // }; type Step = { dataTable?: { location: Location; rows: { location: Location; cells: { location: Location; value: string; }[]; id: string; }[]; }; id: string; keyword: string; location: Location; text: string; }; // export type Hook = { // code: (this: World, ...args: any[]) => Promise; // } export type JestSuite = { tags: any[]; steps: Step[]; examples: any[]; id: string; location: Location; keyword: string; name: string; }; export type JestGherkinTest = { context: Context; duration?: number; path: Config.Path; tmpPath?: Config.Path; suites: JestSuite[]; } // type JestGherkinStep = IStep & { // description: string; // code(this: World): Promise; // stepArgs?: any[]; // }; // export type JestGherkinSuite = { // document: { // children?: (FeatureChild[] | null); // description?: (string | null); // keyword?: (string | null); // language?: (string | null); // location?: (Location | null); // name?: (string | null); // tags?: (Tag[] | null); // }; // afterEach: Hook[]; // afterAll: Hook[]; // beforeEach: Hook[]; // beforeAll: Hook[]; // suites: (Scenario & { // name?: string; // steps: { // name: string; // given: JestGherkinStep[]; // when: JestGherkinStep[]; // then: JestGherkinStep[]; // }; // })[]; // } export type JasmineFactory = { create: (createOptions: Record) => JestEnvironment & Jasmine; _interface: (jasmine: Jasmine, env: any) => { describe(description: string, specDefinitions: Function): any; xdescribe(description: string, specDefinitions: Function): any; fdescribe(description: string, specDefinitions: Function): any; it(): any; xit(): any; fit(): any; beforeEach(): any; afterEach(): any; beforeAll(): any; CucumberWorld(): World; afterAll(): any; pending(): any; fail(): any; spyOn(obj: Record, methodName: string, accessType?: string | undefined): any; jsApiReporter: JsApiReporter; jasmine: Jasmine; }; }