playwright.config.ts 3.4 KB

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