👷 Improve Playwright CI speed: sharding (paralel runs), run in Docker to use cache, use env vars (#1405)

This commit is contained in:
Sebastián Ramírez
2024-10-25 23:56:34 +02:00
committed by GitHub
parent d3d370cad0
commit e684f3c8d6
11 changed files with 121 additions and 27 deletions

View File

@@ -1 +1,2 @@
VITE_API_URL=http://localhost:8000
MAILCATCHER_HOST=http://localhost:1080

View File

@@ -0,0 +1,13 @@
FROM node:20
WORKDIR /app
COPY package*.json /app/
RUN npm install
RUN npx -y playwright install --with-deps
COPY ./ /app/
ARG VITE_API_URL=${VITE_API_URL}

View File

@@ -1,11 +1,10 @@
import { defineConfig, devices } from '@playwright/test';
import 'dotenv/config'
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();
/**
* See https://playwright.dev/docs/test-configuration.
@@ -21,7 +20,7 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
reporter: process.env.CI ? 'blob' : 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */

View File

@@ -49,7 +49,7 @@ function UsersTable() {
const { page } = Route.useSearch()
const navigate = useNavigate({ from: Route.fullPath })
const setPage = (page: number) =>
navigate({ search: (prev) => ({ ...prev, page }) })
navigate({ search: (prev: {[key: string]: string}) => ({ ...prev, page }) })
const {
data: users,

View File

@@ -45,7 +45,7 @@ function ItemsTable() {
const { page } = Route.useSearch()
const navigate = useNavigate({ from: Route.fullPath })
const setPage = (page: number) =>
navigate({ search: (prev) => ({ ...prev, page }) })
navigate({ search: (prev: {[key: string]: string}) => ({ ...prev, page }) })
const {
data: items,

View File

@@ -50,7 +50,9 @@ test("User can reset password successfully using the link", async ({
timeout: 5000,
})
await page.goto(`http://localhost:1080/messages/${emailData.id}.html`)
await page.goto(
`${process.env.MAILCATCHER_HOST}/messages/${emailData.id}.html`,
)
const selector = 'a[href*="/reset-password?token="]'
@@ -103,7 +105,9 @@ test("Weak new password validation", async ({ page, request }) => {
timeout: 5000,
})
await page.goto(`http://localhost:1080/messages/${emailData.id}.html`)
await page.goto(
`${process.env.MAILCATCHER_HOST}/messages/${emailData.id}.html`,
)
const selector = 'a[href*="/reset-password?token="]'
let url = await page.getAttribute(selector, "href")

View File

@@ -10,7 +10,7 @@ async function findEmail({
request,
filter,
}: { request: APIRequestContext; filter?: (email: Email) => boolean }) {
const response = await request.get("http://localhost:1080/messages")
const response = await request.get(`${process.env.MAILCATCHER_HOST}/messages`)
let emails = await response.json()

View File

@@ -20,6 +20,6 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src", "*.ts", "**/*.ts"],
"include": ["src/**/*.ts", "tests/**/*.ts", "playwright.config.ts"],
"references": [{ "path": "./tsconfig.node.json" }]
}