playwright.config.ts 3.4 KB

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