-
Notifications
You must be signed in to change notification settings - Fork 19
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
Chore: introduce Fishery as object factory and yarn dev:msw #1023
base: alerts-per-check
Are you sure you want to change the base?
Conversation
a75b502
to
0b04626
Compare
- Also, adding loading and error states
- Addresses all check types, probes and alerts
786a5e2
to
a5be00b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ace but there are some things we can tighten up! 🔧
src/test/db.ts
Outdated
probe: Factory.define<Probe>(() => ({ | ||
id: faker.number.int({ min: 1, max: 999999 }), | ||
name: faker.string.uuid(), | ||
public: faker.datatype.boolean(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be opinionated and generate Private probes by default. I was experimenting with the probe definitions and found this was a source of flaky tests because the app behaviour changes dependent on if they are public or private probes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per my comment below on reflecting upon this, I think we should have two factories. One that creates public probes and one that creates private probes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried creating two separate factories—one for PrivateProbes and one for PublicProbes—but since the IDs for public and private probes can’t overlap, we need to manage their creation within a single factory. This requires using a transient parameter, similar to how it’s done with checks. But having two separate factories was complicating things, so I found it more straightforward to just use one factory that creates private probes by default. For fixtures that require a public probe, we can simply set the public: true
property.
- move worker initialization to module.ts - use sequence for Fishery ids - simplify probes and checks mocks creation
There was a problem hiding this 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
if (process.env.NODE_ENV === 'development' && process.env.REACT_APP_MSW) { | ||
setupWorker(...handlers).start(); | ||
} |
There was a problem hiding this comment.
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:
- Move line 33 and associated imports to a file like
startServerWorker.ts
:
import { setupWorker } from 'msw';
import { handlers } from 'test/handlers';
setupWorker(...handlers).start();
- change line 33 to:
await import(
./startServiceWorker);
Then we don't include the additional 850kb overhead our mocks have 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ❤️
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:
These factories are used to create fixtures in
src/test/fixtures/probes.ts
,src/test/fixtures/checks.ts
, andsrc/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