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-5952 vitest pt 1 #219

Merged
merged 1 commit into from
Nov 13, 2024
Merged

Mrc-5952 vitest pt 1 #219

merged 1 commit into from
Nov 13, 2024

Conversation

M-Kusumgar
Copy link
Collaborator

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

part 1 for the vitest upgrade, some main changes to be aware of that youll be seeing in the following PRs:

  • vi.mock is very similar to jest.mock but you do have to mock everything the component uses explicitly so if you import update function from plotly.js-basic-min then you have to explicitly state it as undefined even if you dont use it in the test so update: undefined
  • if you want to use mocked functions in vi.mock and use them later in your file to see how many times theyve been called for example then you must use vi.hoisted to create your mocked functions and these will be available in vi.mock and the rest of your tests
  • done callbacks have been deprecated for a while, so replacing setTimeout with await/async

@M-Kusumgar M-Kusumgar changed the title first batch of tests Mrc-5952 vitest pt 1 Nov 6, 2024
Copy link
Contributor

@EmmaLRussell EmmaLRussell left a comment

Choose a reason for hiding this comment

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

Looks good! It's hard to tell from CI how these front end tests are doing because it runs the back end tests first - which also fail. so it never gets as far as the front end ones. Might be worth swapping that order round for now?

Comment on lines +2 to 24
vi.mock("plotly.js-basic-dist-min", () => {
return {
default: undefined,
update: undefined
}
});
vi.mock("../../../../src/components/help/MarkdownItImport.ts", () => {
class MarkDownItClass {
constructor() {
return {
use: vi.fn().mockReturnValue({
renderer: { rules: {} },
render: vi.fn()
})
}
}
};
return {
default: {
default: MarkDownItClass
}
}
});
Copy link
Contributor

Choose a reason for hiding this comment

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

If some of these bits are going to pop up several times, I wonder if it would be worth importing them from a shared module?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thats a good idea im not sure if you actually can even extract out vi.mocks, they seem to care about hoisting and not capturing stuff from the env and so on but i think there must be some functionality in vitest! i have made a ticket: https://mrc-ide.myjetbrains.com/youtrack/issue/mrc-5980/vi.mock-in-shared-module will do it in a future pr

@M-Kusumgar
Copy link
Collaborator Author

Looks good! It's hard to tell from CI how these front end tests are doing because it runs the back end tests first - which also fail. so it never gets as far as the front end ones. Might be worth swapping that order round for now?

i did these PRs after they all started passing, will see it passing fairly soon!

@M-Kusumgar M-Kusumgar changed the base branch from mrc-5951 to mrc-5945 November 13, 2024 20:26
@M-Kusumgar M-Kusumgar merged commit 4c35783 into mrc-5945 Nov 13, 2024
0 of 2 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