| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  | import { defineConfig, devices, PlaywrightTestConfig, Project } from '@playwright/test'; | 
					
						
							| 
									
										
										
										
											2024-02-23 19:39:30 +08:00
										 |  |  | import path, { dirname } from 'path'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { PluginOptions } from '@grafana/plugin-e2e'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-03 22:45:54 +08:00
										 |  |  | export const testDirRoot = 'e2e-playwright'; | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  | const pluginDirRoot = path.join(testDirRoot, 'plugin-e2e'); | 
					
						
							| 
									
										
										
										
											2025-09-03 22:45:54 +08:00
										 |  |  | export const DEFAULT_URL = 'http://localhost:3001'; | 
					
						
							| 
									
										
										
										
											2024-02-23 19:39:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-03 22:45:54 +08:00
										 |  |  | export function withAuth(project: Project): Project { | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |   project.dependencies ??= []; | 
					
						
							|  |  |  |   project.use ??= {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   project.dependencies = project.dependencies.concat('authenticate'); | 
					
						
							|  |  |  |   project.use = { | 
					
						
							|  |  |  |     ...project.use, | 
					
						
							|  |  |  |     storageState: `playwright/.auth/${process.env.GRAFANA_ADMIN_USER || 'admin'}.json`, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return project; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-03 22:45:54 +08:00
										 |  |  | export const baseConfig: PlaywrightTestConfig<PluginOptions, {}> = { | 
					
						
							| 
									
										
										
										
											2024-02-23 19:39:30 +08:00
										 |  |  |   fullyParallel: true, | 
					
						
							|  |  |  |   /* Retry on CI only */ | 
					
						
							|  |  |  |   retries: process.env.CI ? 2 : 0, | 
					
						
							|  |  |  |   /* Opt out of parallel tests on CI. */ | 
					
						
							|  |  |  |   workers: process.env.CI ? 1 : undefined, | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |   reporter: [ | 
					
						
							|  |  |  |     ['html'], // pretty
 | 
					
						
							|  |  |  |   ], | 
					
						
							| 
									
										
										
										
											2025-07-25 17:54:07 +08:00
										 |  |  |   expect: { | 
					
						
							|  |  |  |     timeout: 10_000, | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2024-02-23 19:39:30 +08:00
										 |  |  |   use: { | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     ...devices['Desktop Chrome'], | 
					
						
							| 
									
										
										
										
											2025-07-19 00:08:47 +08:00
										 |  |  |     baseURL: process.env.GRAFANA_URL ?? DEFAULT_URL, | 
					
						
							| 
									
										
										
										
											2024-03-12 20:48:32 +08:00
										 |  |  |     trace: 'retain-on-failure', | 
					
						
							| 
									
										
										
										
											2024-02-23 19:39:30 +08:00
										 |  |  |     httpCredentials: { | 
					
						
							|  |  |  |       username: 'admin', | 
					
						
							|  |  |  |       password: 'admin', | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |     screenshot: 'only-on-failure', | 
					
						
							|  |  |  |     permissions: ['clipboard-read', 'clipboard-write'], | 
					
						
							| 
									
										
										
										
											2024-02-23 19:39:30 +08:00
										 |  |  |     provisioningRootDir: path.join(process.cwd(), process.env.PROV_DIR ?? 'conf/provisioning'), | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2025-09-03 22:45:54 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default defineConfig<PluginOptions>({ | 
					
						
							|  |  |  |   ...baseConfig, | 
					
						
							| 
									
										
										
										
											2025-07-19 00:08:47 +08:00
										 |  |  |   ...(!process.env.GRAFANA_URL && { | 
					
						
							|  |  |  |     webServer: { | 
					
						
							|  |  |  |       command: 'yarn e2e:plugin:build && ./e2e-playwright/start-server', | 
					
						
							|  |  |  |       url: DEFAULT_URL, | 
					
						
							|  |  |  |       stdout: 'pipe', | 
					
						
							|  |  |  |       stderr: 'pipe', | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   }), | 
					
						
							| 
									
										
										
										
											2024-02-23 19:39:30 +08:00
										 |  |  |   projects: [ | 
					
						
							|  |  |  |     // Login to Grafana with admin user and store the cookie on disk for use in other tests
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'authenticate', | 
					
						
							|  |  |  |       testDir: `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`, | 
					
						
							|  |  |  |       testMatch: [/.*\.js/], | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     // Login to Grafana with new user with viewer role and store the cookie on disk for use in other tests
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'createUserAndAuthenticate', | 
					
						
							|  |  |  |       testDir: `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`, | 
					
						
							|  |  |  |       testMatch: [/.*\.js/], | 
					
						
							|  |  |  |       use: { | 
					
						
							|  |  |  |         user: { | 
					
						
							|  |  |  |           user: 'viewer', | 
					
						
							|  |  |  |           password: 'password', | 
					
						
							|  |  |  |           role: 'Viewer', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     // Run all tests in parallel using user with admin role
 | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2024-02-23 19:39:30 +08:00
										 |  |  |       name: 'admin', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/plugin-e2e-api-tests/as-admin-user'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							| 
									
										
										
										
											2024-02-23 19:39:30 +08:00
										 |  |  |     // Run all tests in parallel using user with viewer role
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       name: 'viewer', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/plugin-e2e-api-tests/as-viewer-user'), | 
					
						
							| 
									
										
										
										
											2024-02-23 19:39:30 +08:00
										 |  |  |       use: { | 
					
						
							|  |  |  |         ...devices['Desktop Chrome'], | 
					
						
							|  |  |  |         storageState: 'playwright/.auth/viewer.json', | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       dependencies: ['createUserAndAuthenticate'], | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2024-10-22 04:13:40 +08:00
										 |  |  |       name: 'elasticsearch', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/elasticsearch'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2024-03-20 06:07:48 +08:00
										 |  |  |       name: 'mysql', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/mysql'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2024-10-21 17:36:18 +08:00
										 |  |  |       name: 'mssql', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/mssql'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2024-08-26 22:01:32 +08:00
										 |  |  |       name: 'extensions-test-app', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(testDirRoot, '/test-plugins/grafana-extensionstest-app'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2024-11-01 15:25:27 +08:00
										 |  |  |       name: 'grafana-e2etest-datasource', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(testDirRoot, '/test-plugins/grafana-test-datasource'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2024-10-22 04:13:22 +08:00
										 |  |  |       name: 'cloudwatch', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/cloudwatch'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-01-03 19:52:15 +08:00
										 |  |  |       name: 'azuremonitor', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/azuremonitor'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-01-03 19:52:15 +08:00
										 |  |  |       name: 'cloudmonitoring', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/cloudmonitoring'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-01-03 19:52:15 +08:00
										 |  |  |       name: 'graphite', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/graphite'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-01-03 19:52:15 +08:00
										 |  |  |       name: 'influxdb', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/influxdb'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-01-03 19:52:15 +08:00
										 |  |  |       name: 'opentsdb', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/opentsdb'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-01-25 03:21:41 +08:00
										 |  |  |       name: 'jaeger', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/jaeger'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-01-25 03:21:41 +08:00
										 |  |  |       name: 'grafana-postgresql-datasource', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/grafana-postgresql-datasource'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-08-01 01:34:48 +08:00
										 |  |  |       name: 'canvas', | 
					
						
							|  |  |  |       testDir: path.join(testDirRoot, '/canvas'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-01-25 03:21:41 +08:00
										 |  |  |       name: 'zipkin', | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       testDir: path.join(pluginDirRoot, '/zipkin'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2025-07-29 00:32:18 +08:00
										 |  |  |       name: 'unauthenticated', | 
					
						
							|  |  |  |       testDir: path.join(testDirRoot, '/unauthenticated'), | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |     }, | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       name: 'various', | 
					
						
							|  |  |  |       testDir: path.join(testDirRoot, '/various-suite'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       name: 'panels', | 
					
						
							|  |  |  |       testDir: path.join(testDirRoot, '/panels-suite'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       name: 'smoke', | 
					
						
							|  |  |  |       testDir: path.join(testDirRoot, '/smoke-tests-suite'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       name: 'dashboards', | 
					
						
							|  |  |  |       testDir: path.join(testDirRoot, '/dashboards-suite'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-06-27 21:09:45 +08:00
										 |  |  |       name: 'loki', | 
					
						
							|  |  |  |       testDir: path.join(testDirRoot, '/loki'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       name: 'cloud-plugins', | 
					
						
							|  |  |  |       testDir: path.join(testDirRoot, '/cloud-plugins-suite'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							| 
									
										
										
										
											2025-07-11 17:31:33 +08:00
										 |  |  |       name: 'dashboard-new-layouts', | 
					
						
							|  |  |  |       testDir: path.join(testDirRoot, '/dashboard-new-layouts'), | 
					
						
							| 
									
										
										
										
											2025-08-21 03:36:54 +08:00
										 |  |  |     }), | 
					
						
							| 
									
										
										
										
											2025-09-04 20:17:54 +08:00
										 |  |  |     // Setup project for dashboard CUJS tests
 | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							|  |  |  |       name: 'dashboard-cujs-setup', | 
					
						
							|  |  |  |       testDir: path.join(testDirRoot, '/dashboard-cujs'), | 
					
						
							|  |  |  |       testMatch: ['global-setup.spec.ts'], | 
					
						
							|  |  |  |     }), | 
					
						
							|  |  |  |     // Main dashboard CUJS tests
 | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							|  |  |  |       name: 'dashboard-cujs', | 
					
						
							|  |  |  |       testDir: path.join(testDirRoot, '/dashboard-cujs'), | 
					
						
							|  |  |  |       testIgnore: ['global-setup.spec.ts', 'global-teardown.spec.ts'], | 
					
						
							|  |  |  |       dependencies: ['dashboard-cujs-setup'], | 
					
						
							|  |  |  |     }), | 
					
						
							|  |  |  |     // Teardown project for dashboard CUJS tests
 | 
					
						
							|  |  |  |     withAuth({ | 
					
						
							|  |  |  |       name: 'dashboard-cujs-teardown', | 
					
						
							|  |  |  |       testDir: path.join(testDirRoot, '/dashboard-cujs'), | 
					
						
							|  |  |  |       testMatch: ['global-teardown.spec.ts'], | 
					
						
							|  |  |  |       dependencies: ['dashboard-cujs'], | 
					
						
							|  |  |  |     }), | 
					
						
							| 
									
										
										
										
											2024-02-23 19:39:30 +08:00
										 |  |  |   ], | 
					
						
							|  |  |  | }); |