<commit_before>/**
 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

// Used as type
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import expect from 'expect';
import {Global} from '@jest/types';

type Process = NodeJS.Process;

export type DoneFn = Global.DoneFn;
export type BlockFn = Global.BlockFn;
export type BlockName = Global.BlockName;
export type BlockMode = void | 'skip' | 'only' | 'todo';
export type TestMode = BlockMode;
export type TestName = Global.TestName;
export type TestFn = Global.TestFn;
export type HookFn = (done?: DoneFn) => Promise<any> | null | undefined;
export type AsyncFn = TestFn | HookFn;
export type SharedHookType = 'afterAll' | 'beforeAll';
export type HookType = SharedHookType | 'afterEach' | 'beforeEach';
export type TestContext = Record<string, any>;
export type Exception = any; // Since in JS anything can be thrown as an error.
export type FormattedError = string; // String representation of error.
export type Hook = {
  asyncError: Exception;
  fn: HookFn;
  type: HookType;
  parent: DescribeBlock;
  timeout: number | undefined | null;
};

export type EventHandler = (event: Event, state: State) => void;

export type Event =
  | {
      name: 'include_test_location_in_result';
    }
  | {
      asyncError: Exception;
      mode: BlockMode;
      name: 'start_describe_definition';
      blockName: BlockName;
    }
  | {
      mode: BlockMode;
      name: 'finish_describe_definition';
      blockName: BlockName;
    }
  | {
      asyncError: Exception;
      name: 'add_hook';
      hookType: HookType;
      fn: HookFn;
      timeout: number | undefined;
    }
  | {
      asyncError: Exception;
      name: 'add_test';
      testName: TestName;
      fn?: TestFn;
      mode?: TestMode;
      timeout: number | undefined;
    }
  | {
      name: 'hook_start';
      hook: Hook;
    }
  | {
      name: 'hook_success';
      describeBlock: DescribeBlock | undefined | null;
      test: TestEntry | undefined | null;
      hook: Hook;
    }
  | {
      name: 'hook_failure';
      error: string | Exception;
      describeBlock: DescribeBlock | undefined | null;
      test: TestEntry | undefined | null;
      hook: Hook;
    }<commit_msg>more precise circus asyncError types (#8150)<commit_after>/**
 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

// Used as type
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import expect from 'expect';
import {Global} from '@jest/types';

type Process = NodeJS.Process;

export type DoneFn = Global.DoneFn;
export type BlockFn = Global.BlockFn;
export type BlockName = Global.BlockName;
export type BlockMode = void | 'skip' | 'only' | 'todo';
export type TestMode = BlockMode;
export type TestName = Global.TestName;
export type TestFn = Global.TestFn;
export type HookFn = (done?: DoneFn) => Promise<any> | null | undefined;
export type AsyncFn = TestFn | HookFn;
export type SharedHookType = 'afterAll' | 'beforeAll';
export type HookType = SharedHookType | 'afterEach' | 'beforeEach';
export type TestContext = Record<string, any>;
export type Exception = any; // Since in JS anything can be thrown as an error.
export type FormattedError = string; // String representation of error.
export type Hook = {
  asyncError: Error;
  fn: HookFn;
  type: HookType;
  parent: DescribeBlock;
  timeout: number | undefined | null;
};

export type EventHandler = (event: Event, state: State) => void;

export type Event =
  | {
      name: 'include_test_location_in_result';
    }
  | {
      asyncError: Error;
      mode: BlockMode;
      name: 'start_describe_definition';
      blockName: BlockName;
    }
  | {
      mode: BlockMode;
      name: 'finish_describe_definition';
      blockName: BlockName;
    }
  | {
      asyncError: Error;
      name: 'add_hook';
      hookType: HookType;
      fn: HookFn;
      timeout: number | undefined;
    }
  | {
      asyncError: Error;
      name: 'add_test';
      testName: TestName;
      fn?: TestFn;
      mode?: TestMode;
      timeout: number | undefined;
    }
  | {
      name: 'hook_start';
      hook: Hook;
    }
  | {
      name: 'hook_success';
      describeBlock: DescribeBlock | undefined | null;
      test: TestEntry | undefined | null;
      hook: Hook;
    }
  | {
      name: 'hook_failure';
      error: string | Exception;
      describeBlock: DescribeBlock | undefined | null;
      test: TestEntry | undefined | null;
      hook: Hook;
    }
{'fraction_non_alphanumeric': 0.10835261939827477, 'fraction_numerical': 0.0008415737428992215, 'mean_word_length': 3.0632478632478635, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1344409', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1413, 'n_words': 461}