E2E tests refactoring (#1318)
* Adds test todos * Can't seem to change locales * WIP playwright test refactoring * jest-playwright cleanup * Test fixes * Test fixes * More test fixes * WIP: Testing fixes * More test fixes * Removes unused files * Installs missing browsers for e2e * ts-node fixes * ts-check fixes * Type fixes * Fixes e2e * FFS * Renamex webhook snapshot * Fixes webhook cross-platform * Renamed webhook snapshot * Apply suggestions from code review Co-authored-by: Max Schmitt <[email protected]> * Removes kont dependency * Cleanup playwright options * Next.js cache optimizations on CI * Uses cache on e2e as well * Fixme is introducing side-effects Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Bailey Pumfleet <[email protected]> Co-authored-by: Max Schmitt <[email protected]>
This commit is contained in:
21 files changed
+521
-847
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { Browser, chromium } from "@playwright/test";
|
||||
|
||||
async function loginAsUser(username: string, browser: Browser) {
|
||||
const page = await browser.newPage();
|
||||
await page.goto("http://localhost:3000/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(
|
||||
username === "onboarding" ? "[data-testid=onboarding]" : "[data-testid=dashboard-shell]"
|
||||
);
|
||||
// Save signed-in state to '${username}StorageState.json'.
|
||||
await page.context().storageState({ path: `playwright/artifacts/${username}StorageState.json` });
|
||||
await page.context().close();
|
||||
}
|
||||
|
||||
async function globalSetup(/* config: FullConfig */) {
|
||||
const browser = await chromium.launch();
|
||||
await loginAsUser("onboarding", browser);
|
||||
// await loginAsUser("free-first-hidden", browser);
|
||||
await loginAsUser("pro", browser);
|
||||
// await loginAsUser("trial", browser);
|
||||
await loginAsUser("free", browser);
|
||||
// await loginAsUser("usa", browser);
|
||||
// await loginAsUser("teamfree", browser);
|
||||
// await loginAsUser("teampro", browser);
|
||||
await browser.close();
|
||||
}
|
||||
|
||||
export default globalSetup;
|
||||
@@ -1,87 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/ban-types */
|
||||
import { provider, Provider } from "kont";
|
||||
import { Page, Cookie } from "playwright";
|
||||
|
||||
/**
|
||||
* Context data that Login provder needs.
|
||||
*/
|
||||
export type Needs = {};
|
||||
|
||||
/**
|
||||
* Login provider's options.
|
||||
*/
|
||||
export type Params = {
|
||||
user: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Context data that Page provider contributes.
|
||||
*/
|
||||
export type Contributes = {
|
||||
page: Page;
|
||||
};
|
||||
|
||||
const cookieCache = new Map<string, Cookie[]>();
|
||||
/**
|
||||
* Creates a new context / "incognito tab" and logs in the specified user
|
||||
*/
|
||||
export function loginProvider(opts: {
|
||||
user: string;
|
||||
/**
|
||||
* Path to navigate to after login
|
||||
*/
|
||||
path?: string;
|
||||
/**
|
||||
* Selector to wait for to decide that the navigation is done
|
||||
*/
|
||||
waitForSelector?: string;
|
||||
}): Provider<Needs, Contributes> {
|
||||
return provider<Needs, Contributes>()
|
||||
.name("login")
|
||||
.before(async () => {
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
const cachedCookies = cookieCache.get(opts.user);
|
||||
if (cachedCookies) {
|
||||
await context.addCookies(cachedCookies);
|
||||
} else {
|
||||
await page.goto("http://localhost:3000/auth/login");
|
||||
// Click input[name="email"]
|
||||
await page.click('input[name="email"]');
|
||||
// Fill input[name="email"]
|
||||
await page.fill('input[name="email"]', `${opts.user}@example.com`);
|
||||
// Press Tab
|
||||
await page.press('input[name="email"]', "Tab");
|
||||
// Fill input[name="password"]
|
||||
await page.fill('input[name="password"]', opts.user);
|
||||
// Press Enter
|
||||
await page.press('input[name="password"]', "Enter");
|
||||
|
||||
await page.waitForNavigation({
|
||||
url(url) {
|
||||
return !url.pathname.startsWith("/auth");
|
||||
},
|
||||
});
|
||||
|
||||
const cookies = await context.cookies();
|
||||
cookieCache.set(opts.user, cookies);
|
||||
}
|
||||
|
||||
if (opts.path) {
|
||||
await page.goto(`http://localhost:3000${opts.path}`);
|
||||
}
|
||||
if (opts.waitForSelector) {
|
||||
await page.waitForSelector(opts.waitForSelector);
|
||||
}
|
||||
|
||||
return {
|
||||
page,
|
||||
context,
|
||||
};
|
||||
})
|
||||
.after(async (ctx) => {
|
||||
await ctx.page?.close();
|
||||
await ctx.context?.close();
|
||||
})
|
||||
.done();
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/ban-types */
|
||||
import { provider, Provider } from "kont";
|
||||
import { Page } from "playwright";
|
||||
|
||||
/**
|
||||
* Context data that Page provder needs.
|
||||
*/
|
||||
export type Needs = {};
|
||||
|
||||
/**
|
||||
* Page provider's options.
|
||||
*/
|
||||
export type Params = {
|
||||
user: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Context data that Page provider contributes.
|
||||
*/
|
||||
export type Contributes = {
|
||||
page: Page;
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new context / "incognito tab" and logs in the specified user
|
||||
*/
|
||||
export function pageProvider(opts: {
|
||||
/**
|
||||
* Path to navigate to
|
||||
*/
|
||||
path: string;
|
||||
}): Provider<Needs, Contributes> {
|
||||
return provider<Needs, Contributes>()
|
||||
.name("page")
|
||||
.before(async () => {
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
|
||||
await page.goto(`http://localhost:3000${opts.path}`);
|
||||
|
||||
return {
|
||||
page,
|
||||
context,
|
||||
};
|
||||
})
|
||||
.after(async (ctx) => {
|
||||
await ctx.page?.close();
|
||||
await ctx.context?.close();
|
||||
})
|
||||
.done();
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
import { test } from "@playwright/test";
|
||||
import { createServer, IncomingMessage, ServerResponse } from "http";
|
||||
|
||||
export function todo(title: string) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
test.skip(title, () => {});
|
||||
}
|
||||
|
||||
export function randomString(length = 12) {
|
||||
let result = "";
|
||||
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
Reference in new issue
Block a user