playwright.config.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import fs from 'node:fs';
  2. import path from 'node:path';
  3. import { defineConfig, devices, type Project } from '@playwright/test';
  4. const authFile = path.resolve(__dirname, './playwright/.auth/admin.json');
  5. // Use prepared auth state.
  6. const storageState = fs.existsSync(authFile) ? authFile : undefined;
  7. const supportedBrowsers = ['chromium', 'firefox', 'webkit'] as const;
  8. const projects: Array<Project> = supportedBrowsers.map((browser) => ({
  9. name: browser,
  10. use: { ...devices[`Desktop ${browser}`], storageState },
  11. testIgnore: /(10-installer|21-basic-features-for-guest)\/.*\.spec\.ts/,
  12. dependencies: ['setup', 'auth'],
  13. }));
  14. const projectsForGuestMode: Array<Project> = supportedBrowsers.map(
  15. (browser) => ({
  16. name: `${browser}/guest-mode`,
  17. use: { ...devices[`Desktop ${browser}`] }, // Do not use storageState
  18. testMatch: /21-basic-features-for-guest\/.*\.spec\.ts/,
  19. }),
  20. );
  21. /**
  22. * Read environment variables from file.
  23. * https://github.com/motdotla/dotenv
  24. */
  25. // require('dotenv').config();
  26. /**
  27. * See https://playwright.dev/docs/test-configuration.
  28. */
  29. export default defineConfig({
  30. expect: {
  31. timeout: 7 * 1000,
  32. },
  33. testDir: './playwright',
  34. outputDir: './playwright/output',
  35. /* Run tests in files in parallel */
  36. fullyParallel: true,
  37. /* Fail the build on CI if you accidentally left test.only in the source code. */
  38. forbidOnly: !!process.env.CI,
  39. /* Retry on CI only */
  40. retries: process.env.CI ? 2 : 0,
  41. /* Opt out of parallel tests on CI. */
  42. workers: process.env.CI ? 1 : undefined,
  43. /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  44. reporter: process.env.CI ? [['github'], ['blob']] : 'list',
  45. webServer: {
  46. command: 'pnpm run server',
  47. url: 'http://localhost:3000',
  48. reuseExistingServer: !process.env.CI,
  49. stdout: 'ignore',
  50. stderr: 'pipe',
  51. },
  52. /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  53. use: {
  54. /* Base URL to use in actions like `await page.goto('/')`. */
  55. baseURL: 'http://localhost:3000',
  56. /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
  57. trace: 'on-first-retry',
  58. viewport: { width: 1400, height: 1024 },
  59. screenshot: 'only-on-failure',
  60. },
  61. /* Configure projects for major browsers */
  62. projects: [
  63. // Setup project
  64. {
  65. name: 'setup',
  66. testMatch: /.*\.setup\.ts/,
  67. testIgnore: /auth\.setup\.ts/,
  68. },
  69. { name: 'auth', testMatch: /auth\.setup\.ts/ },
  70. {
  71. name: 'chromium/installer',
  72. use: { ...devices['Desktop Chrome'], storageState },
  73. testMatch: /10-installer\/.*\.spec\.ts/,
  74. dependencies: ['setup'],
  75. },
  76. ...projects,
  77. ...projectsForGuestMode,
  78. /* Test against mobile viewports. */
  79. // {
  80. // name: 'Mobile Chrome',
  81. // use: { ...devices['Pixel 5'] },
  82. // },
  83. // {
  84. // name: 'Mobile Safari',
  85. // use: { ...devices['iPhone 12'] },
  86. // },
  87. /* Test against branded browsers. */
  88. // {
  89. // name: 'Microsoft Edge',
  90. // use: { ...devices['Desktop Edge'], channel: 'msedge' },
  91. // },
  92. // {
  93. // name: 'Google Chrome',
  94. // use: { ...devices['Desktop Chrome'], channel: 'chrome' },
  95. // },
  96. ],
  97. });