/
runtime.bench.js
109 lines (84 loc) · 2.98 KB
/
runtime.bench.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict';
const { expect } = require('chai');
const { Linter } = require('eslint');
const { times, toPairs, fromPairs } = require('rambda');
const {
runBenchmark,
cpuSpeed
} = require('./measure');
const mochaPlugin = require('../');
const allRules = mochaPlugin.configs.all.rules;
function lintManyFilesWithAllRecommendedRules({ numberOfFiles }) {
const linter = new Linter();
linter.defineRules(mochaPlugin.rules);
const config = {
rules: fromPairs(
toPairs(allRules).map(([ ruleName, ruleSettings ]) => {
const [ , ruleNameWithoutPrefix ] = ruleName.split('/');
return [ ruleNameWithoutPrefix, ruleSettings ];
})
),
parserOptions: {
ecmaVersion: 2018
}
};
times((index) => {
const codeToLint = `
'use strict';
const assert = require('assert');
const sinon = require('sinon');
const sut = require('./sut');
describe('SUT ${index}', function () {
let fooStub;
before(() => {
fooStub = sinon.stub(sut, 'foo');
});
after(() => {
fooStub.restore();
});
beforeEach(function (done) {
done();
});
afterEach(() => {
fooStub.reset();
});
it('should work', async function () {
const bar = {};
await sut(bar);
assert(fooStub.callCount === 42);
});
describe('nested suite', async () => {
beforeEach(async function () {
await sleep(200);
});
xit('doesn’t work yet', function () {
sut();
});
});
context('more context', function () {
it.only('only here it works', () => {
sut();
assert(true);
});
});
});
`;
linter.verify(codeToLint, config);
}, numberOfFiles);
}
describe('runtime', () => {
it('should not take longer as the defined budget to lint many files with the recommended config', () => {
const budget = 3750000 / cpuSpeed;
const { medianDuration } = runBenchmark(() => {
lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 });
}, 50);
expect(medianDuration).to.be.below(budget);
});
it('should not consume more memory as the defined budget to lint many files with the recommended config', () => {
const budget = 2750000;
const { medianMemory } = runBenchmark(() => {
lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 });
}, 50);
expect(medianMemory).to.be.below(budget);
});
});