jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.22k stars 6.47k forks source link

[Feature]: Expand perfStats to time test loading vs test execution #15341

Open glenjamin opened 2 weeks ago

glenjamin commented 2 weeks ago

🚀 Feature Proposal

In #14622 perfStats was expanded to provide breakdowns of parts of the test init process

However, it doesn't include a timer for the interval between calling import/require on the test file, and starting the actual test execution.

Motivation

In my experience this timing is a common cause of slow test suite execution, I'm currently exploring ways of collecting timing information about this phase, to help people target improvements in module loading for tests.

Example

No response

Pitch

This needs to live in core, as only jest-circus have the relevant context to be able to perform this timing.

I'm happy to submit a PR for this if I get the nod that the proposal makes sense

glenjamin commented 2 weeks ago

I've been able to get something close enough to the correct numbers by reading the code closely and assigning slightly different meanings to the timestamps provided:

const {
  loadTestEnvironmentStart: testInitStart,
  setupAfterEnvEnd: testImportStart,
  end: testEnd,
} = testResult.perfStats;
const firstTestStart = testResult.testResults[0].startAt;