fix: export NetworkFixture class as value#32
fix: export NetworkFixture class as value#32christoph-fricke wants to merge 1 commit intomswjs:mainfrom
Conversation
|
Hi, @christoph-fricke. The You can configure {
network: [
({ page, store, baseURL }, use) => {
const [fixture] = createNetworkFixture({
initialHandlers: defineHandlers(store, baseURL!)
})
return fixture({ page }, use)
},
{ auto: true }
]
}This might not be the most elegant approach, but that is what we have given the current Playwright fixtures composition. I highly suggest you explore this instead of extending the Let me know if this works for your case. |
|
Hi @kettanaito. I am only creating an instance of the While I am open to use your workaround instead and have tried to use it, it breaks instantly once type checking and type-aware linting come into play. Not using destructuring does not work because Playwright fails with "First argument must use the object destructuring pattern.": network: [
({ page, store, baseURL }, use, testInfo) => {
const [fixture] = createNetworkFixture({
initialHandlers: defineHandlers(store, baseURL!),
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: Don't want to destructure and restructure every Fixture Arg...
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return fixture({ page }, use, testInfo); // `fixture` returns any...
},
{ auto: true },
],Compared to to the snippet, creating an instance of |
|
Thanks for the insight. That's not a great experience, but I would say using I've seen two approaches to Playwright fixtures in a library context:
The second one sounds more like what you're proposing. |
Before version v0.4.3 the class
NetworkFixturewas exposed as a full export. #17 changed it to a type-only export, which results in the class no longer being exported from JS (only its type definitions file).In my use-case I need to construct the handlers passed to the network fixture from another Playwright fixture. Therefore, using the provided high-level
createNetworkFixturefunction to create the fixture does not work in this case.