1 | View Code Duplication | import path from 'path'; |
|
0 ignored issues
–
show
Duplication
introduced
by
![]() |
|||
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, true); |
||
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 |