@trackunit/iris-app-playwright 0.2.122 → 0.3.2
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/README.md +7 -5
- package/migrations/v1-0-0/await-iris-app.js +223 -0
- package/migrations.json +7 -1
- package/package.json +1 -1
- package/src/fixtures/baseTest.d.ts +2 -1
- package/src/fixtures/baseTest.js +3 -1
- package/src/fixtures/irisApp.fixture.d.ts +52 -2
- package/src/fixtures/irisApp.fixture.js +61 -3
- package/src/generators/playwright-configuration/files/root/playwright/tests/app.spec.ts__tmpl__ +1 -1
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ describe("My Feature", () => {
|
|
|
63
63
|
test("user can log in", async ({ page, login, irisApp }) => {
|
|
64
64
|
await login();
|
|
65
65
|
|
|
66
|
-
const app = irisApp();
|
|
66
|
+
const app = await irisApp();
|
|
67
67
|
await expect(app.getByTestId("app-content")).toBeVisible();
|
|
68
68
|
});
|
|
69
69
|
});
|
|
@@ -110,13 +110,15 @@ You don't have to do anything to opt in — the cache is wired up automatically.
|
|
|
110
110
|
|
|
111
111
|
### `irisApp`
|
|
112
112
|
|
|
113
|
-
|
|
113
|
+
Resolves to a `FrameLocator` for an Iris app iframe. Always await it.
|
|
114
114
|
|
|
115
115
|
```typescript
|
|
116
|
-
irisApp(options?: IrisAppOptions): FrameLocator
|
|
116
|
+
irisApp(options?: IrisAppOptions): Promise<FrameLocator>
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
Defaults to `iframe[data-testid="app-iframe"]`. Pass `testId` to target a different iframe.
|
|
119
|
+
Defaults to the first `iframe[data-testid="app-iframe"]`. Pass `testId` to target a different iframe. On a feature-branch host the fixture waits until that iframe is attached, and a missing iframe rejects with `host never became ready`.
|
|
120
|
+
|
|
121
|
+
Before 1.0.0 `irisApp()` returned the `FrameLocator` synchronously. The `v1-0-0-await-iris-app` migration rewrites existing `irisApp(...)` calls to `await irisApp(...)` and widens local `() => FrameLocator` types for the fixture; run it with `nx g @trackunit/migrations:migrate` followed by `nx g @trackunit/migrations:run-migrations`. Calls outside an async function are reported for manual review.
|
|
120
122
|
|
|
121
123
|
### `storybookPreview`
|
|
122
124
|
|
|
@@ -212,7 +214,7 @@ Use the `describe` wrapper exported from `@trackunit/iris-app-playwright/support
|
|
|
212
214
|
| Cypress API | Playwright equivalent |
|
|
213
215
|
|---|---|
|
|
214
216
|
| `cy.login("auth")` | `await login()` |
|
|
215
|
-
| `cy.enterIrisApp()` | `irisApp()`
|
|
217
|
+
| `cy.enterIrisApp()` | `await irisApp()` resolves to `FrameLocator` |
|
|
216
218
|
| `cy.enterStorybookPreview()` | `storybookPreview()` returns `FrameLocator` |
|
|
217
219
|
| `cy.getValidateFeatureFlags()` | `getValidateFeatureFlags()` |
|
|
218
220
|
| `cy.configCat("flag")` | `await configCat("flag")` |
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.awaitIrisApp = exports.awaitIrisAppCalls = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
7
|
+
const MIGRATION_NAME = "v1-0-0-await-iris-app";
|
|
8
|
+
const FIXTURE_NAME = "irisApp";
|
|
9
|
+
const SOURCE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
|
|
10
|
+
const isSourceFile = (filePath) => SOURCE_EXTENSIONS.some(extension => filePath.endsWith(extension));
|
|
11
|
+
const isUnderNodeModulesOrDist = (filePath) => filePath.split("/").some(segment => segment === "node_modules" || segment === "dist" || segment === ".nx");
|
|
12
|
+
const scriptKindFor = (filePath) => {
|
|
13
|
+
if (filePath.endsWith(".tsx"))
|
|
14
|
+
return ts.ScriptKind.TSX;
|
|
15
|
+
if (filePath.endsWith(".jsx"))
|
|
16
|
+
return ts.ScriptKind.JSX;
|
|
17
|
+
if (filePath.endsWith(".ts"))
|
|
18
|
+
return ts.ScriptKind.TS;
|
|
19
|
+
return ts.ScriptKind.JS;
|
|
20
|
+
};
|
|
21
|
+
const parse = (filePath, content) => ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true, scriptKindFor(filePath));
|
|
22
|
+
const FRAME_LOCATOR = "FrameLocator";
|
|
23
|
+
/** `irisApp(...)` or `<anything>.irisApp(...)`. */
|
|
24
|
+
const isIrisAppCall = (node) => {
|
|
25
|
+
if (!ts.isCallExpression(node))
|
|
26
|
+
return false;
|
|
27
|
+
const callee = node.expression;
|
|
28
|
+
if (ts.isIdentifier(callee))
|
|
29
|
+
return callee.text === FIXTURE_NAME;
|
|
30
|
+
return ts.isPropertyAccessExpression(callee) && callee.name.text === FIXTURE_NAME;
|
|
31
|
+
};
|
|
32
|
+
const unwrapParentheses = (node) => {
|
|
33
|
+
let current = node;
|
|
34
|
+
while (ts.isParenthesizedExpression(current.parent)) {
|
|
35
|
+
current = current.parent;
|
|
36
|
+
}
|
|
37
|
+
return current;
|
|
38
|
+
};
|
|
39
|
+
const isAlreadyAwaited = (call) => ts.isAwaitExpression(unwrapParentheses(call).parent);
|
|
40
|
+
/**
|
|
41
|
+
* `await` binds looser than member access and call, so `irisApp().x` must
|
|
42
|
+
* become `(await irisApp()).x`. Everything else (`const a = irisApp()`,
|
|
43
|
+
* `expect(irisApp())`, `return irisApp()`, `irisApp() ?? x`) reads correctly
|
|
44
|
+
* with a bare `await` in front.
|
|
45
|
+
*/
|
|
46
|
+
const needsParentheses = (call) => {
|
|
47
|
+
const parent = call.parent;
|
|
48
|
+
if (ts.isPropertyAccessExpression(parent) || ts.isElementAccessExpression(parent)) {
|
|
49
|
+
return parent.expression === call;
|
|
50
|
+
}
|
|
51
|
+
if (ts.isCallExpression(parent))
|
|
52
|
+
return parent.expression === call;
|
|
53
|
+
// `await x ** 2` is a syntax error; the unary operand of `**` must be parenthesised.
|
|
54
|
+
if (ts.isBinaryExpression(parent)) {
|
|
55
|
+
return parent.operatorToken.kind === ts.SyntaxKind.AsteriskAsteriskToken && parent.left === call;
|
|
56
|
+
}
|
|
57
|
+
return ts.isNonNullExpression(parent) || ts.isTaggedTemplateExpression(parent);
|
|
58
|
+
};
|
|
59
|
+
const isFunctionLike = (node) => ts.isFunctionDeclaration(node) ||
|
|
60
|
+
ts.isFunctionExpression(node) ||
|
|
61
|
+
ts.isArrowFunction(node) ||
|
|
62
|
+
ts.isMethodDeclaration(node) ||
|
|
63
|
+
ts.isGetAccessorDeclaration(node) ||
|
|
64
|
+
ts.isSetAccessorDeclaration(node) ||
|
|
65
|
+
ts.isConstructorDeclaration(node);
|
|
66
|
+
const isAsync = (fn) => (ts.getModifiers(fn) ?? []).some(modifier => modifier.kind === ts.SyntaxKind.AsyncKeyword);
|
|
67
|
+
/**
|
|
68
|
+
* Positions where `await` is a syntax error even when an async function
|
|
69
|
+
* encloses them: parameter initialisers, class fields, class static blocks,
|
|
70
|
+
* decorators, and `extends` clauses. The class body boundary is what matters,
|
|
71
|
+
* so a nested async method under the same class is still fine.
|
|
72
|
+
*/
|
|
73
|
+
const forbidsAwait = (node) => ts.isParameter(node) ||
|
|
74
|
+
ts.isPropertyDeclaration(node) ||
|
|
75
|
+
ts.isClassStaticBlockDeclaration(node) ||
|
|
76
|
+
ts.isDecorator(node) ||
|
|
77
|
+
ts.isHeritageClause(node);
|
|
78
|
+
/**
|
|
79
|
+
* `await` is only valid directly inside an async function. A call inside a
|
|
80
|
+
* nested sync callback (`[0, 1].map(i => irisApp().getByTestId(...))`), at
|
|
81
|
+
* module top level, or in one of the {@link forbidsAwait} positions cannot be
|
|
82
|
+
* rewritten without changing the surrounding shape, which is the caller's
|
|
83
|
+
* decision.
|
|
84
|
+
*/
|
|
85
|
+
const isInsideAsyncFunction = (call) => {
|
|
86
|
+
let current = call.parent;
|
|
87
|
+
while (!ts.isSourceFile(current)) {
|
|
88
|
+
if (forbidsAwait(current))
|
|
89
|
+
return false;
|
|
90
|
+
if (isFunctionLike(current))
|
|
91
|
+
return isAsync(current);
|
|
92
|
+
current = current.parent;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
};
|
|
96
|
+
const applyEdits = (content, edits) => {
|
|
97
|
+
// Later positions first, so earlier positions stay valid while splicing.
|
|
98
|
+
// Edits are pushed outer-first (pre-order), and an outer call shares its
|
|
99
|
+
// start with the inner call it chains on (`x.irisApp().irisApp()`). The
|
|
100
|
+
// text inserted last at an offset ends up leftmost, so the inner edit is
|
|
101
|
+
// applied first and the outer `await` lands outside it.
|
|
102
|
+
const ordered = edits
|
|
103
|
+
.map((edit, index) => ({ edit, index }))
|
|
104
|
+
.sort((a, b) => b.edit.start - a.edit.start || b.index - a.index);
|
|
105
|
+
let updated = content;
|
|
106
|
+
for (const { edit: { start, end, text }, } of ordered) {
|
|
107
|
+
updated = updated.slice(0, start) + text + updated.slice(end);
|
|
108
|
+
}
|
|
109
|
+
return updated;
|
|
110
|
+
};
|
|
111
|
+
const isFrameLocatorReference = (type) => ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName) && type.typeName.text === FRAME_LOCATOR;
|
|
112
|
+
/**
|
|
113
|
+
* `() => FrameLocator` -> `() => Promise<FrameLocator>`. A function type whose
|
|
114
|
+
* return is anything else (already a `Promise`, a union, a different type) is
|
|
115
|
+
* not the fixture's old shape and is left alone.
|
|
116
|
+
*/
|
|
117
|
+
const widenFrameLocatorReturn = (type, sourceFile) => {
|
|
118
|
+
if (type === undefined || !ts.isFunctionTypeNode(type) || !isFrameLocatorReference(type.type))
|
|
119
|
+
return null;
|
|
120
|
+
return { start: type.type.getStart(sourceFile), end: type.type.getEnd(), text: `Promise<${FRAME_LOCATOR}>` };
|
|
121
|
+
};
|
|
122
|
+
/** A parameter, property signature, or property declaration named `irisApp` with a type annotation. */
|
|
123
|
+
const isIrisAppDeclaration = (node) => (ts.isParameter(node) || ts.isPropertySignature(node) || ts.isPropertyDeclaration(node)) &&
|
|
124
|
+
ts.isIdentifier(node.name) &&
|
|
125
|
+
node.name.text === FIXTURE_NAME &&
|
|
126
|
+
node.type !== undefined;
|
|
127
|
+
const awaitIrisAppCalls = (filePath, content) => {
|
|
128
|
+
const sourceFile = parse(filePath, content);
|
|
129
|
+
const edits = [];
|
|
130
|
+
const syncCallLines = [];
|
|
131
|
+
/** Local type aliases used as the type of an `irisApp` declaration, e.g. `irisApp: IrisAppFn`. */
|
|
132
|
+
const irisAppAliasNames = new Set();
|
|
133
|
+
const typeAliases = [];
|
|
134
|
+
const visit = (node) => {
|
|
135
|
+
if (isIrisAppCall(node) && !isAlreadyAwaited(node)) {
|
|
136
|
+
if (isInsideAsyncFunction(node)) {
|
|
137
|
+
const start = node.getStart(sourceFile);
|
|
138
|
+
if (needsParentheses(node)) {
|
|
139
|
+
edits.push({ start, end: start, text: "(await " }, { start: node.getEnd(), end: node.getEnd(), text: ")" });
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
edits.push({ start, end: start, text: "await " });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
syncCallLines.push(sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else if (isIrisAppDeclaration(node)) {
|
|
150
|
+
const widened = widenFrameLocatorReturn(node.type, sourceFile);
|
|
151
|
+
if (widened !== null) {
|
|
152
|
+
edits.push(widened);
|
|
153
|
+
}
|
|
154
|
+
else if (ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName)) {
|
|
155
|
+
irisAppAliasNames.add(node.type.typeName.text);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else if (ts.isTypeAliasDeclaration(node)) {
|
|
159
|
+
typeAliases.push(node);
|
|
160
|
+
}
|
|
161
|
+
ts.forEachChild(node, visit);
|
|
162
|
+
};
|
|
163
|
+
visit(sourceFile);
|
|
164
|
+
for (const alias of typeAliases) {
|
|
165
|
+
if (!irisAppAliasNames.has(alias.name.text))
|
|
166
|
+
continue;
|
|
167
|
+
const widened = widenFrameLocatorReturn(alias.type, sourceFile);
|
|
168
|
+
if (widened !== null)
|
|
169
|
+
edits.push(widened);
|
|
170
|
+
}
|
|
171
|
+
return { content: edits.length === 0 ? content : applyEdits(content, edits), syncCallLines };
|
|
172
|
+
};
|
|
173
|
+
exports.awaitIrisAppCalls = awaitIrisAppCalls;
|
|
174
|
+
/**
|
|
175
|
+
* `@trackunit/iris-app-playwright` 1.0.0: the `irisApp` fixture resolves to
|
|
176
|
+
* `Promise<FrameLocator>` in every environment, so a feature-branch host can
|
|
177
|
+
* wait for the iframe before any page assertion. Every `irisApp(...)` call
|
|
178
|
+
* therefore needs an `await`.
|
|
179
|
+
*
|
|
180
|
+
* Rewrites `irisApp(...)` and `<x>.irisApp(...)` calls inside async functions
|
|
181
|
+
* to `await irisApp(...)`, parenthesised when the call is the receiver of a
|
|
182
|
+
* member access or call. Calls that are already awaited are left alone. Calls
|
|
183
|
+
* that are not inside an async function are reported with `file:line` and left
|
|
184
|
+
* for manual review, because adding `await` there would be a syntax error.
|
|
185
|
+
*
|
|
186
|
+
* Also widens the old fixture shape in local types: a parameter or property
|
|
187
|
+
* named `irisApp` typed `(...) => FrameLocator`, and any same-file type alias
|
|
188
|
+
* such a declaration uses, becomes `(...) => Promise<FrameLocator>`.
|
|
189
|
+
*/
|
|
190
|
+
const awaitIrisApp = (tree) => {
|
|
191
|
+
let touched = 0;
|
|
192
|
+
const manualReview = [];
|
|
193
|
+
(0, devkit_1.visitNotIgnoredFiles)(tree, "/", filePath => {
|
|
194
|
+
if (!isSourceFile(filePath) || isUnderNodeModulesOrDist(filePath))
|
|
195
|
+
return;
|
|
196
|
+
const content = tree.read(filePath, "utf-8");
|
|
197
|
+
if (content === null || !content.includes(FIXTURE_NAME))
|
|
198
|
+
return;
|
|
199
|
+
const result = (0, exports.awaitIrisAppCalls)(filePath, content);
|
|
200
|
+
if (result.content !== content) {
|
|
201
|
+
tree.write(filePath, result.content);
|
|
202
|
+
touched += 1;
|
|
203
|
+
}
|
|
204
|
+
for (const line of result.syncCallLines) {
|
|
205
|
+
manualReview.push(`${filePath}:${line}`);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
if (touched === 0) {
|
|
209
|
+
devkit_1.logger.info(` ${MIGRATION_NAME}: no files changed`);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
devkit_1.logger.info(` ${MIGRATION_NAME}: updated ${touched} file(s)`);
|
|
213
|
+
}
|
|
214
|
+
for (const location of manualReview) {
|
|
215
|
+
devkit_1.logger.warn(` ${MIGRATION_NAME}: ${location} calls irisApp() but is not inside an async function. Make the enclosing function async and await the call, or hoist \`const app = await irisApp();\` out of it.`);
|
|
216
|
+
}
|
|
217
|
+
if (touched > 0 || manualReview.length > 0) {
|
|
218
|
+
devkit_1.logger.info(` ${MIGRATION_NAME}: if you override the irisApp fixture, return Promise<FrameLocator> (or use createIrisApp from @trackunit/iris-app-playwright/support) so it matches IrisAppFixtures["irisApp"].`);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
exports.awaitIrisApp = awaitIrisApp;
|
|
222
|
+
exports.default = exports.awaitIrisApp;
|
|
223
|
+
//# sourceMappingURL=await-iris-app.js.map
|
package/migrations.json
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
{
|
|
2
|
-
"generators": {
|
|
2
|
+
"generators": {
|
|
3
|
+
"v1-0-0-await-iris-app": {
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "irisApp() now resolves to Promise<FrameLocator> in every environment. Rewrite irisApp(...) calls inside async functions to await irisApp(...), parenthesised when the call is the receiver of a member access, and report calls outside async functions for manual review.",
|
|
6
|
+
"implementation": "./migrations/v1-0-0/await-iris-app"
|
|
7
|
+
}
|
|
8
|
+
}
|
|
3
9
|
}
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import { expect } from "@playwright/test";
|
|
|
2
2
|
export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & import("./login.fixture").TrackunitBaseFixtures & import("./irisApp.fixture").IrisAppFixtures & import("./featureFlags.fixture").FeatureFlagFixtures & import("./localDevMode.fixture").LocalDevModeFixtures, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions & import("./login.fixture").LoginCacheFixtures>;
|
|
3
3
|
export { expect };
|
|
4
4
|
export type { FeatureFlag, FeatureFlagFixtures } from "./featureFlags.fixture";
|
|
5
|
-
export
|
|
5
|
+
export { createIrisApp } from "./irisApp.fixture";
|
|
6
|
+
export type { CreateIrisAppOptions, IrisAppFixtures, IrisAppOptions, StorybookPreviewOptions } from "./irisApp.fixture";
|
|
6
7
|
export type { LocalDevModeFixtures } from "./localDevMode.fixture";
|
|
7
8
|
export type { AuthCredentials, LoginOptions, TrackunitBaseFixtures } from "./login.fixture";
|
package/src/fixtures/baseTest.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.expect = exports.test = void 0;
|
|
3
|
+
exports.createIrisApp = exports.expect = exports.test = void 0;
|
|
4
4
|
const test_1 = require("@playwright/test");
|
|
5
5
|
Object.defineProperty(exports, "expect", { enumerable: true, get: function () { return test_1.expect; } });
|
|
6
6
|
const featureFlags_fixture_1 = require("./featureFlags.fixture");
|
|
@@ -9,4 +9,6 @@ const irisApp_fixture_1 = require("./irisApp.fixture");
|
|
|
9
9
|
const localDevMode_fixture_1 = require("./localDevMode.fixture");
|
|
10
10
|
const login_fixture_1 = require("./login.fixture");
|
|
11
11
|
exports.test = (0, test_1.mergeTests)(harRecording_fixture_1.test, login_fixture_1.test, irisApp_fixture_1.test, featureFlags_fixture_1.test, localDevMode_fixture_1.test);
|
|
12
|
+
var irisApp_fixture_2 = require("./irisApp.fixture");
|
|
13
|
+
Object.defineProperty(exports, "createIrisApp", { enumerable: true, get: function () { return irisApp_fixture_2.createIrisApp; } });
|
|
12
14
|
//# sourceMappingURL=baseTest.js.map
|
|
@@ -6,10 +6,60 @@ export interface StorybookPreviewOptions {
|
|
|
6
6
|
/** Storybook preview iframe element id. Defaults to `storybook-preview-iframe`. */
|
|
7
7
|
iframeId?: string;
|
|
8
8
|
}
|
|
9
|
+
type IrisAppAttachWait = {
|
|
10
|
+
waitFor: (options?: {
|
|
11
|
+
state?: "attached";
|
|
12
|
+
timeout?: number;
|
|
13
|
+
}) => Promise<void>;
|
|
14
|
+
first?: () => IrisAppAttachWait;
|
|
15
|
+
};
|
|
16
|
+
type IrisAppFramePage = {
|
|
17
|
+
locator: (selector: string) => IrisAppAttachWait;
|
|
18
|
+
frameLocator: (selector: string) => FrameLocator;
|
|
19
|
+
};
|
|
20
|
+
type IrisAppTestTimeout = {
|
|
21
|
+
timeout: number;
|
|
22
|
+
setTimeout: (timeout: number) => void;
|
|
23
|
+
};
|
|
9
24
|
export interface IrisAppFixtures {
|
|
10
|
-
/**
|
|
11
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Resolves to the Iris app frame. On a feature-branch host, waits until the
|
|
27
|
+
* requested iframe is attached first. A missing iframe rejects with
|
|
28
|
+
* {@link HostNeverBecameReadyError} (`host never became ready`) before the
|
|
29
|
+
* locator is returned. Other hosts resolve immediately, without waiting.
|
|
30
|
+
* Callers await this in every environment. Defaults to `data-testid="app-iframe"`
|
|
31
|
+
* and the first match, because a page can render more than one app iframe.
|
|
32
|
+
*/
|
|
33
|
+
irisApp: (options?: IrisAppOptions) => Promise<FrameLocator>;
|
|
12
34
|
/** Returns a FrameLocator for the Storybook preview iframe. Defaults to `id="storybook-preview-iframe"`. */
|
|
13
35
|
storybookPreview: (options?: StorybookPreviewOptions) => FrameLocator;
|
|
14
36
|
}
|
|
37
|
+
export type CreateIrisAppOptions = {
|
|
38
|
+
/** When false, do not call `.first()`. Default is true. */
|
|
39
|
+
first?: boolean;
|
|
40
|
+
/** Replaces the default `iframe[data-testid="..."]` selector. */
|
|
41
|
+
selector?: (testId?: string) => string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Builds the `irisApp` accessor.
|
|
45
|
+
*
|
|
46
|
+
* Root cause (GLU-2633): `page.frameLocator` does not wait for the iframe, and
|
|
47
|
+
* `locator.waitFor` rejects with Playwright's `TimeoutError` when the
|
|
48
|
+
* feature-branch iframe never attaches. The job then reports that wait
|
|
49
|
+
* timeout, or the caller's later page assertion, instead of the host never
|
|
50
|
+
* becoming ready. The accessor waits until the requested iframe is attached.
|
|
51
|
+
* Only that Playwright timeout is rethrown as {@link HostNeverBecameReadyError}
|
|
52
|
+
* before the locator is returned. Any other attach failure is rethrown
|
|
53
|
+
* unchanged. Once the iframe is attached, the locator is returned and later
|
|
54
|
+
* page assertions belong to the caller. A host that is not a feature branch
|
|
55
|
+
* returns the locator immediately and does not extend the test timeout.
|
|
56
|
+
* Playwright's own test timeout would otherwise expire before this wait, so
|
|
57
|
+
* the running test's timeout grows by {@link MAIN_MENU_READY_TIMEOUT_MS} once
|
|
58
|
+
* per test, before the first feature-branch wait. Later `irisApp()` calls in
|
|
59
|
+
* that test do not add the budget again. An unlimited timeout (`0`) is left
|
|
60
|
+
* untouched. The accessor is always a promise, so `const app = await irisApp()`
|
|
61
|
+
* and `await irisApp().then(...)` are the same shape when the gate is off.
|
|
62
|
+
*/
|
|
63
|
+
export declare const createIrisApp: (page: IrisAppFramePage, testInfo?: IrisAppTestTimeout, options?: CreateIrisAppOptions) => IrisAppFixtures["irisApp"];
|
|
15
64
|
export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & IrisAppFixtures, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>;
|
|
65
|
+
export {};
|
|
@@ -1,10 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.test = void 0;
|
|
3
|
+
exports.test = exports.createIrisApp = void 0;
|
|
4
4
|
const test_1 = require("@playwright/test");
|
|
5
|
+
const hostReadiness_1 = require("./hostReadiness");
|
|
6
|
+
const login_fixture_1 = require("./login.fixture");
|
|
7
|
+
const irisAppFrameSelector = (testId) => `iframe[data-testid="${testId ?? "app-iframe"}"]`;
|
|
8
|
+
const firstMatch = (value, useFirst) => useFirst && value.first !== undefined ? value.first() : value;
|
|
9
|
+
/**
|
|
10
|
+
* Builds the `irisApp` accessor.
|
|
11
|
+
*
|
|
12
|
+
* Root cause (GLU-2633): `page.frameLocator` does not wait for the iframe, and
|
|
13
|
+
* `locator.waitFor` rejects with Playwright's `TimeoutError` when the
|
|
14
|
+
* feature-branch iframe never attaches. The job then reports that wait
|
|
15
|
+
* timeout, or the caller's later page assertion, instead of the host never
|
|
16
|
+
* becoming ready. The accessor waits until the requested iframe is attached.
|
|
17
|
+
* Only that Playwright timeout is rethrown as {@link HostNeverBecameReadyError}
|
|
18
|
+
* before the locator is returned. Any other attach failure is rethrown
|
|
19
|
+
* unchanged. Once the iframe is attached, the locator is returned and later
|
|
20
|
+
* page assertions belong to the caller. A host that is not a feature branch
|
|
21
|
+
* returns the locator immediately and does not extend the test timeout.
|
|
22
|
+
* Playwright's own test timeout would otherwise expire before this wait, so
|
|
23
|
+
* the running test's timeout grows by {@link MAIN_MENU_READY_TIMEOUT_MS} once
|
|
24
|
+
* per test, before the first feature-branch wait. Later `irisApp()` calls in
|
|
25
|
+
* that test do not add the budget again. An unlimited timeout (`0`) is left
|
|
26
|
+
* untouched. The accessor is always a promise, so `const app = await irisApp()`
|
|
27
|
+
* and `await irisApp().then(...)` are the same shape when the gate is off.
|
|
28
|
+
*/
|
|
29
|
+
const createIrisApp = (page, testInfo, options) => {
|
|
30
|
+
const useFirst = options?.first !== false;
|
|
31
|
+
const selectorFor = options?.selector ?? irisAppFrameSelector;
|
|
32
|
+
let budgetReserved = false;
|
|
33
|
+
return async (irisOptions) => {
|
|
34
|
+
const selector = selectorFor(irisOptions?.testId);
|
|
35
|
+
const frame = () => firstMatch(page.frameLocator(selector), useFirst);
|
|
36
|
+
if (!(0, hostReadiness_1.isFeatureBranchHost)()) {
|
|
37
|
+
return frame();
|
|
38
|
+
}
|
|
39
|
+
if (!budgetReserved) {
|
|
40
|
+
(0, login_fixture_1.extendTestTimeout)(testInfo, login_fixture_1.MAIN_MENU_READY_TIMEOUT_MS);
|
|
41
|
+
budgetReserved = true;
|
|
42
|
+
}
|
|
43
|
+
return waitForAttachedIrisAppFrame(page, selector, useFirst);
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
exports.createIrisApp = createIrisApp;
|
|
47
|
+
const isPlaywrightTimeout = (error) => error instanceof test_1.errors.TimeoutError;
|
|
48
|
+
const waitForAttachedIrisAppFrame = async (page, selector, useFirst) => {
|
|
49
|
+
try {
|
|
50
|
+
await firstMatch(page.locator(selector), useFirst).waitFor({
|
|
51
|
+
state: "attached",
|
|
52
|
+
timeout: login_fixture_1.MAIN_MENU_READY_TIMEOUT_MS,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (isPlaywrightTimeout(error)) {
|
|
57
|
+
throw new hostReadiness_1.HostNeverBecameReadyError(error);
|
|
58
|
+
}
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
return firstMatch(page.frameLocator(selector), useFirst);
|
|
62
|
+
};
|
|
5
63
|
exports.test = test_1.test.extend({
|
|
6
|
-
irisApp: async ({ page }, provide) => {
|
|
7
|
-
await provide((
|
|
64
|
+
irisApp: async ({ page }, provide, testInfo) => {
|
|
65
|
+
await provide((0, exports.createIrisApp)(page, testInfo));
|
|
8
66
|
},
|
|
9
67
|
storybookPreview: async ({ page }, provide) => {
|
|
10
68
|
await provide((options) => page.frameLocator(`iframe[id="${options?.iframeId ?? "storybook-preview-iframe"}"]`));
|
package/src/generators/playwright-configuration/files/root/playwright/tests/app.spec.ts__tmpl__
CHANGED
|
@@ -8,7 +8,7 @@ describe("Sample E2E Test", () => {
|
|
|
8
8
|
// await expect(page.getByTestId("your-app-element")).toBeVisible();
|
|
9
9
|
|
|
10
10
|
// Example: Test Iris app integration
|
|
11
|
-
// const app = irisApp();
|
|
11
|
+
// const app = await irisApp();
|
|
12
12
|
// await expect(app.getByTestId("your-test-id")).toBeVisible();
|
|
13
13
|
|
|
14
14
|
await expect(page.locator("#host-layout-content")).toBeVisible();
|