Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarn scripts for quality of life in development #5087

Merged
merged 2 commits into from
Mar 28, 2022

Conversation

Iku-turso
Copy link
Contributor

Run and watch targetable unit- or integration-tests.

…ion testing) in development

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
…is able to be specific to a file

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
@Iku-turso Iku-turso requested a review from a team as a code owner March 23, 2022 16:51
@Iku-turso Iku-turso requested review from Nokel81 and DmitriyNoa and removed request for a team March 23, 2022 16:51
@Nokel81 Nokel81 added this to the 5.5.0 milestone Mar 23, 2022
@Nokel81 Nokel81 added the chore label Mar 23, 2022
@@ -28,6 +28,8 @@
"build:mac": "yarn run compile && electron-builder --mac --dir",
"build:win": "yarn run compile && electron-builder --win --dir",
"integration": "jest --runInBand --detectOpenHandles --forceExit integration",
"test:unit": "jest --watch --testPathIgnorePatterns integration",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discovered you need to make sure you have an up-to-date build before running this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is intentional. The script is for development, and for that, it is optimized for quick start-up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, bit messy if it's already running when you checkout a new branch

@@ -28,6 +28,8 @@
"build:mac": "yarn run compile && electron-builder --mac --dir",
"build:win": "yarn run compile && electron-builder --win --dir",
"integration": "jest --runInBand --detectOpenHandles --forceExit integration",
"test:unit": "jest --watch --testPathIgnorePatterns integration",
"test:integration": "func() { jest ${1:-xyz} --watch --runInBand --detectOpenHandles --forceExit --modulePaths=[\"<rootDir>/integration/\"]; }; func",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What file changes will cause tests to rerun? I edited/saved some files but no tests were run ("No tests found, exiting with code 0").

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For unit tests, watch triggers after a change in most production or test code (and also some configuration files). The initial behavior of jest --watch is to use git to find uncommitted production and test-code, and run all tests directly or indirectly affected by those changes.

In your case:

  1. The changed files need to be related to a test for anything to happen.
  2. Our current unrelated configuration expects *.test-files to contain at least one test in order to not be perceived as failure. This explains "No tests found, exiting with code 0".

Deviating from this, for integration tests the watch triggers only for changes in test code, as the tests happen over already built application. Still, this makes tweaking the slow integration tests a bit more friendly :)

FYI: In watch mode, you can also use w to see additional controls. Eg. p or t will make you able to specify explicitly which tests to run, a will make you run all tests despite git, and f will make you re-run only failing tests. Cool stuff, right? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure I edited an integration test file (edited some string, maybe the test name). I'll try again

Copy link
Contributor

@jim-docker jim-docker Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test to integration/__tests__/cluster-pages.tests.ts and saved. No tests found. Pressing o runs the tests. Is this how to use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a sesh? Or all this should be documented somewhere within jest. Hmm.

@Nokel81 Nokel81 merged commit 5e429d2 into master Mar 28, 2022
@Nokel81 Nokel81 deleted the yarn-scripts-for-quality-of-life-in-development branch March 28, 2022 13:09
@Nokel81 Nokel81 mentioned this pull request May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants