
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@zebreus/jest-bench
Advanced tools
Run benchmark with Jest. Write benchmark files along with your test files, and benchmark using any existing test environment you're using. This package builds on top of the excellent benchmark package.
Some environments such as jest-electron are only useable with Jest version less than 27, therefore this package takes its version after Jest version for easy installation:
| Jest version | Jest-Bench version |
|---|---|
| 26.x.x | 26.x.x |
| 27.x.x | 27.x.x |
| 28.x.x | 28.x.x |
For contributors, branch main works with Jest version 28.
Install
npm i -D jest-bench
Create a jest config file just for running benchmarks. You can use names such as jest-bench.config.json.
{
// Jest-bench need its own test environemtn to function
"testEnvironment": "jest-bench/environment",
"testEnvironmentOptions": {
// still Jest-bench environment will run your environment if you specify it here
"testEnvironment": "jest-environment-node",
"testEnvironmentOptions": {
// specify any option for your environment
}
},
// always include "default" reporter along with Jest-bench reporter
// for error reporting
"reporters": ["default", "jest-bench/reporter"],
// will pick up "*.bench.js" files or files in "__benchmarks__" folder.
"testRegex": "(/__benchmarks__/.*|\\.bench)\\.(ts|tsx|js)$",
...
}
Now any files with names that match *.bench.js, or are inside __benchmarks__ folder will be considered benchmark files. More examples:
import { benchmarkSuite } from "jest-bench";
let a;
benchmarkSuite("sample", {
// setup will not run just once, it will run for each loop
setup() {
a = [...Array(10e6).keys()];
},
// same thing with teardown
teardown() {
if (a.length < 10e6) a.unshift(0);
},
["Array.indexOf"]: () => {
a.indexOf(555599);
},
["delete Array[i]"]: () => {
expect(a.length).toEqual(10e6);
delete a[0];
},
["Array.unshift"]: () => {
a.unshift(-1);
},
["Array.push"]: () => {
a.push(1000000);
},
});
To see more examples, check out the test folder. You can now run benchmarks like this:
npx jest --projects jest-bench.config.json
Jest-bench saves benchmark results to benchmarks/result.txt in addition to being printed, so you might want to add this folder to .gitignore.
# .gitignore
benchmarks/result.txt
Create and run a new suite. Each suite creates and is associated with a describe block underneath.
test block. You can also write jest assertions, even though doing so makes little sense as it will affect benchmark results. Special keys include:
teardown are evaled together with the benchmark. So once you declare this, any variable defined outside of setup and teardown becomes invisible to the benchmark. If this and teardown are not defined then benchmarks will still be able to see variables in outer scopes.beforeAll block (and it does call beforeAll underneath). Again you probably don't want to define or initialize variables here if you also include setup or teardown.FAQs
Run benchmark with Jest
We found that @zebreus/jest-bench demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.