Code Duplication    Length = 45-46 lines in 2 locations

tests/helpers/benchmark/benchmarks-browser.test.js 1 location

@@ 1-46 (lines=46) @@
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, 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

tests/helpers/benchmark/benchmarks-fallback.test.js 1 location

@@ 2-46 (lines=45) @@
1
// import path from 'path';
2
import { assert } from 'chai';
3
import { load, sleep } from '../../Test';
4
5
const benchmarkPath = 'benchmark.js';
6
const hrtime = process.hrtime;
7
const performance = global.performance;
8
9
let getBenchmark;
10
11
let  startBenchmark;
12
13
suite('Fallback benchmarks');
14
15
before(function () {
16
    process.hrtime = 0;
17
    global.performance = null;
18
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
    process.hrtime = hrtime;
45
    global.performance = performance;
46
});
47