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

feat(test runner): server side mocking #34520

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Jan 28, 2025

Implements #30766.

Adds an HTTP proxy that application servers can route their network traffic through to make it subject to Playwright routes.

@Skn0tt Skn0tt requested a review from dgozman January 28, 2025 15:34
@Skn0tt Skn0tt self-assigned this Jan 28, 2025
@Skn0tt Skn0tt force-pushed the mockingproxy-headers-only branch 2 times, most recently from 16427c5 to 1c79cc8 Compare January 28, 2025 15:39

This comment has been minimized.

fix linter

revert unneeded change
@Skn0tt Skn0tt force-pushed the mockingproxy-headers-only branch from 1c79cc8 to 156918e Compare January 28, 2025 16:15

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

docs/src/test-api/class-testoptions.md Outdated Show resolved Hide resolved
packages/playwright-core/src/client/browserContext.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/utils/httpServer.ts Outdated Show resolved Hide resolved
packages/playwright/src/index.ts Outdated Show resolved Hide resolved
docs/src/mock.md Outdated Show resolved Hide resolved
docs/src/mock.md Outdated Show resolved Hide resolved
packages/protocol/src/protocol.yml Outdated Show resolved Hide resolved
packages/protocol/src/protocol.yml Show resolved Hide resolved

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

packages/playwright-core/src/client/browserContext.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/client/mockingProxy.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/client/mockingProxy.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/client/mockingProxy.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/client/mockingProxy.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/server/mockingProxy.ts Outdated Show resolved Hide resolved

This comment has been minimized.

This comment has been minimized.

@vitalets
Copy link
Contributor

vitalets commented Feb 5, 2025

Hi @Skn0tt @dgozman
I've recently discovered that Next.js has an experimental flag to mock server-side requests with Playwright:
https://github.com/vercel/next.js/blob/canary/packages/next/src/experimental/testmode/playwright/README.md

Just curios, how does it relates to this PR? Seems like they provide own fixtures for running proxy as well..

@Skn0tt
Copy link
Member Author

Skn0tt commented Feb 5, 2025

Just curios, how does it relates to this PR? Seems like they provide own fixtures for running proxy as well..

Their experiment tries to solve the same problem in a very similar manner to this. It doesn't look like a lot happened to that experiment in Next.js, and it's not even in the docs. So I could imagine that they'll recommend our mocking proxy instead.

@Skn0tt
Copy link
Member Author

Skn0tt commented Feb 5, 2025

cc @dvoytenko @ijjk for visibility

@MindaugasMateika
Copy link
Contributor

Hi @Skn0tt @dgozman I've recently discovered that Next.js has an experimental flag to mock server-side requests with Playwright: https://github.com/vercel/next.js/blob/canary/packages/next/src/experimental/testmode/playwright/README.md

Just curios, how does it relates to this PR? Seems like they provide own fixtures for running proxy as well..

Third-party implementations, such as msw, playwright-msw and others, have always been available for those who wanted server-side mocking. However, it doesn't compare with having server-side mocking built directly into Playwright which will offer parallel support, bug fixes, and most imporantly peace of mind knowing it will remain working with future releases ❤️ My 2 cents, not a contributor.

@Skn0tt
Copy link
Member Author

Skn0tt commented Feb 5, 2025

From my understanding of playwright-msw, it's about mocking browser requests. This work is about mocking server requests, which is different.

@Skn0tt Skn0tt force-pushed the mockingproxy-headers-only branch from 275e062 to a5f4be6 Compare February 6, 2025 09:32

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Feb 7, 2025

Test results for "tests 1"

1 failed
❌ [playwright-test] › tests/reporter-html.spec.ts:2680:5 › merged › execSync doesnt produce a second stdout attachment @macos-latest-node18-2

13 flaky ⚠️ [firefox-page] › tests/page/page-evaluate.spec.ts:403:3 › should throw for too deep reference chain @firefox-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/browsercontext-proxy.spec.ts:27:3 › should work when passing the proxy only on the context level @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/browsertype-connect.spec.ts:554:5 › launchServer › should error when saving download after deletion @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/inspector/cli-codegen-2.spec.ts:24:7 › cli codegen › should contain open page @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/proxy.spec.ts:93:11 › should proxy local network requests › with other bypasses › link-local @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/proxy.spec.ts:228:3 › should use socks proxy @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/proxy.spec.ts:238:3 › should use socks proxy in second page @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/selector-generator.spec.ts:129:5 › selector generator › should use ordinal for identical nodes @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/selector-generator.spec.ts:437:5 › selector generator › should ignore empty aria-label for candidate consideration @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › tests/library/trace-viewer.spec.ts:109:1 › should show tracing.group in the action list with location @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-leaks.spec.ts:82:5 › click should not leak @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-leaks.spec.ts:107:5 › fill should not leak @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › tests/page/page-leaks.spec.ts:161:5 › waitFor should not leak @webkit-ubuntu-22.04-node18

37848 passed, 655 skipped
✔️✔️✔️

Merge workflow run.

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.

4 participants