Skip to content

Commit

Permalink
test(website-e2e): add playwright lighthouse audit
Browse files Browse the repository at this point in the history
test(website-e2e): add basic lighthouse audit
  • Loading branch information
MFarabi619 committed Dec 3, 2024
1 parent d34864d commit d825735
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 17 deletions.
20 changes: 11 additions & 9 deletions apps/website-e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const baseURL = process.env.BASE_URL || 'http://localhost:3000'
*/
export default defineConfig({
...nxE2EPreset(__filename, { testDir: './src' }),
fullyParallel: true,
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL,
Expand All @@ -29,26 +30,27 @@ export default defineConfig({
},
/* Run your local dev server before starting the tests */
webServer: {
command: 'pnpm nx dev website --verbose',
command: 'pnpm nx start website --verbose',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
cwd: workspaceRoot,
},
reporter: [['html']],
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},
// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

// Uncomment for mobile browsers support
/* {
Expand Down
8 changes: 0 additions & 8 deletions apps/website-e2e/src/example.spec.ts

This file was deleted.

60 changes: 60 additions & 0 deletions apps/website-e2e/src/website.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// import type { Browser } from 'playwright'
// import { chromium, expect, test } from '@playwright/test'
// import getPort from 'get-port'
// import { playAudit } from 'playwright-lighthouse'

// const lighthouseTest = test.extend<{ Page }, { port: number, browser: Browser }>({
// port: [
// async (use) => {
// // Assign a unique port for each playwright worker to support parallel tests
// const port = await getPort()
// await use(port)
// },
// { scope: 'worker' },
// ],

// browser: [
// async ({ port }, use) => {
// const browser = await chromium.launch({
// args: [`--remote-debugging-port=${port}`],
// })
// await use(browser)
// },
// { scope: 'worker' },
// ],
// })

// const thresholdsConfig = {
// 'performance': 90,
// 'accessibility': 90,
// 'best-practices': 90,
// 'seo': 90,
// // 'pwa': 50,
// }

// TODO: re-activate after website refactor (three.js/spline)
// lighthouseTest('should pass lighthouse audits', async ({ page, port }) => {
// await page.goto('/')

// await playAudit({
// page,
// port,
// thresholds: thresholdsConfig,
// reports: {
// formats: {
// // json: true, // defaults to false
// html: true, // defaults to false
// // csv: true, // defaults to false
// },
// name: `latest-report`, // defaults to `lighthouse-${new Date().getTime()}`
// directory: `${process.cwd()}../../../lighthouse-report`, // defaults to `${process.cwd()}/lighthouse`
// },
// })
// })

// test('has title', async ({ page }) => {
// await page.goto('/')

// // Expect h1 to contain a substring.
// expect(await page.locator('h1').textContent()).toContain('Sponsorship')
// })

0 comments on commit d825735

Please sign in to comment.