diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e1c0d33..6d3075a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,8 +18,8 @@ jobs: - name: Setup Node.js environment uses: actions/setup-node@v3 with: - node-version: '20' - cache: 'yarn' + node-version: "20" + cache: "yarn" - name: Install dependencies run: yarn install --immutable --prefer-offline @@ -48,7 +48,7 @@ jobs: if: steps.check-for-backend.outputs.has-backend == 'true' uses: actions/setup-go@v3 with: - go-version: '1.20' + go-version: "1.20" - name: Test backend if: steps.check-for-backend.outputs.has-backend == 'true' @@ -64,30 +64,21 @@ jobs: version: latest args: buildAll - - name: Check for E2E - id: check-for-e2e - run: | - if [ -d "cypress" ] - then - echo "has-e2e=true" >> $GITHUB_OUTPUT - fi + - name: Install Playwright Browsers + run: yarn playwright install --with-deps - name: Start grafana docker - if: steps.check-for-e2e.outputs.has-e2e == 'true' run: docker-compose up -d - - name: Run e2e tests - if: steps.check-for-e2e.outputs.has-e2e == 'true' - run: yarn run e2e + - name: Run Playwright tests + run: yarn playwright test - name: Stop grafana docker - if: steps.check-for-e2e.outputs.has-e2e == 'true' run: docker-compose down - - name: Archive E2E output - uses: actions/upload-artifact@v3 - if: steps.check-for-e2e.outputs.has-e2e == 'true' && steps.run-e2e-tests.outcome != 'success' + - uses: actions/upload-artifact@v4 + if: always() with: - name: cypress-videos - path: cypress/videos - retention-days: 5 + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/.gitignore b/.gitignore index 7f355e3..ab25ef9 100755 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,8 @@ grafana # Binaries build/ +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ +tests-examples/ diff --git a/cypress.json b/cypress.json deleted file mode 100644 index 60ed5aa..0000000 --- a/cypress.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "video": false -} diff --git a/cypress/integration/01-smoke.spec.ts b/cypress/integration/01-smoke.spec.ts deleted file mode 100644 index ed0867d..0000000 --- a/cypress/integration/01-smoke.spec.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { e2e } from '@grafana/e2e'; - -e2e.scenario({ - describeName: 'Smoke test', - itName: 'Smoke test', - scenario: () => { - e2e.pages.Home.visit(); - e2e().contains('Welcome to Grafana').should('be.visible'); - }, -}); diff --git a/package.json b/package.json index fa89968..782d94a 100644 --- a/package.json +++ b/package.json @@ -20,8 +20,9 @@ "devDependencies": { "@babel/core": "^7.24.9", "@grafana/eslint-config": "^7.0.0", - "@grafana/plugin-e2e": "^1.6.0", + "@grafana/plugin-e2e": "^1.6.1", "@grafana/tsconfig": "^1.3.0-rc1", + "@playwright/test": "^1.45.3", "@swc/core": "^1.7.1", "@swc/helpers": "^0.5.12", "@swc/jest": "^0.2.36", diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..0235e8a --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,63 @@ +import { dirname } from 'path'; +import { defineConfig, devices } from '@playwright/test'; +import type { PluginOptions } from '@grafana/plugin-e2e'; + +const pluginE2eAuth = `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`; + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// import dotenv from 'dotenv'; +// dotenv.config({ path: path.resolve(__dirname, '.env') }); + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + testDir: './tests', + /* Run tests in files in parallel */ + fullyParallel: true, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: process.env.CI ? 1 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: 'html', + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Base URL to use in actions like `await page.goto('/')`. */ + baseURL: 'http://localhost:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: 'on-first-retry', + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: 'auth', + testDir: pluginE2eAuth, + testMatch: [/.*\.js/], + }, + { + name: 'run-tests', + use: { + ...devices['Desktop Chrome'], + // @grafana/plugin-e2e writes the auth state to this file, + // the path should not be modified + storageState: 'playwright/.auth/admin.json', + }, + dependencies: ['auth'], + } + ], + + /* Run your local dev server before starting the tests */ + // webServer: { + // command: 'npm run start', + // url: 'http://127.0.0.1:3000', + // reuseExistingServer: !process.env.CI, + // }, +}); diff --git a/tests/example.spec.ts b/tests/example.spec.ts new file mode 100644 index 0000000..54a906a --- /dev/null +++ b/tests/example.spec.ts @@ -0,0 +1,18 @@ +import { test, expect } from '@playwright/test'; + +test('has title', async ({ page }) => { + await page.goto('https://playwright.dev/'); + + // Expect a title "to contain" a substring. + await expect(page).toHaveTitle(/Playwright/); +}); + +test('get started link', async ({ page }) => { + await page.goto('https://playwright.dev/'); + + // Click the get started link. + await page.getByRole('link', { name: 'Get started' }).click(); + + // Expects page to have a heading with the name of Installation. + await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible(); +}); diff --git a/yarn.lock b/yarn.lock index 4414ffd..21236c4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -659,7 +659,7 @@ ua-parser-js "^1.0.32" web-vitals "^4.0.1" -"@grafana/plugin-e2e@^1.6.0": +"@grafana/plugin-e2e@^1.6.1": version "1.6.1" resolved "https://registry.yarnpkg.com/@grafana/plugin-e2e/-/plugin-e2e-1.6.1.tgz#51c4f9d32f5d92e38061f09f5bcaa9d5070d64b5" integrity sha512-1Ww1luGFKeytiAhbg321+z8n0yZ5ARTkUgSN4YdRkupHThwi+pysqGmmiy9tJyewyqkZMt8maawL6gK2qyTKHA== @@ -1240,6 +1240,13 @@ resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.1.1.tgz#1ec17e2edbec25c8306d424ecfbf13c7de1aaa31" integrity sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA== +"@playwright/test@^1.45.3": + version "1.45.3" + resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.45.3.tgz#22e9c38b3081d6674b28c6e22f784087776c72e5" + integrity sha512-UKF4XsBfy+u3MFWEH44hva1Q8Da28G6RFtR2+5saw+jgAFQV5yYnB1fu68Mz7fO+5GJF3wgwAIs0UelU8TxFrA== + dependencies: + playwright "1.45.3" + "@popperjs/core@2.11.8": version "2.11.8" resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.8.tgz#6b79032e760a0899cd4204710beede972a3a185f" @@ -4189,6 +4196,11 @@ fs.realpath@^1.0.0: resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== +fsevents@2.3.2: + version "2.3.2" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a" + integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== + fsevents@^2.3.2, fsevents@~2.3.2: version "2.3.3" resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6" @@ -6152,6 +6164,20 @@ pkg-dir@^4.2.0: dependencies: find-up "^4.0.0" +playwright-core@1.45.3: + version "1.45.3" + resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.45.3.tgz#e77bc4c78a621b96c3e629027534ee1d25faac93" + integrity sha512-+ym0jNbcjikaOwwSZycFbwkWgfruWvYlJfThKYAlImbxUgdWFO2oW70ojPm4OpE4t6TAo2FY/smM+hpVTtkhDA== + +playwright@1.45.3: + version "1.45.3" + resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.45.3.tgz#75143f73093a6e1467f7097083d2f0846fb8dd2f" + integrity sha512-QhVaS+lpluxCaioejDZ95l4Y4jSFCsBvl2UZkpeXlzxmqS+aABr5c82YmfMHrL6x27nvrvykJAFpkzT2eWdJww== + dependencies: + playwright-core "1.45.3" + optionalDependencies: + fsevents "2.3.2" + portfinder@^1.0.17: version "1.0.32" resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.32.tgz#2fe1b9e58389712429dc2bea5beb2146146c7f81"