From f75463e170e8983dd4c22a5a6b3d0475aa6faa39 Mon Sep 17 00:00:00 2001 From: Jack Westbrook Date: Mon, 9 Dec 2024 14:56:17 +0100 Subject: [PATCH] refactor(playwright): move playwright config and add package.json to prevent esm errors --- .gitignore | 11 ++++++----- e2e/plugin-e2e/package.json | 5 +++++ .../plugin-e2e/playwright.config.ts | 16 ++++++---------- package.json | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 e2e/plugin-e2e/package.json rename playwright.config.ts => e2e/plugin-e2e/playwright.config.ts (91%) diff --git a/.gitignore b/.gitignore index ba113e0e744..0178397d4b6 100644 --- a/.gitignore +++ b/.gitignore @@ -180,11 +180,12 @@ compilation-stats.json /e2e/extensions !/e2e/extensions/.keep /e2e/extensions-suite -/test-results/ -/playwright-report/ -/blob-report/ -/playwright/.cache/ -/playwright/.auth/ +test-results/ +playwright-report/ +blob-report/ +playwright/.cache/ +playwright/.auth/ + # grafana server /scripts/grafana-server/server.log diff --git a/e2e/plugin-e2e/package.json b/e2e/plugin-e2e/package.json new file mode 100644 index 00000000000..10094e6b5ec --- /dev/null +++ b/e2e/plugin-e2e/package.json @@ -0,0 +1,5 @@ +{ + "name": "grafana-e2e-playwright-tests", + "description": "This package.json exists to override the 'type': 'module' setting in root package.json", + "type": "commonjs" +} diff --git a/playwright.config.ts b/e2e/plugin-e2e/playwright.config.ts similarity index 91% rename from playwright.config.ts rename to e2e/plugin-e2e/playwright.config.ts index 85d5d31941a..007a498a2db 100644 --- a/playwright.config.ts +++ b/e2e/plugin-e2e/playwright.config.ts @@ -1,12 +1,8 @@ import { defineConfig, devices } from '@playwright/test'; -import { createRequire } from 'node:module'; import path, { dirname } from 'path'; import { PluginOptions } from '@grafana/plugin-e2e'; -const require = createRequire(import.meta.url); -const testDirRoot = 'e2e/plugin-e2e/'; - export default defineConfig({ fullyParallel: true, /* Retry on CI only */ @@ -46,7 +42,7 @@ export default defineConfig({ // Run all tests in parallel using user with admin role { name: 'admin', - testDir: path.join(testDirRoot, '/plugin-e2e-api-tests/as-admin-user'), + testDir: './plugin-e2e-api-tests/as-admin-user', use: { ...devices['Desktop Chrome'], storageState: 'playwright/.auth/admin.json', @@ -56,7 +52,7 @@ export default defineConfig({ // Run all tests in parallel using user with viewer role { name: 'viewer', - testDir: path.join(testDirRoot, '/plugin-e2e-api-tests/as-viewer-user'), + testDir: './plugin-e2e-api-tests/as-viewer-user', use: { ...devices['Desktop Chrome'], storageState: 'playwright/.auth/viewer.json', @@ -65,7 +61,7 @@ export default defineConfig({ }, { name: 'elasticsearch', - testDir: path.join(testDirRoot, '/elasticsearch'), + testDir: './elasticsearch', use: { ...devices['Desktop Chrome'], storageState: 'playwright/.auth/admin.json', @@ -74,7 +70,7 @@ export default defineConfig({ }, { name: 'mysql', - testDir: path.join(testDirRoot, '/mysql'), + testDir: './mysql', use: { ...devices['Desktop Chrome'], storageState: 'playwright/.auth/admin.json', @@ -83,7 +79,7 @@ export default defineConfig({ }, { name: 'mssql', - testDir: path.join(testDirRoot, '/mssql'), + testDir: './mssql', use: { ...devices['Desktop Chrome'], storageState: 'playwright/.auth/admin.json', @@ -110,7 +106,7 @@ export default defineConfig({ }, { name: 'cloudwatch', - testDir: path.join(testDirRoot, '/cloudwatch'), + testDir: './cloudwatch', use: { ...devices['Desktop Chrome'], storageState: 'playwright/.auth/admin.json', diff --git a/package.json b/package.json index 7d1294fd4f4..d3e4ce5c6be 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "e2e:enterprise": "./e2e/start-and-run-suite enterprise", "e2e:enterprise:dev": "./e2e/start-and-run-suite enterprise dev", "e2e:enterprise:debug": "./e2e/start-and-run-suite enterprise debug", - "e2e:playwright": "yarn playwright test", + "e2e:playwright": "yarn playwright test -c ./e2e/plugin-e2e/playwright.config.ts", "e2e:playwright:server": "yarn e2e:plugin:build && ./e2e/plugin-e2e/start-and-run-suite", "e2e:storybook": "PORT=9001 ./e2e/run-suite storybook true", "e2e:plugin:build": "nx run-many -t build --projects='@test-plugins/*'",