jest-expect-message
jest-expect-message copied to clipboard
Adding jest-expect-message to a project tanks expect performance
Bug
-
package
version: 1.0.2 -
node
version: v12.1.0 -
npm
(oryarn
) version: npm 6.14.3 -
jest
version: 25.1.0 - Environment: 2015 MacBook Pro running OSX 10.15.4
Relevant code or config
// src/jest_expect_profile.test.js
const { performance } = require('perf_hooks');
const RUN_SIZE = 2000;
it('expect takes longer than expected', () => {
const t0 = performance.now();
for (let i = 0; i < RUN_SIZE; i += 1) {
expect(i).toBe(i);
}
console.log(`Total time: ${performance.now() - t0} ms`);
});
it('wraping in a conditional is much quicker', () => {
const t0 = performance.now();
for (let i = 0; i < RUN_SIZE; i += 1) {
if (i === RUN_SIZE) {
expect(i).toBe(i);
}
}
console.log(`Total time: ${performance.now() - t0} ms`);
});
/* package.json */
{
"name": "jest-performance",
"version": "1.0.0",
"description": "",
"main": "jest_expect_profile.test.js",
"scripts": {
"test": "jest"
},
"author": "",
"license": "ISC",
"devDependencies": {
"jest": "^25.4.0",
"jest-expect-message": "^1.0.2"
},
"jest": {
"setupFilesAfterEnv": [
"jest-expect-message"
],
"testEnvironment": "node"
}
}
What you did:
Run expect in a loop, wrapped in some performance profiling, with and without the jest-expect-message
library enabled.
What happened (please provide anything you think will help):
Test takes much, much longer (40-50x) with the library enabled!
Without jest-expect-message
enabled
PASS src/jest_expect_profile.test.js
✓ expect takes longer than expected (150ms)
✓ wraping in a conditional is much quicker (2ms)
console.log
Total time: 132.83245699852705 ms
at Object.<anonymous> (src/jest_expect_profile.test.js:10:11)
console.log
Total time: 0.04529799520969391 ms
at Object.<anonymous> (src/jest_expect_profile.test.js:20:11)
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.064s, estimated 7s
Ran all test suites related to changed files.
With jest-expect-message
enabled
PASS src/jest_expect_profile.test.js (6.022s)
✓ expect takes longer than expected (5535ms)
✓ wraping in a conditional is much quicker (1ms)
console.log
Total time: 5523.3286210000515 ms
at Object.<anonymous> (src/jest_expect_profile.test.js:10:11)
console.log
Total time: 0.04469999670982361 ms
at Object.<anonymous> (src/jest_expect_profile.test.js:20:11)
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 6.08s
Ran all test suites related to changed files.
Reproduction repository (if possible):
https://github.com/droberts-ada/jest-performance