-
Notifications
You must be signed in to change notification settings - Fork 10
/
primitives.ts
38 lines (31 loc) · 1.92 KB
/
primitives.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Copyright (c) 2019, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { dispatch } from './state';
import { HOOKS, RUN_BENCHMARK, MODES } from './constants';
const _dispatchDescribe = (nodeName: string, blockFn: Function, mode?: string) => {
dispatch({ nodeName, mode, nodeType: 'start_describe_definition' });
blockFn();
dispatch({ nodeName, nodeType: 'finish_describe_definition' });
};
const describe = (blockName: string, blockFn: Function) => _dispatchDescribe(blockName, blockFn);
describe.only = (blockName: string, blockFn: Function) => _dispatchDescribe(blockName, blockFn, MODES.ONLY);
describe.skip = (blockName: string, blockFn: Function) => _dispatchDescribe(blockName, blockFn, MODES.SKIP);
const _dispatchBenchmark = (nodeName: any, blockFn: Function, mode?: string) => {
dispatch({ nodeName, mode, nodeType: 'start_benchmark_definition' });
blockFn();
dispatch({ nodeName, nodeType: 'finish_benchmark_definition' });
};
const benchmark = (benchmarkName: string, fn: Function) => _dispatchBenchmark(benchmarkName, fn);
benchmark.only = (benchmarkName: string, fn: Function) => _dispatchBenchmark(benchmarkName, fn, MODES.ONLY);
benchmark.skip = (benchmarkName: string, fn: Function) => _dispatchBenchmark(benchmarkName, fn, MODES.SKIP);
const _addHook = (fn: Function, hookType: string) => dispatch({ nodeName: 'hook', fn, hookType, nodeType: 'add_hook' });
const beforeAll = (fn: Function) => _addHook(fn, HOOKS.BEFORE_ALL);
const before = (fn: Function) => _addHook(fn, HOOKS.BEFORE);
const afterAll = (fn: Function) => _addHook(fn, HOOKS.AFTER_ALL);
const after = (fn: Function) => _addHook(fn, HOOKS.AFTER);
const run = (fn: Function) => dispatch({ nodeName: 'run', fn, nodeType: RUN_BENCHMARK });
export { describe, benchmark, beforeAll, before, afterAll, after, run };