Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ plugins:
spec: 'https://mskelton.dev/yarn-outdated/v2'

yarnPath: .yarn/releases/yarn-4.0.2.cjs

nodeLinker: node-modules
31 changes: 31 additions & 0 deletions packages/playwright-msw/src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,37 @@ describe('utils', () => {
});
});

describe('getHandlerPath for GraphQL handler', () => {
it.each<{ path: Path; expected: Path }>`
path | expected
${'/api/users'} | ${'/api/users'}
${/^\/api\/.*/} | ${/^\/api\/.*/}
`(
'return "$expected" for graphql.link() with "$path"',
({ path, expected }) => {
expect(
getHandlerPath(
graphql
.link(path)
.query('Query', () => HttpResponse.json({ data: {} })),
{},
),
).toStrictEqual(expected);
},
);

it('return the default endpoint path for graphql handler without link() call', () => {
const defaultHandler = graphql.query('Query', () =>
HttpResponse.json({ data: {} }),
);
expect(
getHandlerPath(defaultHandler, {
graphqlUrl: '/defaultGraphqlEndpoint',
}),
).toStrictEqual('/defaultGraphqlEndpoint');
});
});

describe('convertMswPathToPlaywrightUrl', () => {
it.each<{ mswPath: string; playwrightUrl: string; expected: boolean }>`
mswPath | playwrightUrl | expected
Expand Down
4 changes: 4 additions & 0 deletions packages/playwright-msw/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const getHandlerPath = (
config: Config,
): Path => {
if (getHandlerType(handler) === 'graphql') {
const handlerInternal = handler as unknown as { endpoint: Path }; // private GraphQLHandler.endpoint
if (handlerInternal.endpoint !== '*') {
return handlerInternal.endpoint;
}
const { graphqlUrl } = config;
if (!graphqlUrl) {
throw new Error(
Expand Down