@forgebook/testing 0.1.5 → 0.1.7

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.
@@ -0,0 +1,8 @@
1
+ import { type TouchWindowRequest } from "forgebook/real-touch";
2
+ /**
3
+ * Opens the catalogue in a touch window and waits until the person closes it.
4
+ *
5
+ * @param request - the catalogue's address.
6
+ */
7
+ export declare const openTouchWindow: (request: TouchWindowRequest) => Promise<void>;
8
+ //# sourceMappingURL=touchWindow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"touchWindow.d.ts","sourceRoot":"","sources":["../../src/touchWindow.ts"],"names":[],"mappings":"AAcA,OAAO,EAAmB,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAwBhF;;;;GAIG;AACH,eAAO,MAAM,eAAe,YAAmB,kBAAkB,KAAG,OAAO,CAAC,IAAI,CAqB/E,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The window `forgebook dev --touch` opens: the catalogue in a Chromium of Playwright's, with Chromium's own touch
3
+ * emulation, so the mouse makes real touch events (trusted, with the browser's own scrolling) where the catalogue's
4
+ * Touch switch can only simulate them.
5
+ *
6
+ * @remarks
7
+ * Loaded from the project by the command only when it runs, as the check is, so the core needs no browser. The
8
+ * emulation is turned on through the browser's protocol (CDP) in every page of the window, popups included, and the
9
+ * pages are marked (`forgebook/real-touch`) so the catalogue's simulated touch stays off there. Still a computer: no
10
+ * virtual keyboard, no viewport shrinking under it, no iOS Safari.
11
+ *
12
+ * @module
13
+ */
14
+ import { chromium } from "@playwright/test";
15
+ import { REAL_TOUCH_FLAG } from "forgebook/real-touch";
16
+ /** How many fingers the emulation offers. */
17
+ const MAX_TOUCH_POINTS = 5;
18
+ /** The pages whose emulation is on: the first page is turned on before it loads, and the context then reports it. */
19
+ const emulated = new WeakSet();
20
+ /**
21
+ * Turns Chromium's touch emulation on in a page: the mouse's presses become touches, as in DevTools' device mode.
22
+ *
23
+ * @param page - the page.
24
+ */
25
+ const emulateTouch = async (page) => {
26
+ if (emulated.has(page))
27
+ return;
28
+ emulated.add(page);
29
+ const session = await page.context().newCDPSession(page);
30
+ await session.send("Emulation.setTouchEmulationEnabled", {
31
+ enabled: true,
32
+ maxTouchPoints: MAX_TOUCH_POINTS
33
+ });
34
+ await session.send("Emulation.setEmitTouchEventsForMouse", { enabled: true, configuration: "mobile" });
35
+ };
36
+ /**
37
+ * Opens the catalogue in a touch window and waits until the person closes it.
38
+ *
39
+ * @param request - the catalogue's address.
40
+ */
41
+ export const openTouchWindow = async (request) => {
42
+ const browser = await chromium.launch({ headless: false });
43
+ // the window's own size, not a fixed viewport: the person resizes it as they like
44
+ const context = await browser.newContext({ viewport: null, hasTouch: true });
45
+ await context.addInitScript((flag) => {
46
+ Object.defineProperty(window, flag, { value: true });
47
+ }, REAL_TOUCH_FLAG);
48
+ context.on("page", (page) => {
49
+ void emulateTouch(page);
50
+ });
51
+ const page = await context.newPage();
52
+ await emulateTouch(page);
53
+ await page.goto(request.url);
54
+ await new Promise((done) => {
55
+ browser.on("disconnected", () => done());
56
+ // the last page closed closes the window
57
+ context.on("close", () => done());
58
+ page.on("close", () => {
59
+ if (context.pages().length === 0)
60
+ void browser.close();
61
+ });
62
+ });
63
+ };
64
+ //# sourceMappingURL=touchWindow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"touchWindow.js","sourceRoot":"","sources":["../../src/touchWindow.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,QAAQ,EAAa,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,eAAe,EAA2B,MAAM,sBAAsB,CAAC;AAEhF,6CAA6C;AAC7C,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAE3B,qHAAqH;AACrH,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAQ,CAAC;AAErC;;;;GAIG;AACH,MAAM,YAAY,GAAG,KAAK,EAAE,IAAU,EAAiB,EAAE;IAC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,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7B,MAAM,IAAI,OAAO,CAAO,CAAC,IAAI,EAAE,EAAE;QAC/B,OAAO,CAAC,EAAE,CAAC,cAAc,EAAE,GAAS,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/C,yCAAyC;QACzC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,GAAS,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QACxC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAS,EAAE;YAC1B,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC,MAAM,KAAK,CAAC;gBAAE,KAAK,OAAO,CAAC,KAAK,EAAE,CAAC;QACzD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forgebook/testing",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Tests from a package's stories: each story and variant in the browser with axe, spills and overlays, screenshots, and each story rendered on the server.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -59,18 +59,22 @@
59
59
  "types": "./dist/src/shotStories.d.ts",
60
60
  "default": "./dist/src/shotStories.js"
61
61
  },
62
+ "./touch": {
63
+ "types": "./dist/src/touchWindow.d.ts",
64
+ "default": "./dist/src/touchWindow.js"
65
+ },
62
66
  "./fonts.css": "./dist/src/fonts/fonts.css"
63
67
  },
64
68
  "dependencies": {
65
69
  "@axe-core/playwright": "4.14.0",
66
70
  "@ensiria/cli-kit": "^0.1.1",
67
- "@forgebook/story-format": "0.1.3"
71
+ "@forgebook/story-format": "0.1.4"
68
72
  },
69
73
  "peerDependencies": {
70
74
  "@playwright/test": "^1.64.0",
71
75
  "vite": "^8.0.0",
72
76
  "vitest": "^5.0.0",
73
- "forgebook": "^0.1.4"
77
+ "forgebook": "^0.1.6"
74
78
  },
75
79
  "devDependencies": {
76
80
  "@playwright/test": "1.64.1",
@@ -79,9 +83,9 @@
79
83
  "react": "19.3.0",
80
84
  "vite": "8.3.5",
81
85
  "vitest": "5.0.5",
86
+ "@forgebook/typescript-config": "0.0.0",
82
87
  "@forgebook/tools": "0.0.0",
83
- "forgebook": "0.1.4",
84
- "@forgebook/typescript-config": "0.0.0"
88
+ "forgebook": "0.1.6"
85
89
  },
86
90
  "publishConfig": {
87
91
  "access": "public"