Total Complexity | 5 |
Complexity/F | 1.25 |
Lines of Code | 42 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | 'use strict' |
||
2 | |||
3 | // eslint-disable-next-line @typescript-eslint/no-var-requires |
||
4 | const bluebirdModule = require('bluebird') |
||
5 | |||
6 | const globalPromise = global.Promise |
||
7 | const globalSetTimeout = global.setTimeout |
||
8 | |||
9 | exports.__esModule = true |
||
10 | |||
11 | exports.mockSetTimeout = expectedPause => { |
||
12 | global.Promise = bluebirdModule.Promise |
||
13 | |||
14 | const mockState = { |
||
15 | expectedPause: expectedPause, |
||
16 | passedTimeout: null, |
||
17 | numTimeoutCalls: 0, |
||
18 | // eslint-disable-next-line @typescript-eslint/no-empty-function |
||
19 | pendingCallback: () => {}, |
||
20 | pendingCallbackArgs: [], |
||
21 | } |
||
22 | |||
23 | global.setTimeout = (callback, ms, ...args) => { |
||
24 | if (ms !== mockState.expectedPause) { |
||
25 | // We use a "magic number" to allow all the other cases work as expected |
||
26 | return globalSetTimeout(callback, ms, ...args) |
||
27 | } |
||
28 | |||
29 | mockState.passedTimeout = ms |
||
30 | mockState.numTimeoutCalls += 1 |
||
31 | mockState.pendingCallback = callback |
||
32 | mockState.pendingCallbackArgs = args |
||
33 | return null |
||
34 | } |
||
35 | |||
36 | return mockState |
||
37 | } |
||
38 | |||
39 | exports.restoreSetTimeout = () => { |
||
40 | global.setTimeout = globalSetTimeout |
||
41 | global.Promise = globalPromise |
||
42 | } |
||
43 |