Passed
Push — master ( 86ced5...e9c0b0 )
by Dmytro
01:49
created

tests/helpers/benchmark/benchmarks-browser.test.js   A

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 46
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 30
mnd 0
bc 0
fnc 4
dl 0
loc 46
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
1
import path from 'path';
2
import { assert } from 'chai';
3
import { load, sleep, testsRootFolder } from '../../Test';
4
5
const benchmarkPath = 'benchmark.js';
6
const polyfillPath = path.join(testsRootFolder, 'polyfills/performance.polyfill.js');
7
const hrtime = process.hrtime;
8
const performance = global.performance;
9
10
let getBenchmark;
11
12
let  startBenchmark;
13
14
suite('Performance benchmarks #browser');
15
16
before(function () {
17
    process.hrtime = 0;
18
    load(polyfillPath);
19
    const fallback = load(benchmarkPath, true);
20
21
    getBenchmark = fallback.getBenchmark;
22
    startBenchmark = fallback.startBenchmark;
23
});
24
25
test('Positive: min measurable time', function () {
26
    const time = startBenchmark();
27
    const benchmark = getBenchmark(time);
28
29
    assert.isString(benchmark);
30
    assert.isNumber(+benchmark);
31
});
32
33
test('Positive: measure time', async function () {
34
    const time = startBenchmark();
35
36
    await sleep(20);
37
    const benchmark = getBenchmark(time);
38
39
    assert.isString(benchmark);
40
    assert.isAtLeast(+benchmark, 19);
41
});
42
43
after(async function () {
44
    global.performance = performance;
45
    process.hrtime = hrtime;
46
});
47