ainzzorl / goodcode

A curated collection of annotated code examples from prominent open-source projects
https://codecatalog.org
Creative Commons Attribution 4.0 International
198 stars 8 forks source link

Jest - Test Sequencing #36

Closed ainzzorl closed 3 years ago

ainzzorl commented 3 years ago

General

Description

Jest is a "delightful JavaScript Testing Framework with a focus on simplicity".

The order in which it runs tests is not arbitrary because "it has a great impact on the user-perceived responsiveness and speed of the test run." First it runs tests that failed in the previous run, then tests that are slow or expected to be slow.

Links

Implementation

Test

What makes it interesting

The code itself is quite simple and not that interesting, but what's instructive is this observation that you can improve user experience by prioritizing tests.

Related work

Sorting tests in JUnit: https://github.com/junit-team/junit4/blob/9ad61c6bf757be8d8968fd5977ab3ae15b0c5aba/src/main/java/org/junit/runner/manipulation/Sorter.java, https://github.com/junit-team/junit4/blob/9ad61c6bf757be8d8968fd5977ab3ae15b0c5aba/src/main/java/org/junit/runner/manipulation/Ordering.java. As far as I can see, it runs them alphabetically.

Other

N/A

ainzzorl commented 3 years ago

Ordering in rspec: https://github.com/rspec/rspec-core/blob/dc898adc3f98d841a43e22cdf62ae2250266c7b6/lib/rspec/core/ordering.rb Supports "Random" and "Last Modified".