@next/playwright 16.2.0-canary.76 → 16.2.0-canary.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -37,6 +37,9 @@ interface PlaywrightPage {
37
37
  * await page.goto(url)
38
38
  * // ...
39
39
  * }, { baseURL: 'http://localhost:3000' })
40
+ *
41
+ * When `@playwright/test` is installed, acquire/release actions appear
42
+ * as labeled steps in the Playwright UI.
40
43
  */
41
44
  export declare function instant<T>(page: PlaywrightPage, fn: () => Promise<T>, options?: {
42
45
  baseURL?: string;
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.instant = instant;
4
+ const step_1 = require("./step");
4
5
  const INSTANT_COOKIE = 'next-instant-navigation-testing';
5
6
  /**
6
7
  * Runs a function with instant navigation enabled. Within this scope,
@@ -19,6 +20,9 @@ const INSTANT_COOKIE = 'next-instant-navigation-testing';
19
20
  * await page.goto(url)
20
21
  * // ...
21
22
  * }, { baseURL: 'http://localhost:3000' })
23
+ *
24
+ * When `@playwright/test` is installed, acquire/release actions appear
25
+ * as labeled steps in the Playwright UI.
22
26
  */
23
27
  async function instant(page, fn, options) {
24
28
  // Acquire the lock by setting the cookie via the browser context. This
@@ -26,11 +30,11 @@ async function instant(page, fn, options) {
26
30
  // The cookie triggers the CookieStore change event in
27
31
  // navigation-testing-lock.ts, which acquires the in-memory navigation lock.
28
32
  const { hostname } = new URL(resolveURL(page, options));
29
- await page
33
+ await (0, step_1.step)('Acquire Instant Lock', () => page
30
34
  .context()
31
35
  .addCookies([
32
36
  { name: INSTANT_COOKIE, value: '1', domain: hostname, path: '/' },
33
- ]);
37
+ ]));
34
38
  try {
35
39
  return await fn();
36
40
  }
@@ -39,7 +43,7 @@ async function instant(page, fn, options) {
39
43
  // triggers the CookieStore change event which resolves the in-memory
40
44
  // lock. For MPA navigations (reload, plain anchor), the listener in
41
45
  // app-bootstrap.ts triggers a page reload to fetch dynamic data.
42
- await page.context().clearCookies({ name: INSTANT_COOKIE });
46
+ await (0, step_1.step)('Release Instant Lock', () => page.context().clearCookies({ name: INSTANT_COOKIE }));
43
47
  }
44
48
  }
45
49
  /**
package/dist/step.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export type Step = <T>(title: string, body: () => Promise<T>) => Promise<T>;
2
+ /**
3
+ * When `@playwright/test` is installed and we're running inside the Playwright
4
+ * test runner, wraps the body in a `test.step()` so it appears as a labeled
5
+ * step in the Playwright UI. Otherwise just executes the body directly.
6
+ */
7
+ declare let step: Step;
8
+ export { step };
package/dist/step.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.step = void 0;
5
+ /**
6
+ * When `@playwright/test` is installed and we're running inside the Playwright
7
+ * test runner, wraps the body in a `test.step()` so it appears as a labeled
8
+ * step in the Playwright UI. Otherwise just executes the body directly.
9
+ */
10
+ let step = (_title, body) => body();
11
+ exports.step = step;
12
+ try {
13
+ const pw = require('@playwright/test');
14
+ if (typeof ((_a = pw.test) === null || _a === void 0 ? void 0 : _a.step) === 'function') {
15
+ const playwrightStep = pw.test.step;
16
+ exports.step = step = async (title, body) => {
17
+ try {
18
+ return await playwrightStep(title, body);
19
+ }
20
+ catch (e) {
21
+ // If test.step fails because we're not inside the Playwright test
22
+ // runner (e.g., running under Jest), fall back to executing the body
23
+ // directly without step labels.
24
+ if (e instanceof Error &&
25
+ e.message.includes('can only be called from a test')) {
26
+ return body();
27
+ }
28
+ throw e;
29
+ }
30
+ };
31
+ }
32
+ }
33
+ catch { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/playwright",
3
- "version": "16.2.0-canary.76",
3
+ "version": "16.2.0-canary.77",
4
4
  "repository": {
5
5
  "url": "vercel/next.js",
6
6
  "directory": "packages/next-playwright"
@@ -17,6 +17,14 @@
17
17
  "dev": "tsc -d -w -p tsconfig.json",
18
18
  "typescript": "tsec --noEmit -p tsconfig.json"
19
19
  },
20
+ "peerDependencies": {
21
+ "@playwright/test": ">=1.0.0"
22
+ },
23
+ "peerDependenciesMeta": {
24
+ "@playwright/test": {
25
+ "optional": true
26
+ }
27
+ },
20
28
  "devDependencies": {
21
29
  "typescript": "5.9.2"
22
30
  }