snippet lint

This commit is contained in:
Simon Knott 2025-02-07 16:08:47 +01:00
parent 974e12366e
commit c322af9ed9
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC

View file

@ -568,7 +568,7 @@ To get started, enable the `mockingProxy` option in your Playwright config:
```js ```js
export default defineConfig({ export default defineConfig({
use: { mockingProxy: "inject-via-header" } use: { mockingProxy: 'inject-via-header' }
}); });
``` ```
@ -724,7 +724,7 @@ const serverConfig = {
(req, next) => { (req, next) => {
const proxy = inject(REQUEST)?.headers.get('x-playwright-proxy'); const proxy = inject(REQUEST)?.headers.get('x-playwright-proxy');
if (proxy) if (proxy)
req = req.clone({ url: decodeURIComponent(proxy) + req.url }) req = req.clone({ url: decodeURIComponent(proxy) + req.url });
return next(req); return next(req);
}, },
]), ]),
@ -743,8 +743,8 @@ Set up a server-side fetch override in an Astro integration:
```js ```js
// astro.config.mjs // astro.config.mjs
import { defineConfig } from 'astro/config'; import { defineConfig } from 'astro/config';
import type { AstroIntegration } from "astro" import type { AstroIntegration } from 'astro';
import { AsyncLocalStorage } from "async_hooks"; import { AsyncLocalStorage } from 'async_hooks';
const playwrightMockingProxy: AstroIntegration = { const playwrightMockingProxy: AstroIntegration = {
name: 'playwrightMockingProxy', name: 'playwrightMockingProxy',
@ -784,24 +784,24 @@ export default defineConfig({
```js ```js
// server/plugins/playwright-mocking-proxy.ts // server/plugins/playwright-mocking-proxy.ts
import { getGlobalDispatcher, setGlobalDispatcher } from "undici" import { getGlobalDispatcher, setGlobalDispatcher } from 'undici';
import { useEvent, getRequestHeader } from '#imports' import { useEvent, getRequestHeader } from '#imports';
export default defineNitroPlugin(() => { export default defineNitroPlugin(() => {
if (process.env.NODE_ENV !== 'test') if (process.env.NODE_ENV !== 'test')
return; return;
const proxiedDispatcher = getGlobalDispatcher().compose(dispatch => (opts, handler) => { const proxiedDispatcher = getGlobalDispatcher().compose(dispatch => (opts, handler) => {
const isInternal = opts.path.startsWith("/__nuxt") const isInternal = opts.path.startsWith('/__nuxt');
const proxy = getRequestHeader(useEvent(), 'x-playwright-proxy') const proxy = getRequestHeader(useEvent(), 'x-playwright-proxy');
if (proxy && !isInternal) { if (proxy && !isInternal) {
const newURL = new URL(decodeURIComponent(proxy) + opts.origin + opts.path); const newURL = new URL(decodeURIComponent(proxy) + opts.origin + opts.path);
opts.origin = newURL.origin; opts.origin = newURL.origin;
opts.path = newURL.pathname; opts.path = newURL.pathname;
} }
return dispatch(opts, handler) return dispatch(opts, handler);
}) });
setGlobalDispatcher(proxiedDispatcher) setGlobalDispatcher(proxiedDispatcher);
}); });
``` ```
@ -813,5 +813,5 @@ export default defineNuxtConfig({
asyncContext: true, asyncContext: true,
} }
} }
}) });
``` ```