-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmarks for runtime with many files
- Loading branch information
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
'use strict'; | ||
|
||
const { expect } = require('chai'); | ||
const { Linter } = require('eslint'); | ||
const times = require('ramda/src/times'); | ||
const { runBenchmark, cpuSpeed } = require('./measure'); | ||
const mochaPlugin = require('../'); | ||
|
||
const recommendedRules = mochaPlugin.configs.recommended.rules; | ||
|
||
function lintManyFilesWithAllRecommendedRules({ numberOfFiles }) { | ||
const linter = new Linter(); | ||
|
||
linter.defineRules(mochaPlugin.rules); | ||
|
||
const config = { | ||
rules: Object.fromEntries(Object.entries(recommendedRules).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 = 52000000 / cpuSpeed; | ||
|
||
const { medianDuration } = runBenchmark(() => { | ||
lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 }); | ||
}, 5); | ||
|
||
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 = 2400000; | ||
|
||
const { medianMemory } = runBenchmark(() => { | ||
lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 }); | ||
}, 5); | ||
|
||
expect(medianMemory).to.be.below(budget); | ||
}); | ||
}); |