One playwright config to rule them all (#4072)
This commit is contained in:
1 parent
b09d727d3f
commit
d27b7ab2c4
60 files changed
+658
-970
No files matched your search
@@ -1,19 +0,0 @@
|
||||
import { Page } from "@playwright/test";
|
||||
|
||||
export async function loginAsUser(username: string, page: Page) {
|
||||
// Skip if file exists
|
||||
await page.goto(`${process.env.PLAYWRIGHT_TEST_BASE_URL}/auth/login`);
|
||||
// Click input[name="email"]
|
||||
await page.click('input[name="email"]');
|
||||
// Fill input[name="email"]
|
||||
await page.fill('input[name="email"]', `${username}@example.com`);
|
||||
// Press Tab
|
||||
await page.press('input[name="email"]', "Tab");
|
||||
// Fill input[name="password"]
|
||||
await page.fill('input[name="password"]', username);
|
||||
// Press Enter
|
||||
await page.press('input[name="password"]', "Enter");
|
||||
await page.waitForSelector("[data-testid=dashboard-shell]");
|
||||
// Save signed-in state to '${username}StorageState.json'.
|
||||
await page.context().storageState({ path: `playwright/artifacts/${username}StorageState.json` });
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
import { PlaywrightTestConfig, devices } from "@playwright/test";
|
||||
import { config as dotEnvConfig } from "dotenv";
|
||||
import * as path from "path";
|
||||
|
||||
// TODO: May be derive it automatically, so that moving the file to another location doesn't require changing the code
|
||||
dotEnvConfig({ path: "../../../../../.env" });
|
||||
const DEFAULT_NAVIGATION_TIMEOUT = 15000;
|
||||
|
||||
// Paths are relative to main playwright config.
|
||||
const outputDir = path.join("../results");
|
||||
const testDir = path.join("../tests");
|
||||
|
||||
// Quick Mode has no retries to fail fast and quickly re-iterate
|
||||
// Also, it runs the tests only one browser for the same reason
|
||||
const quickMode = process.env.QUICK === "true";
|
||||
const CI = process.env.CI;
|
||||
export const config: PlaywrightTestConfig = {
|
||||
forbidOnly: !!CI,
|
||||
retries: quickMode && !CI ? 0 : 1,
|
||||
workers: 1,
|
||||
timeout: 60_000,
|
||||
reporter: [
|
||||
[CI ? "github" : "list"],
|
||||
[
|
||||
"html",
|
||||
{
|
||||
outputFolder: path.join(process.cwd(), "playwright", "reports", "playwright-html-report"),
|
||||
open: "never",
|
||||
},
|
||||
],
|
||||
["junit", { outputFile: path.join(process.cwd(), "playwright", "reports", "results.xml") }],
|
||||
],
|
||||
outputDir,
|
||||
webServer: {
|
||||
command: "NEXT_PUBLIC_IS_E2E=1 yarn workspace @calcom/web start -p 3000",
|
||||
port: 3000,
|
||||
timeout: 60_000,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
},
|
||||
use: {
|
||||
baseURL: "http://localhost:3000",
|
||||
locale: "en-US",
|
||||
trace: "retain-on-failure",
|
||||
headless: !!process.env.CI || !!process.env.PLAYWRIGHT_HEADLESS,
|
||||
},
|
||||
projects: [
|
||||
{
|
||||
name: "chromium",
|
||||
testDir,
|
||||
use: {
|
||||
...devices["Desktop Chrome"],
|
||||
/** If navigation takes more than this, then something's wrong, let's fail fast. */
|
||||
navigationTimeout: DEFAULT_NAVIGATION_TIMEOUT,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
export * from "../../../../apps/web/playwright/lib/testUtils";
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
getCloseComCustomActivityTypeFieldsIds,
|
||||
getCloseComLeadId,
|
||||
} from "@calcom/lib/CloseComeUtils";
|
||||
import { CalendarEvent } from "@calcom/types/Calendar";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
jest.mock("@calcom/lib/CloseCom", () => ({
|
||||
default: class {
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
"version": "0.0.0",
|
||||
"main": "./index.ts",
|
||||
"description": "It would allow a booker to connect with the right person or choose the right event, faster. It would work by taking inputs from the booker and using that data to route to the correct booker/event as configured by Cal user ",
|
||||
"scripts": {
|
||||
"app-e2e": "yarn playwright test --config=playwright/config/playwright.config.ts",
|
||||
"app-e2e-quick": "QUICK=true yarn app-e2e"
|
||||
},
|
||||
"dependencies": {
|
||||
"@calcom/lib": "*",
|
||||
"dotenv": "^16.0.1",
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
import { Page, chromium } from "@playwright/test";
|
||||
|
||||
// TODO: Import it in _playwright/config/globalSetup.ts and export it from there.
|
||||
import { loginAsUser } from "@calcom/app-store/_apps-playwright/config/globalSetup";
|
||||
import { hashPassword } from "@calcom/lib/auth";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
async function installApp(appName: string, redirectUrl: string, page: Page) {
|
||||
await page.goto(`${process.env.PLAYWRIGHT_TEST_BASE_URL}/apps/${appName}`);
|
||||
await page.click('[data-testid="install-app-button"]');
|
||||
await page.waitForNavigation({
|
||||
url: (url) => {
|
||||
return url.pathname == redirectUrl;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function createUser(userName: string) {
|
||||
const email = `${userName}@example.com`;
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
username: userName,
|
||||
email,
|
||||
completedOnboarding: true,
|
||||
password: await hashPassword(userName),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function globalSetup(/* config: FullConfig */) {
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
const appName = "routing_forms";
|
||||
const userName = `${appName}-e2e-${Math.random()}`;
|
||||
process.env.APP_USER_NAME = userName;
|
||||
await createUser(userName);
|
||||
await loginAsUser(userName, page);
|
||||
await installApp(appName, `/apps/${appName}/forms`, page);
|
||||
page.context().close();
|
||||
}
|
||||
|
||||
export default globalSetup;
|
||||
@@ -1,18 +0,0 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
async function deleteUser(userName: string) {
|
||||
await prisma.user.deleteMany({
|
||||
where: {
|
||||
AND: {
|
||||
username: {
|
||||
contains: userName,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
async function globalTeardown(/* config: FullConfig */) {
|
||||
await deleteUser("routing_forms-e2e");
|
||||
}
|
||||
|
||||
export default globalTeardown;
|
||||
@@ -1,12 +0,0 @@
|
||||
import { expect, Config } from "@playwright/test";
|
||||
|
||||
import { config as baseConfig } from "@calcom/app-store/_apps-playwright/config/playwright.config";
|
||||
|
||||
const config: Config = {
|
||||
...baseConfig,
|
||||
globalSetup: require.resolve("./globalSetup"),
|
||||
globalTeardown: require.resolve("./globalTeardown"),
|
||||
};
|
||||
|
||||
expect.extend({});
|
||||
export default config;
|
||||
@@ -1,5 +0,0 @@
|
||||
import { test as base } from "@playwright/test";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
interface Fixtures {}
|
||||
export const test = base.extend<Fixtures>({});
|
||||
@@ -1,20 +0,0 @@
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
export * from "@calcom/app-store/_apps-playwright/lib/testUtils";
|
||||
export async function cleanUpForms() {
|
||||
await prisma.app_RoutingForms_Form.deleteMany({
|
||||
where: {
|
||||
user: {
|
||||
username: process.env.APP_USER_NAME,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function cleanUpSeededForm(formId: string) {
|
||||
return await prisma.app_RoutingForms_FormResponse.deleteMany({
|
||||
where: {
|
||||
formId,
|
||||
},
|
||||
});
|
||||
}
|
||||
+17
-17
@@ -1,9 +1,7 @@
|
||||
import { expect, Page } from "@playwright/test";
|
||||
|
||||
import { seededForm } from "@calcom/prisma/seed-app-store";
|
||||
|
||||
import { test } from "../fixtures/fixtures";
|
||||
import { cleanUpForms, cleanUpSeededForm } from "../lib/testUtils";
|
||||
import { test } from "@calcom/web/playwright/lib/fixtures";
|
||||
|
||||
async function gotoRoutingLink(page: Page, formId: string) {
|
||||
await page.goto(`/forms/${formId}`);
|
||||
@@ -69,12 +67,24 @@ async function fillForm(
|
||||
};
|
||||
}
|
||||
|
||||
test.use({ storageState: `playwright/artifacts/${process.env.APP_USER_NAME}StorageState.json` });
|
||||
test.describe("Routing Forms", () => {
|
||||
test("should be able to add a new form and view it", async ({ page }) => {
|
||||
page.goto("/");
|
||||
test.beforeEach(async ({ page, users }) => {
|
||||
const user = await users.create({ username: "routing_forms" });
|
||||
await user.login();
|
||||
// Install app
|
||||
await page.goto(`/apps/routing_forms`);
|
||||
await page.click('[data-testid="install-app-button"]');
|
||||
await page.waitForNavigation({
|
||||
url: (url) => url.pathname === `/apps/routing_forms/forms`,
|
||||
});
|
||||
});
|
||||
|
||||
await page.click('[href="/apps/routing_forms/forms"]');
|
||||
test.afterEach(async ({ users }) => {
|
||||
// This also delete forms on cascade
|
||||
await users.deleteAll();
|
||||
});
|
||||
|
||||
test("should be able to add a new form and view it", async ({ page }) => {
|
||||
await page.waitForSelector('[data-testid="empty-screen"]');
|
||||
|
||||
const formId = await addForm(page);
|
||||
@@ -98,8 +108,6 @@ test.describe("Routing Forms", () => {
|
||||
});
|
||||
|
||||
test("should be able to edit the form", async ({ page }) => {
|
||||
await page.goto("/apps/routing_forms/forms");
|
||||
|
||||
await addForm(page);
|
||||
const description = "Test Description";
|
||||
|
||||
@@ -218,12 +226,4 @@ test.describe("Routing Forms", () => {
|
||||
expect(await page.locator('button[type="submit"][disabled]').count()).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
test.afterAll(() => {
|
||||
cleanUpForms();
|
||||
});
|
||||
|
||||
test.afterEach(() => {
|
||||
cleanUpSeededForm(seededForm.id);
|
||||
});
|
||||
});
|
||||
+4
-3
@@ -1,7 +1,8 @@
|
||||
import { expect, Frame } from "@playwright/test";
|
||||
import { expect } from "@playwright/test";
|
||||
|
||||
import { test } from "../fixtures/fixtures";
|
||||
import { todo, getEmbedIframe, bookFirstEvent, deleteAllBookingsByEmail } from "../lib/testUtils";
|
||||
import { test } from "@calcom/web/playwright/lib/fixtures";
|
||||
|
||||
import { bookFirstEvent, deleteAllBookingsByEmail, getEmbedIframe, todo } from "../lib/testUtils";
|
||||
|
||||
test("Inline Iframe - Configured with Dark Theme", async ({
|
||||
page,
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import { expect } from "@playwright/test";
|
||||
|
||||
import { test } from "../fixtures/fixtures";
|
||||
import { test } from "@calcom/web/playwright/lib/fixtures";
|
||||
|
||||
test("Preview - embed-core should load", async ({ page }) => {
|
||||
await page.goto("http://localhost:3000/embed/preview.html");
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CalendarEvent } from "@calcom/types/Calendar";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
|
||||
import CloseCom, {
|
||||
CloseComCustomActivityCreate,
|
||||
|
||||
Reference in new issue
Block a user