playwright.config.ts 3.4 KB

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