Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

75 lignes
2.5 KiB

  1. import { defineConfig, devices } from '@playwright/test'
  2. import fs from 'node:fs'
  3. import path from 'node:path'
  4. const loadLocalEnvironment = () => {
  5. const filename = process.env.E2E_ENV_FILE?.trim() || path.resolve('.env')
  6. if (!fs.existsSync(filename)) return
  7. for (const line of fs.readFileSync(filename, 'utf8').split(/\r?\n/)) {
  8. const match = line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/)
  9. if (!match || match[1]!.startsWith('#') || process.env[match[1]!]) continue
  10. const raw = match[2]!
  11. process.env[match[1]!] = raw.length >= 2 && ((raw.startsWith('"') && raw.endsWith('"')) || (raw.startsWith("'") && raw.endsWith("'")))
  12. ? raw.slice(1, -1)
  13. : raw
  14. }
  15. }
  16. loadLocalEnvironment()
  17. const rawApplicationBaseUrl = process.env.BASE_URL?.trim() || 'http://127.0.0.1:6180'
  18. let applicationUrl: URL
  19. try {
  20. applicationUrl = new URL(rawApplicationBaseUrl)
  21. } catch {
  22. throw new Error('BASE_URL must be an absolute HTTP(S) URL')
  23. }
  24. if (!['http:', 'https:'].includes(applicationUrl.protocol) || applicationUrl.username || applicationUrl.password) {
  25. throw new Error('BASE_URL must be an HTTP(S) URL without embedded credentials')
  26. }
  27. const applicationLoopbackHosts = new Set(['127.0.0.1', 'localhost', '::1', '[::1]'])
  28. if (
  29. !applicationLoopbackHosts.has(applicationUrl.hostname.toLowerCase())
  30. && applicationUrl.protocol !== 'https:'
  31. && process.env.E2E_ALLOW_INSECURE_REMOTE !== '1'
  32. ) {
  33. throw new Error('Remote BASE_URL must use HTTPS unless E2E_ALLOW_INSECURE_REMOTE=1 explicitly accepts the risk')
  34. }
  35. const baseURL = applicationUrl.toString().replace(/\/$/, '')
  36. export default defineConfig({
  37. testDir: './tests',
  38. outputDir: './artifacts/test-results',
  39. fullyParallel: false,
  40. workers: 1,
  41. retries: process.env.CI ? 1 : 0,
  42. timeout: 60_000,
  43. expect: {
  44. timeout: 10_000,
  45. },
  46. reporter: [
  47. ['list'],
  48. ['html', { outputFolder: 'artifacts/html-report', open: 'never' }],
  49. ['json', { outputFile: 'artifacts/results.json' }],
  50. ],
  51. use: {
  52. baseURL,
  53. locale: 'zh-CN',
  54. timezoneId: 'Asia/Shanghai',
  55. actionTimeout: 10_000,
  56. navigationTimeout: 20_000,
  57. screenshot: 'off',
  58. // Auth traces contain request bodies and bearer tokens. Keep them disabled
  59. // by default; an operator may opt in only in a protected local/CI workspace.
  60. trace: process.env.E2E_TRACE === '1' ? 'retain-on-failure' : 'off',
  61. video: 'retain-on-failure',
  62. },
  63. projects: [
  64. {
  65. name: 'chromium',
  66. use: { ...devices['Desktop Chrome'] },
  67. },
  68. ],
  69. })