playwright.config.ts 3.1 KB

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