forked from calcom/cal.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playwright.config.ts
318 lines (287 loc) · 9.72 KB
/
playwright.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import type { Frame, PlaywrightTestConfig } from "@playwright/test";
import { devices, expect } from "@playwright/test";
import dotEnv from "dotenv";
import * as os from "os";
import * as path from "path";
import { WEBAPP_URL } from "@calcom/lib/constants";
dotEnv.config({ path: ".env" });
const outputDir = path.join(__dirname, "test-results");
// Dev Server on local can be slow to start up and process requests. So, keep timeouts really high on local, so that tests run reliably locally
// So, if not in CI, keep the timers high, if the test is stuck somewhere and there is unnecessary wait developer can see in browser that it's stuck
const DEFAULT_NAVIGATION_TIMEOUT = process.env.CI ? 30000 : 120000;
const DEFAULT_EXPECT_TIMEOUT = process.env.CI ? 30000 : 120000;
// Test Timeout can hit due to slow expect, slow navigation.
// So, it should me much higher than sum of expect and navigation timeouts as there can be many async expects and navigations in a single test
const DEFAULT_TEST_TIMEOUT = process.env.CI ? 60000 : 240000;
const headless = !!process.env.CI || !!process.env.PLAYWRIGHT_HEADLESS;
const IS_EMBED_TEST = process.argv.some((a) => a.startsWith("--project=@calcom/embed-core"));
const IS_EMBED_REACT_TEST = process.argv.some((a) => a.startsWith("--project=@calcom/embed-react"));
const webServer: PlaywrightTestConfig["webServer"] = [
{
command:
"NEXT_PUBLIC_IS_E2E=1 NODE_OPTIONS='--dns-result-order=ipv4first' yarn workspace @calcom/web start -p 3000",
port: 3000,
timeout: 60_000,
reuseExistingServer: !process.env.CI,
},
];
if (IS_EMBED_TEST) {
ensureAppServerIsReadyToServeEmbed(webServer[0]);
webServer.push({
command: "yarn workspace @calcom/embed-core dev",
port: 3100,
timeout: 60_000,
reuseExistingServer: !process.env.CI,
});
}
if (IS_EMBED_REACT_TEST) {
ensureAppServerIsReadyToServeEmbed(webServer[0]);
webServer.push({
command: "yarn workspace @calcom/embed-react dev",
port: 3101,
timeout: 60_000,
reuseExistingServer: !process.env.CI,
});
}
const DEFAULT_CHROMIUM = {
...devices["Desktop Chrome"],
timezoneId: "Europe/London",
storageState: {
cookies: [
{
url: WEBAPP_URL,
name: "calcom-timezone-dialog",
expires: -1,
value: "1",
},
],
},
locale: "en-US",
/** If navigation takes more than this, then something's wrong, let's fail fast. */
navigationTimeout: DEFAULT_NAVIGATION_TIMEOUT,
};
const config: PlaywrightTestConfig = {
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
// While debugging it should be focussed mode
// eslint-disable-next-line turbo/no-undeclared-env-vars
workers: process.env.PWDEBUG ? 1 : os.cpus().length,
timeout: DEFAULT_TEST_TIMEOUT,
maxFailures: headless ? 10 : undefined,
fullyParallel: true,
reporter: [
[process.env.CI ? "blob" : "list"],
["html", { outputFolder: "./test-results/reports/playwright-html-report", open: "never" }],
["junit", { outputFile: "./test-results/reports/results.xml" }],
],
outputDir: path.join(outputDir, "results"),
webServer,
use: {
baseURL: process.env.NEXT_PUBLIC_WEBAPP_URL,
locale: "en-US",
trace: "retain-on-failure",
headless,
// chromium-specific permissions - Chromium seems to be the only browser type that requires perms
contextOptions: {
permissions: ["clipboard-read", "clipboard-write"],
},
},
projects: [
{
name: "@calcom/web",
testDir: "./apps/web/playwright",
testMatch: /.*\.e2e\.tsx?/,
expect: {
timeout: DEFAULT_EXPECT_TIMEOUT,
},
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TS definitions for USE are wrong.
use: DEFAULT_CHROMIUM,
},
{
name: "@calcom/app-store",
testDir: "./packages/app-store/",
testMatch: /.*\.e2e\.tsx?/,
expect: {
timeout: DEFAULT_EXPECT_TIMEOUT,
},
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TS definitions for USE are wrong.
use: DEFAULT_CHROMIUM,
},
{
name: "@calcom/embed-core",
testDir: "./packages/embeds/embed-core/",
testMatch: /.*\.e2e\.tsx?/,
expect: {
timeout: DEFAULT_EXPECT_TIMEOUT,
},
use: {
...devices["Desktop Chrome"],
locale: "en-US",
baseURL: "http://localhost:3100/",
},
},
{
name: "@calcom/embed-react",
testDir: "./packages/embeds/embed-react/",
expect: {
timeout: DEFAULT_EXPECT_TIMEOUT,
},
testMatch: /.*\.e2e\.tsx?/,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TS definitions for USE are wrong.
use: {
...DEFAULT_CHROMIUM,
baseURL: "http://localhost:3101/",
},
},
{
name: "@calcom/embed-core--firefox",
testDir: "./packages/embeds/",
testMatch: /.*\.e2e\.tsx?/,
expect: {
timeout: DEFAULT_EXPECT_TIMEOUT,
},
use: { ...devices["Desktop Firefox"] },
},
{
name: "@calcom/embed-core--webkit",
testDir: "./packages/embeds/",
testMatch: /.*\.e2e\.tsx?/,
expect: {
timeout: DEFAULT_EXPECT_TIMEOUT,
},
use: { ...devices["Desktop Safari"] },
},
],
};
export type ExpectedUrlDetails = {
searchParams?: Record<string, string | string[]>;
pathname?: string;
origin?: string;
};
expect.extend({
async toBeEmbedCalLink(
iframe: Frame,
calNamespace: string,
//TODO: Move it to testUtil, so that it doesn't need to be passed
// eslint-disable-next-line
getActionFiredDetails: (a: { calNamespace: string; actionType: string }) => Promise<any>,
expectedUrlDetails: ExpectedUrlDetails = {},
isPrerendered?: boolean
) {
if (!iframe || !iframe.url) {
return {
pass: false,
message: () => `Expected to provide an iframe, got ${iframe}`,
};
}
const u = new URL(iframe.url());
const pathname = u.pathname;
const expectedPathname = `${expectedUrlDetails.pathname}/embed`;
if (expectedPathname && expectedPathname !== pathname) {
return {
pass: false,
message: () => `Expected pathname to be ${expectedPathname} but got ${pathname}`,
};
}
const origin = u.origin;
const expectedOrigin = expectedUrlDetails.origin;
if (expectedOrigin && expectedOrigin !== origin) {
return {
pass: false,
message: () => `Expected origin to be ${expectedOrigin} but got ${origin}`,
};
}
const searchParams = u.searchParams;
const expectedSearchParams = expectedUrlDetails.searchParams || {};
for (const [expectedKey, expectedValue] of Object.entries(expectedSearchParams)) {
const value = searchParams.get(expectedKey);
if (value !== expectedValue) {
return {
message: () => `${expectedKey} should have value ${expectedValue} but got value ${value}`,
pass: false,
};
}
}
const frameElement = await iframe.frameElement();
if (isPrerendered) {
if (await frameElement.isVisible()) {
return {
pass: false,
message: () => `Expected prerender iframe to be not visible`,
};
}
return {
pass: true,
message: () => `is prerendered`,
};
}
const iframeReadyEventDetail = await new Promise(async (resolve) => {
const iframeReadyCheckInterval = setInterval(async () => {
const iframeReadyEventDetail = await getActionFiredDetails({
calNamespace,
actionType: "linkReady",
});
if (iframeReadyEventDetail) {
clearInterval(iframeReadyCheckInterval);
resolve(iframeReadyEventDetail);
}
}, 500);
});
if (!(await frameElement.isVisible())) {
return {
pass: false,
message: () => `Expected iframe to be visible`,
};
}
//At this point we know that window.initialBodyVisibility would be set as DOM would already have been ready(because linkReady event can only fire after that)
const {
visibility: visibilityBefore,
background: backgroundBefore,
initialValuesSet,
} = await iframe.evaluate(() => {
return {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
visibility: window.initialBodyVisibility,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
background: window.initialBodyBackground,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
initialValuesSet: window.initialValuesSet,
};
});
expect(initialValuesSet).toBe(true);
expect(visibilityBefore).toBe("hidden");
expect(backgroundBefore).toBe("transparent");
const { visibility: visibilityAfter, background: backgroundAfter } = await iframe.evaluate(() => {
return {
visibility: document.body.style.visibility,
background: document.body.style.background,
};
});
expect(visibilityAfter).toBe("visible");
expect(backgroundAfter).toBe("transparent");
if (!iframeReadyEventDetail) {
return {
pass: false,
message: () => `Iframe not ready to communicate with parent`,
};
}
return {
pass: true,
message: () => `passed`,
};
},
});
export default config;
function ensureAppServerIsReadyToServeEmbed(webServer: { port?: number; url?: string }) {
// We should't depend on an embed dependency for App's tests. So, conditionally modify App webServer.
// Only one of port or url can be specified, so remove port.
delete webServer.port;
webServer.url = `${process.env.NEXT_PUBLIC_WEBAPP_URL}/embed/embed.js`;
console.log("Ensuring that /embed/embed.js is 200 before starting tests");
}