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

fix(vitest): split out tests #870

Merged
merged 21 commits into from
Sep 5, 2023
Merged

Conversation

kanadgupta
Copy link
Member

@kanadgupta kanadgupta commented Aug 23, 2023

🧰 Changes

This PR is branched off of #857 and splits out our test bed into two parts: single-threaded and multi-threaded. The tests that require different directory changes (i.e. they use process.chdir() have been moved into the former, while the latter contains the vast majority of all tests.

For the single-threaded tests, MSW has been introduced because nock wasn't working properly when attempting to parse and validate certain request bodies. The goal is to eventually introduce MSW across the entire repository, but that's not a priority at the moment.

🧬 QA & Testing

Do tests pass?

@kanadgupta kanadgupta changed the base branch from next to feat/vitest August 23, 2023 20:54
.github/workflows/ci.yml Outdated Show resolved Hide resolved
__tests__/helpers/get-gha-setup.ts Outdated Show resolved Hide resolved
__tests__/single-threaded/openapi/index.test.ts Outdated Show resolved Hide resolved
@kanadgupta kanadgupta changed the title Feat/vitest split tests fix(vitest): split out tests Sep 5, 2023
@esbuild/android-arm wasn't showing up in here, i think it got accidentally removed which is causing node 14 tests to break
@kanadgupta kanadgupta marked this pull request as ready for review September 5, 2023 21:57
@kanadgupta kanadgupta merged commit ed480ed into feat/vitest Sep 5, 2023
10 checks passed
@kanadgupta kanadgupta deleted the feat/vitest-split-tests branch September 5, 2023 22:01
erunion added a commit that referenced this pull request Sep 7, 2023
* feat(test): moving unit tests over to vitest

* fix: prettier issues

* ci: stop testing node 14

* fix: schema updater for prettier 3

* fix: install missing vitest coverage dep

* chore: better link

* ci: let other node versions run if one fails

* ci: try skipping some tests

* chore(deps): bump eslint config

* test: don't return in before* hooks

if you return a function within before* hooks, they'll run on teardown. so these functions are currently doing the opposite of what we're intending 😮‍💨

see: https://vitest.dev/api/#beforeall

* test: more before* hook fixes

* test: try using stubEnv in a few places

* chore: typo

* chore: rebuild lockfile using npm i

* chore: wait this happened after i ran "npm i" again?

* Revert "Merge branch 'next' into feat/vitest"

This reverts commit 22f7904, reversing
changes made to 3298545.

... weird. so i tried merging from next and reinstalling using `npm i`, which removed these packages and will cause node 14 tests to fail.... i hate it here

* fix(vitest): split out tests (#870)

* test: try splitting out tests

* ci: knip fix

* ci: oops

* chore: remove unused snapshots

* refactor: try using MSW instead of nock in single-threaded tests

* chore: temporarily don't worry about coverage 🤐

* chore: backfill headers-polyfill

* ci: re-enable tests on node 14

* test: add JSON error body

* ci: try matrix for threads

* ci: oops

* chore: copy edits

* chore: run build before tests

* fix(ci): split out ci and test steps

* chore: fix lockfile

* Revert "fix(ci): split out ci and test steps"

This reverts commit 112ec66.

* chore: clean out some comment junk

* chore: try fixing lockfile (again)

@esbuild/android-arm wasn't showing up in here, i think it got accidentally removed which is causing node 14 tests to break

* feat: better header checking

* fix: don't nest timers

* chore: remove unnecessary globals file

* chore: bumping eslint-config

---------

Co-authored-by: Kanad Gupta <git@kanad.dev>
Co-authored-by: Kanad Gupta <8854718+kanadgupta@users.noreply.github.com>
kanadgupta pushed a commit that referenced this pull request Sep 7, 2023
# [8.7.0-next.1](v8.6.6...v8.7.0-next.1) (2023-09-07)

### Features

* **test:** moving unit tests over to vitest ([#857](#857)) ([36d561b](36d561b)), closes [#870](#870)

[skip ci]
@kanadgupta kanadgupta mentioned this pull request May 1, 2024
kanadgupta added a commit that referenced this pull request May 1, 2024
## 🧰 Changes

> [!IMPORTANT]
> **this continues to be a vitest supremacy account 😤**

In this repo, we have tests that use `process.chdir()`, so we maintain a
separate Vitest config for running those via a
[`forks`](https://vitest.dev/config/#forks) pool vs. the standard
[`threads`](https://vitest.dev/config/#threads) pool — see
#870 for more background on this.

We've used two separate npm scripts (i.e., `npm run test:multi && npm
run test:single`) to run our tests sequentially. I discovered this
morning that [Vitest's workspaces
feature](https://vitest.dev/guide/workspace) isn't just for monorepos —
it's actually the recommended way to maintain multiple test
configurations no matter the context.

In this PR, I consolidated our two test configs into a single workspace
config. We get a few nice benefits by leveraging workspaces:
- No longer needing to manually pass in the correct config file when
running certain test files (e.g., `npx vitest --config
vitest.single-threaded.config.ts [file]`). In other words, `npx vitest
[file]` ✨ just works ✨, which should make it a lot easier for new
contributors to run tests
- Much cleaner test output — we now can see coverage across all files,
rather than two separate coverage reports[^1]
- Easier to share options between the two configs
- A single config file to rule them all
- Tests seem to be faster (but hard to say)

## 🧬 QA & Testing

Do all the tests run? And do they still run and pass properly? Here's
the latest test run in `next` for comparison:
https://github.com/readmeio/rdme/actions/runs/8910638856

[^1]: Small downside to this — [workspaces don't allow you to configure
coverage options](https://vitest.dev/guide/workspace#coverage). Not a
huge deal since our coverage is great in this repo and we can stick to
the defaults and it still addresses our needs.
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.

2 participants