Skip to content

test: run unit tests before integration tests#1832

Merged
alxndrsn merged 5 commits into
getodk:masterfrom
alxndrsn:mocha-opt-in
May 23, 2026
Merged

test: run unit tests before integration tests#1832
alxndrsn merged 5 commits into
getodk:masterfrom
alxndrsn:mocha-opt-in

Conversation

@alxndrsn
Copy link
Copy Markdown
Contributor

@alxndrsn alxndrsn commented May 19, 2026

This change:

This change will allow a failed unit test to fail the full test pipeline significantly faster than previously.

What has been done to verify that this works as intended?

  • run locally
  • run in CI

Why is this the best possible solution? Were any other approaches considered?

  • faster failures
  • simpler understanding
  • less chance of surprising things happening when new files are introduced in test directory.

An alternative approach (or additional change) could be to "shift left" more by:

test: lint test-unit test-integration-fast test-integration-slow

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

No effect - just tests.

Does this change require updates to the API documentation? If so, please update docs/api.yaml as part of this PR.

No.

Before submitting this PR, please make sure you have:

  • run make test and confirmed all checks still pass, or witnessed Github completing all checks with success
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

This change:

* executes unit tests before integration tests, ensuring faster failure and cleaner reporting
* implements mocha global setup/teardown more idiomatically
* protects against mistakes like that fixed in getodk#1828
@alxndrsn alxndrsn marked this pull request as ready for review May 19, 2026 06:13
@alxndrsn alxndrsn requested review from ktuite and matthew-white May 19, 2026 06:13
Comment thread .mocharc.js Outdated
Comment thread Makefile Outdated
@alxndrsn alxndrsn requested a review from matthew-white May 21, 2026 11:03
Comment thread Makefile

.PHONY: test-fast
test-fast: node_version
NODE_CONFIG_ENV=test BCRYPT=insecure npx mocha --recursive --fgrep @slow --invert
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm noticing that test-fast set NODE_CONFIG_ENV=test, while test didn't. It probably doesn't really matter for this PR though. This PR is taking a different approach with test and test-fast, relating them to test-unit and test-integration. Even test-unit and test-integration do different things from one another when it comes to NODE_CONFIG_ENV.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Due to line 3 (

NODE_CONFIG_ENV ?= test
), NODE_CONFIG_ENV is pretty much always test anyway.

I'm not really sure of the purpose of this, as there is no config/test.json. Perhaps @sadiqkhoja can give more context.

Given that NODE_CONFIG_ENV defaults to test, and there is no config/test.json, I don't think this change is going to have an obvious effect.

Copy link
Copy Markdown
Member

@ktuite ktuite left a comment

Choose a reason for hiding this comment

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

i like the approach of recursively calling make-test and make-integration in order to preserve make test-fast, which i'll be using more!

@alxndrsn alxndrsn merged commit adea902 into getodk:master May 23, 2026
6 checks passed
@alxndrsn alxndrsn deleted the mocha-opt-in branch May 23, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants