-
Notifications
You must be signed in to change notification settings - Fork 0
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
Mrc 6022 - vitest server pt 2 #235
base: mrc-6021
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## mrc-6021 #235 +/- ##
============================================
- Coverage 99.78% 99.61% -0.17%
============================================
Files 159 183 +24
Lines 4107 4462 +355
Branches 936 987 +51
============================================
+ Hits 4098 4445 +347
- Misses 8 15 +7
- Partials 1 2 +1 ☔ View full report in Codecov by Sentry. |
@@ -50,13 +50,13 @@ describe("apiService", () => { | |||
headers: AxiosRequestHeaders, | |||
transformResponse: AxiosResponseTransformer | |||
) => { | |||
expect(headers).toStrictEqual({ | |||
expect(headers.toJSON()).toEqual({ |
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.
axios code changed as we updated the package, so just have to explicitly convert to json before checking
const { mockJsonResponseError } = vi.hoisted(() => ({ mockJsonResponseError: vi.fn() })); | ||
vi.mock("../src/jsonResponse", () => { return { jsonResponseError: mockJsonResponseError }; }); |
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.
mockJsonResponseError
has to be hoisted as it is used in the vi.mock
and in the tests
expect(errorCallback).not.toHaveBeenCalled(); | ||
done(); | ||
}, 200); | ||
await new Promise(res => setTimeout(res, 200)); |
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.
instead of setTimeout and using done
callback (which is now completely deprecated) we just await 200ms before moving on
import bodyParser from "body-parser"; | ||
|
||
describe("odin routes", () => { | ||
const express = require("express"); | ||
const bodyParser = require("body-parser"); | ||
const { mockRouter } = vi.hoisted(() => ({ | ||
mockRouter: { | ||
get: vi.fn(), | ||
post: vi.fn() | ||
} | ||
})); | ||
|
||
const mockRouter = { | ||
get: jest.fn(), | ||
post: jest.fn() | ||
}; | ||
const realRouter = express.Router; | ||
vi.mock("express", () => ({ | ||
Router: () => mockRouter | ||
})); | ||
|
||
const spyText = jest.spyOn(bodyParser, "text"); | ||
|
||
beforeAll(() => { | ||
express.Router = () => mockRouter; | ||
describe("odin routes", async () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks() |
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 was weird, we were importing and then reassigning an imported thing as something else and then resetting it with the real router? this is just a roundabout of just mocking the package so thats what i changed this to, now im just mocking the router
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.
have done this same thing in a couple other places below
@@ -30,7 +30,7 @@ describe("registerRoutes", () => { | |||
} as any; | |||
|
|||
it("registers all expected routes", () => { | |||
const router = registerRoutes(mockApp); | |||
const router = registerRoutes(mockApp) as unknown as typeof mockRouter; |
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.
forcing type because we know it will return the mockRouter
in this test so just helping typescript along
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
This finishes the tests, points of interest have been highlighted by comments, the only other thing ive done is update wodin versions, we were on versions 0.1.0 and 0.3.0 for frontend and backend respectively (in main), after this upgrade i just went up major versions to 1.0.0 for both, seems alright to me after this big upgrade!
also
genversion
is a package we use to generate version thats in the package.json into theversion.ts
file, not sure why we need a package for this if im being honest but i just put it in for now cos its a very slim package