You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: add more documentation and Playwright guidance [🤖 automated] (#89)
> [!NOTE]
> 🤖 This PR was generated by HeiBot from the following prompt:
> > Proceed with improvements to the documentation. While you're at it,
a recent upgrade caused the docs to no longer show the root README.md in
the docusaurus pages as the default home page. Let's restore that
functionality and ensure the embedded image is also shown/published.
> > make sure to run prettier formatter afterwards so files use valid
formatting.
---
## Summary
- replace the custom Docusaurus landing page with a generated homepage
synced from the repository root `README.md`
- copy README media assets into the docs static output and wire homepage
sync into the docs `start`, `build`, and `deploy` scripts
- add a dedicated Playwright guide for installing Laika interceptors
before initial requests fire, and link it from the README and existing
docs pages
- fix the stale API-reference link used from the README/homepage flow
## Testing
- `yarn rrun prettier --check README.md docs/README.md docs/package.json
docs/sidebars.js docs/scripts/sync-homepage-from-readme.mjs
docs/src/pages/index.mdx docs/docs/how-to-install.md
docs/docs/resetting-between-tests.md docs/docs/usage-in-playwright.md`
- `cd docs && yarn build`
## Notes
- removed the old custom React landing page and its unused CSS module in
favor of the generated README-backed MDX page
- verified the built homepage now emits `/laika/media/...` asset URLs so
the embedded README images publish correctly under the site base path
---
> [!TIP]
> **💬 To make additional changes**, continue the conversation in the
original Slack thread, or trigger a new workflow dispatch with
`restore-session-from-run-id: 23865408578`.
<!-- HEIBOT_RUN_ID:24852762143 -->
---------
Co-authored-by: HeiBot Agent <183646609+zendesk-heibot[bot]@users.noreply.github.com>
Co-authored-by: Bazyli Brzóska <bbrzoska@zendesk.com>
Co-authored-by: Codex <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Copy file name to clipboardExpand all lines: docs/README.md
+10-3Lines changed: 10 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,27 @@
1
1
# Website
2
2
3
-
This website is built using [Docusaurus 2](https://v2.docusaurus.io/), a modern static website generator.
3
+
This website is built using [Docusaurus](https://docusaurus.io/), a modern static website generator.
4
4
5
5
## Installation
6
6
7
7
```console
8
-
yarn install
8
+
cd ..
9
+
yarn install --immutable
10
+
11
+
cd docs
12
+
yarn install --immutable
9
13
```
10
14
15
+
The docs site generates API reference pages from the package source, so the root workspace dependencies and generated `tsconfig.json` need to exist. The docs scripts will bootstrap those root dependencies automatically if they are missing, but installing both workspaces upfront is faster and keeps the setup explicit.
16
+
11
17
## Local Development
12
18
13
19
```console
14
20
yarn start
15
21
```
16
22
17
-
This command starts a local development server and open up a browser window. Most changes are reflected live without having to restart the server.
23
+
This command starts a local development server and opens a browser window. Most changes are reflected live without having to restart the server.
24
+
The docs home at `/docs/` is generated from the repository root `README.md` before the site starts or builds. The generated README page, copied README media, and generated API reference docs all stay gitignored.
Return a cleanup function from `onSubscribe()` if the interceptor needs to dispose any test-local state when the observer disconnects.
84
+
85
+
## Turn off network fallback
86
+
87
+
By default, unmatched queries and mutations can still fall through to the next Apollo link. If you want a request to stay in a loading state until your test explicitly responds, disable that fallback:
See [Usage in Playwright](pathname:///docs/usage-in-playwright) and [Usage in Cypress](pathname:///docs/usage-in-cypress) for the browser-runner patterns built on top of that hook.
Copy file name to clipboardExpand all lines: docs/docs/how-to-install.md
+75-20Lines changed: 75 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,11 +25,12 @@ If your project uses Apollo Client 4, make sure `rxjs` `^7.3.0` is installed as
25
25
26
26
## Loading the Laika Link in your project
27
27
28
-
For tests that run on your production code, you'll likely want to load the link conditionally, so that it is not downloaded by your users, but only in certain scenarios, e.g. inside of your browser test runner.
28
+
For tests that run on your production code, you'll likely want to load the link conditionally, so that it is not downloaded by your users, but only in certain scenarios, such as inside of your browser test runner.
29
29
30
-
Include the link wherever you like in your chain of links, however we recommend putting it right before the connection with the backend occurs for most accurate results.
30
+
Include the link wherever you like in your chain of links. We recommend putting it right before the connection with the backend occurs for the most accurate results.
@@ -49,58 +50,110 @@ const apolloClient = new ApolloClient({
49
50
})
50
51
```
51
52
52
-
### Customizing loading of the Link
53
+
### Customizing loading of the link
53
54
54
-
By default, link is lazily loaded and if you use webpack, split into a seaprate chunk by utilizing the `createLazyLoadableLink` function provided in the package.
55
+
By default, the link is lazily loaded and, if you use webpack, split into a separate chunk by utilizing the `createLazyLoadableLink` function provided in the package.
55
56
56
57
You may customize this behavior. This is the default behavior:
If you're using webpack, the `webpackChunkName` magic comment will ensure a separate chunk is file created for the link.
73
+
If you're using webpack, the `webpackChunkName` magic comment will ensure a separate chunk is created for the link.
73
74
74
-
## Loading the Link in unit tests
75
+
## Conditionally enabling Laika
75
76
76
-
If you have full control over the Apollo client inside of your tests, you may directly create the Link from an instance of Laika:
77
+
Most apps should enable Laika only for specific environments, developers, or test sessions.
77
78
78
-
```typescript
79
+
Common patterns include:
80
+
81
+
- a build-time flag such as `NODE_ENV !== 'production'`
82
+
- a query parameter such as `?laika=1` or `?e2e=true`
83
+
- a test-only browser hook that your Playwright or Cypress suite opts into
84
+
85
+
For complete examples, see [Conditionally loading Laika](pathname:///docs/loading-laika-conditionally).
86
+
87
+
## Browser E2E runners
88
+
89
+
When you need to intercept requests that fire during the initial page render, register callbacks on `window.laikaReadyCallbacks` before the app code executes.
90
+
91
+
Use:
92
+
93
+
-[Usage in Playwright](pathname:///docs/usage-in-playwright) for `page.addInitScript()` / `browserContext.addInitScript()`
94
+
-[Usage in Cypress](pathname:///docs/usage-in-cypress) for `cy.visit(..., { onBeforeLoad })`
95
+
96
+
If you already know your app only enables Laika behind a query parameter, make sure your test navigates with that flag enabled as well.
97
+
98
+
## Loading the link in unit tests
99
+
100
+
If you have full control over the Apollo client inside of your tests, you may directly create the link from an instance of Laika:
101
+
102
+
```ts
103
+
import {
104
+
ApolloClient,
105
+
ApolloLink,
106
+
InMemoryCache,
107
+
Observable,
108
+
gql,
109
+
} from'@apollo/client'
79
110
import { Laika } from'@zendesk/laika/esm/laika'
80
111
81
112
const laika =newLaika()
82
113
83
-
const link =from([laika.createLink(), newHttpLink({ uri: '...' })])
For a more complete unit-testing guide, see [Usage in Jest / Vitest](pathname:///docs/usage-in-jest-vitest).
156
+
104
157
Note that Laika itself isn't directly exported from `@zendesk/laika` in order to minimize the amount of data that is bundled with your application when using lazily loaded Laika in production.
105
158
106
159
If your test runner reuses the same page or process across tests, call `laika.mockRestoreAll()` in `afterEach` to clear all interceptors before the next scenario starts. See [Resetting Between Tests](pathname:///docs/resetting-between-tests).
@@ -111,4 +164,6 @@ See the [API reference](pathname:///docs/api).
111
164
112
165
## What next?
113
166
114
-
Read about how to use the library in [Laika](pathname:///docs/api/interfaces/Laika).
167
+
If you're deciding where Laika should sit in your test strategy, start with [Testing approach](pathname:///docs/testing-approach).
168
+
169
+
For advanced matcher, lifecycle, and passthrough patterns, see [Advanced usage](pathname:///docs/advanced-usage).
0 commit comments