-
Notifications
You must be signed in to change notification settings - Fork 53
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
test(playwright): enhance manager procedure mocking #1254
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
Thank you to have started this, so for me I tried this way and first the typescript problem is blocking, and I don't see a beautiful way to fix it :/
So maybe we should convert it to a function with two sub function inside?
I explain:
// Path: playwright/utils/mockManagerProcedures.ts
async function handleRoute() {}
function mockManagerProcedures() {
const procedures: Map<string, MockManagerProcedure[]> = new Map();
init: (page: Page) => Promise<void>;
mock: ({ path, handler?, config? }) => void;
}
// Path: playwright/fixtures/index.ts
export type DefaultFixtures = {
mockProcedure: ({ path, handler?, config? }) => void
};
export const defaultTest = () => {
return baseTest.extend<DefaultFixtures>({
mockProcedure: async ({ page }, use) => {
const { init, mock } = mockManagerProcedures();
await init(page);
await use(mock);
}
});
WDYT?
* Mocks | ||
*/ | ||
procedures: async ({ page }, use) => { | ||
await use(await MockManagerProcedures.init(page)); |
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.
Here this is broken in typescript with any :/
I guess it's because of the confusion with class for typescript.
Maybe we should create a classic TS function to handle this? It could remove the problem with the constructor. WDYT?
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.
It might be because I renamed mockManagerProcedures.ts
to MockManagerProcedures.ts
and eslint/tsserver isn't picking it up. I have full typing on my end.
Git properly shows the rename that was done via git mv
. If it's still giving you trouble, maybe we can just rename the file something else temporarily.
A classic function is possible, but seems a bit messy considering we already have a class that encapsulates the mocking logic. The alternative was:
const mockManagerProcedures = new MockManagerProcedures()
await mockManagerProcedures.setup(page)
The setup
/init
methods are necessary because constructors cannot return Promises, thus they cannot use async
/await
.
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.
Another thing to consider re: using a plain function:
We may want to check the list of mocked procedures. Returning the full MockProceduresClass
allows us to read the instance's procedures
property. Providing a single mockProcedures
fixture wouldn't allow that, unless we returned an object.
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 with the typescript problem 🚀
Super work! Thanks!
Context
This PR enhance's
@slicemachine/manager
mocking in Playwright tests.This PR can be used as is or as a base for a refined implementation.
The Solution
procedures
fixture with aprocedures.mock()
method.Impact / Dependencies
Checklist before requesting a review
🐕