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

mrc-6021 Vitest server pt 1 #234

Merged
merged 2 commits into from
Dec 3, 2024
Merged

mrc-6021 Vitest server pt 1 #234

merged 2 commits into from
Dec 3, 2024

Conversation

M-Kusumgar
Copy link
Collaborator

@M-Kusumgar M-Kusumgar commented Nov 16, 2024

This is the first batch of tests. The general change is jest -> vi the other points of interests are highlighted by comments, CI should still not be passing but the relevant tests should be passing, everything will be passing by the next PR

Copy link

codecov bot commented Nov 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.78%. Comparing base (c55d5a8) to head (c42b13b).
Report is 7 commits behind head on mrc-6018.

Additional details and impacted files
@@            Coverage Diff            @@
##           mrc-6018     #234   +/-   ##
=========================================
  Coverage     99.78%   99.78%           
=========================================
  Files           159      159           
  Lines          4107     4107           
  Branches        936      938    +2     
=========================================
  Hits           4098     4098           
  Misses            8        8           
  Partials          1        1           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -27,5 +27,5 @@
<script type="module" src="/wodin.js"></script>
<link rel="stylesheet" href="/wodin.css"/>
{{/hotReload}}
<script async src="{{mathjaxSrc}}"></script>
<script async src="{{& mathjaxSrc}}"></script>
Copy link
Collaborator Author

@M-Kusumgar M-Kusumgar Nov 16, 2024

Choose a reason for hiding this comment

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

forgot to escape this special character in mathjaxSrc too (its a URL)

Comment on lines +6 to +16
const { mockSessionStore, mockGetSessionStore } = vi.hoisted(() => {
const mockSessionStore = {
getSessionIdFromFriendlyId: vi.fn().mockImplementation(() => { return sessionIdFromFriendlyId; })
};
const mockGetSessionStore = vi.fn().mockReturnValue(mockSessionStore);
return {
mockSessionStore,
mockGetSessionStore
}
})
vi.mock("../../src/db/sessionStore", () => { return { getSessionStore: mockGetSessionStore }; });
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just to explain this pattern in a couple of places in this PR and future ones:
vi.mock works almost the same as jest.mock however it cannot capture external variables except for those that have been hoisted through vi.hoisted so vi.hoisted expressions are always run first so are guaranteed to exist for the mock, so most of it is the same, just any variable (such as a mocked method that you want to test) that is used in the tests and the mock must be hoisted

Copy link
Collaborator

Choose a reason for hiding this comment

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

umm are you sure?? ive never had to hoist like this when using vitest.. if your mock starts with mock it should auto hoist

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep i think so, here i have tried to just define them as variables with prefix mock however i get this error
image

its because vi.mock itself is hoisted to the top so i need to make sure those mocks are also hoisted so they exist when vi.mock runs

Copy link
Collaborator

@absternator absternator left a comment

Choose a reason for hiding this comment

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

LGTM... just left a small comment about hoisting

Comment on lines +6 to +16
const { mockSessionStore, mockGetSessionStore } = vi.hoisted(() => {
const mockSessionStore = {
getSessionIdFromFriendlyId: vi.fn().mockImplementation(() => { return sessionIdFromFriendlyId; })
};
const mockGetSessionStore = vi.fn().mockReturnValue(mockSessionStore);
return {
mockSessionStore,
mockGetSessionStore
}
})
vi.mock("../../src/db/sessionStore", () => { return { getSessionStore: mockGetSessionStore }; });
Copy link
Collaborator

Choose a reason for hiding this comment

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

umm are you sure?? ive never had to hoist like this when using vitest.. if your mock starts with mock it should auto hoist

@M-Kusumgar M-Kusumgar merged commit 62156cf into mrc-6018 Dec 3, 2024
10 of 12 checks passed
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