question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: only run dependent tests on save

See original GitHub issue

🚀 Feature Proposal

Stealing this from mocha-webpack/mochapack’s killer feature in --watch mode:

Unlike mocha, mochapack analyzes your dependency graph and run only those test files that were affected by this file change.

You’ll get continuous feedback whenever you make changes as all tests that are related in any way to this change will be tested again. Isn’t that awesome?

I am proposing the same feature be added to jest under a flag like --onlyOnSave.

Motivation

Running a whole test suite is slow, but immediate feedback on a change is great. Using it.only() and describe.only() gets you closer to speedy test results, but you still need to think about what tests are affected by a change in your source code. This feature reduces all that extra thought so the only thing you need to do is write changes in source and watch the related tests just run.

Example

npx jest --onlyOnSave tests/

in your editor, save a file and watch jest only run the test cases related to said file.

Outline

the implementation would come down to a few things (apologies I dont know the internal workings of jest yet):

on file change:

  • build a dependency graph for changed file (find-imports can likely help with this)
  • find which dependent files are test files
  • execute those test files only

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
andykaiscommented, Apr 10, 2019

this may be a misunderstanding, I may have not been clear enough in my description. The feature I am describing would change which test files are ran per each file write. E.g., say you have this project structure:

// a.js 
// b.js
// a.test.js
import A from './a'
it('test a', () => {
  ...
})
// b.test.js
import B from './b'
it('test b', () => {
  ...
})

If I boot up mochapack --watch, then in my editor I save a.js, only test file a.test.js will run, if I save file b.js, only test file b.test.js will run.

If you want to see it yourself, then run a simple app with mochapack. Ill do my best to create an example repo later tonight, but its just the standard behavior for mochapack --watch.

0reactions
github-actions[bot]commented, May 2, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Writing Tests That Depend On Other Tests - Gleb Bahmutov
Cypress Best Practices strongly advocates for keeping the tests independent of each other. Tests should be independent of each other.
Read more >
Dependent tests between two TestCase classes in PHPUnit
So I want to test B only if the tests for A (or one of it's tests) run without a failure. How can...
Read more >
What are TestNG Dependent Tests and How to ... - Tools QA
TestNG lets you create dependencies between groups in the XML file. So, if you have multiple groups in the TestNG file, you can...
Read more >
Run jest for unit tests of modified files only | by SunCommander
In this article, you will learn how to run Jest for modified files only in a Pull Request. This can be done using...
Read more >
Organizing Test Suite - WebdriverIO
To prevent this, you should run your tests in parallel. WebdriverIO already tests each spec (or feature file in Cucumber) in parallel within...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found