Skip to content

Commit

Permalink
test(e2e): replace cypress with playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
jackw committed Feb 15, 2024
1 parent ec8b6e5 commit 31386c4
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 11 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ e2e-results/
# Editor
.idea

.eslintcache
.eslintcache
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright/.auth/
10 changes: 0 additions & 10 deletions cypress/integration/01-smoke.spec.ts

This file was deleted.

109 changes: 109 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",
"test": "jest --watch --onlyChanged",
"test:ci": "jest --passWithNoTests --maxWorkers 4",
"test:playwright": "playwright test",
"typecheck": "tsc --noEmit",
"lint": "eslint --cache --ignore-path ./.gitignore --ext .js,.jsx,.ts,.tsx .",
"lint:fix": "npm run lint -- --fix",
Expand All @@ -22,7 +23,9 @@
"@grafana/e2e": "9.5.3",
"@grafana/e2e-selectors": "9.5.3",
"@grafana/eslint-config": "^6.0.0",
"@grafana/plugin-e2e": "^0.12.0",
"@grafana/tsconfig": "^1.2.0-rc1",
"@playwright/test": "^1.41.2",
"@swc/core": "^1.3.90",
"@swc/helpers": "^0.5.0",
"@swc/jest": "^0.2.26",
Expand Down
87 changes: 87 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { defineConfig, devices } from '@playwright/test';
import { dirname } from 'node:path';

const pluginE2eAuth = `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`;

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* 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:https://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: [
// 1. Login to Grafana and store the cookie on disk for use in other tests.
{
name: 'auth',
testDir: pluginE2eAuth,
testMatch: [/.*\.js/],
},
{
name: 'chromium',
use: { ...devices['Desktop Chrome'], storageState: 'playwright/.auth/user.json' },
dependencies: ['auth'],
},

// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// },

// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// },

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'docker compose up -d',
// url: 'http:https://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
28 changes: 28 additions & 0 deletions tests/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { test } from '@grafana/plugin-e2e';

test.describe.configure({ mode: 'parallel' });

test('add a traffic light panel to a new dashboard', async ({ panelEditPage, page }) => {
// @ts-expect-error - types currently set to union of core panel plugins
await panelEditPage.setVisualization('Traffic Light');
await panelEditPage.setPanelTitle('Traffic light panel test');
await panelEditPage.collapseSection('Traffic Light');

});

// test('open a clock panel in a provisioned dashboard and set time format to "12 hour"', async ({
// selectors,
// page,
// request,
// grafanaVersion,
// readProvision,
// }) => {
// const dashboard = await readProvision({ filePath: 'provisioning/dashboards/panels.json' });
// const args = { dashboard: { uid: dashboard.uid }, id: '5' };
// const panelEditPage = await new PanelEditPage({ page, selectors, grafanaVersion, request }, args);
// await panelEditPage.goto();
// await expect(panelEditPage.getVisualizationName()).toHaveText('Clock');
// await panelEditPage.collapseSection('Clock');
// await clickRadioButton(page, '12 Hour');
// await expect(true).toBe(true);
// });

0 comments on commit 31386c4

Please sign in to comment.