Skip to content

Chore: introduce Fishery as object factory and yarn dev:msw #1023

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

Merged
merged 65 commits into from
Jan 31, 2025

Conversation

VikaCep
Copy link
Contributor

@VikaCep VikaCep commented Dec 19, 2024

Closes: #850

This PR introduces the following changes:

Fishery: Simplifies mocking data in tests, removing the need for hard-coded objects. It works alongside Faker to automatically generate dynamic test data for more flexible testing scenarios.

It defines factories for:

  • All different check types
  • Probes
  • Check alerts

These factories are used to create fixtures in src/test/fixtures/probes.ts, src/test/fixtures/checks.ts, and src/test/fixtures/checkAlerts.ts.

Mocked API responses: Adds the ability to start the app with mocked API responses. To use this, run yarn dev:msw. This runs a service worker that uses the same handlers as in test .

Example of running the app using MSW mocked responses:

Screen.Recording.2024-12-20.at.15.44.15.mov

@VikaCep VikaCep self-assigned this Dec 19, 2024
@VikaCep VikaCep marked this pull request as ready for review December 19, 2024 16:30
@VikaCep VikaCep requested a review from a team as a code owner December 19, 2024 16:30
@VikaCep VikaCep requested review from ckbedwell and removed request for a team December 19, 2024 16:30
@VikaCep VikaCep changed the title Chore: introduce Fishery as object factory Chore: introduce Fishery as object factory and yarn dev:msw Dec 20, 2024
VikaCep added 21 commits January 7, 2025 11:54
- adjust schema validation to make it optional
- add test handlers for new alerts requests
- Also, invalidate cache for fetching fresh check alerts
- Instead of grouping by alert type, I'm displaying all alerts as separate ones
- Grouping by type didn't allow to specify threshold for different percentiles
- since the alerts API is no longer in dev, I'm adding the mocks back to be able to test it
- This should be improved by #850
- Also, adding loading and error states
- Add specific predefined alerts according to the check type in a single constants file
- Display threshold units
@VikaCep VikaCep requested a review from a team as a code owner January 7, 2025 15:16
Copy link
Contributor

@ckbedwell ckbedwell left a comment

Choose a reason for hiding this comment

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

One thing to change then let's get this in! 🎉

src/module.ts Outdated
Comment on lines 32 to 34
if (process.env.NODE_ENV === 'development' && process.env.REACT_APP_MSW) {
setupWorker(...handlers).start();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just needs a small modification so it gets tree-shaken properly and doesn't affect the production bundle size:

  1. Move line 33 and associated imports to a file like startServerWorker.ts:
import { setupWorker } from 'msw';
import { handlers } from 'test/handlers';

setupWorker(...handlers).start();
  1. change line 33 to: await import(./startServiceWorker);

Then we don't include the additional 850kb overhead our mocks have 😄

Comparing the webpack console output before and after making this change. Before 2.87MiB. After 2.02MiB

@VikaCep VikaCep requested a review from ckbedwell January 23, 2025 14:58
ckbedwell
ckbedwell previously approved these changes Jan 29, 2025
Copy link
Contributor

@ckbedwell ckbedwell left a comment

Choose a reason for hiding this comment

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

LGTM ❤️

Base automatically changed from alerts-per-check to main January 31, 2025 13:41
@VikaCep VikaCep dismissed ckbedwell’s stale review January 31, 2025 13:41

The base branch was changed.

@VikaCep VikaCep merged commit 0253f91 into main Jan 31, 2025
7 checks passed
@VikaCep VikaCep deleted the sm-fixtures-fishery branch January 31, 2025 14:40
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.

Add an object factory to create SM fixtures
2 participants