Skip to content

Commit

Permalink
feat(e2e): switching to playwright (#1720)
Browse files Browse the repository at this point in the history
* Switching to playwright

* some screenshots

* Updated screenshots and command to run in docker

* prebuild demo app to warm up cache

---------

Co-authored-by: Dmitriy Shekhovtsov <[email protected]>
  • Loading branch information
santam85 and valorkin authored Aug 28, 2023
1 parent 4ba9e76 commit d29158f
Show file tree
Hide file tree
Showing 49 changed files with 254 additions and 653 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ jobs:
- uses: actions/setup-node@v3
with:
cache: npm
node-version: 18.17.0
node-version: 18
- run: npm ci

- run: npm run lint
- run: npm run build:lib
- run: npm run build:schematics
- run: npm run test:ci
- run: npm run test:schematics
- run: |
npx cypress install
npm run e2e:ci
- run: npm run build:prod
- run: npm run e2e
6 changes: 5 additions & 1 deletion apps/ng2-charts-demo/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": ["../../.eslintrc.json"],
"extends": ["plugin:playwright/recommended", "../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
Expand Down Expand Up @@ -31,6 +31,10 @@
"files": ["*.html"],
"extends": ["plugin:@nx/angular-template"],
"rules": {}
},
{
"files": ["e2e/**/*.{ts,js,tsx,jsx}"],
"rules": {}
}
]
}
38 changes: 38 additions & 0 deletions apps/ng2-charts-demo/e2e/ng2-charts.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { test, expect } from "@playwright/test";

test(`navigate to main Demo page and check info`, async ({ page }) => {
const topBarSelector = "mat-toolbar";
const mainContentSelector = "main";
await page.goto("/");

// wait for animations to finish
await expect(page.locator(topBarSelector)).toBeVisible();

await expect(page.locator(topBarSelector)).toHaveScreenshot();

return expect(page.locator(mainContentSelector)).toBeVisible();
});

const componentsArray = [
{ url: "/#LineChart", selector: "app-line-chart" },
{ url: "/#BarChart", selector: "app-bar-chart" },
{ url: "/#DoughnutChart", selector: "app-doughnut-chart" },
{ url: "/#RadarChart", selector: "app-radar-chart" },
{ url: "/#PieChart", selector: "app-pie-chart" },
{ url: "/#PolarAreaChart", selector: "app-polar-area-chart" },
{ url: "/#BubbleChart", selector: "app-bubble-chart" },
{ url: "/#ScatterChart", selector: "app-scatter-chart" },
{ url: "/#DynamicChart", selector: "app-dynamic-chart" }
];

componentsArray.forEach((component) => {
test(`${component.selector}`, async ({ page }) => {
await page.goto(component.url);
// wait for animations to finish
await expect(page.locator(component.selector)
.locator("canvas"))
.toBeVisible();

return expect(page.locator(component.selector).locator("canvas")).toHaveScreenshot();
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions apps/ng2-charts-demo/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { defineConfig, devices } from "@playwright/test";
import { nxE2EPreset } from "@nx/playwright/preset";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { workspaceRoot } from "@nx/devkit";

// For CI, you may want to set BASE_URL to the deployed application.
const baseURL = process.env["BASE_URL"] || "http://localhost:4200";

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

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
...nxE2EPreset(__filename, { testDir: "./e2e" }),
projects: [{
name: "chromium",
use: { ...devices["Desktop Chrome"] }
}],
webServer: {
command: "nx serve-static",
url: baseURL,
reuseExistingServer: !process.env.CI
},
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
baseURL,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry"
}
});
15 changes: 15 additions & 0 deletions apps/ng2-charts-demo/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@
"options": {
"buildTarget": "ng2-charts-demo:build"
}
},
"e2e": {
"executor": "@nx/playwright:playwright",
"outputs": ["{workspaceRoot}/dist/.playwright/apps/ng2-charts-demo"],
"options": {
"config": "apps/ng2-charts-demo/playwright.config.ts"
},
"configurations": {
"update-snapshots": {
"options": {
"skipInstall": true,
"updateSnapshots": "all"
}
}
}
}
},
"implicitDependencies": ["ng2-charts"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class BarChartComponent {
@ViewChild(BaseChartDirective) chart: BaseChartDirective | undefined;

public barChartOptions: ChartConfiguration['options'] = {
responsive: true,
// We use these empty structures as placeholders for dynamic theming.
scales: {
x: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class FinancialChartComponent {
};

public financialChartOptions: ChartConfiguration['options'] = {
responsive: true,
animation: false,
maintainAspectRatio: false,
scales: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class PieChartComponent {

// Pie
public pieChartOptions: ChartConfiguration['options'] = {
responsive: true,
plugins: {
legend: {
display: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { ChartConfiguration, ChartData, ChartEvent, ChartType } from 'chart.js';
})
export class RadarChartComponent {
// Radar
public radarChartOptions: ChartConfiguration['options'] = {
responsive: true,
};
public radarChartOptions: ChartConfiguration['options'] = {};
public radarChartLabels: string[] = [
'Eating',
'Drinking',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { ChartConfiguration, ChartData, ChartEvent, ChartType } from 'chart.js';
})
export class ScatterChartComponent {
// scatter
public scatterChartOptions: ChartConfiguration['options'] = {
responsive: true,
};
public scatterChartOptions: ChartConfiguration['options'] = {};
public scatterChartLabels: string[] = [
'Eating',
'Drinking',
Expand Down
10 changes: 0 additions & 10 deletions apps/ng2-charts-e2e/.eslintrc.json

This file was deleted.

20 changes: 0 additions & 20 deletions apps/ng2-charts-e2e/cypress.config.ts

This file was deleted.

40 changes: 0 additions & 40 deletions apps/ng2-charts-e2e/project.json

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
42 changes: 0 additions & 42 deletions apps/ng2-charts-e2e/src/e2e/spec.cy.ts

This file was deleted.

49 changes: 0 additions & 49 deletions apps/ng2-charts-e2e/src/support/commands.ts

This file was deleted.

17 changes: 0 additions & 17 deletions apps/ng2-charts-e2e/src/support/e2e.ts

This file was deleted.

16 changes: 0 additions & 16 deletions apps/ng2-charts-e2e/tsconfig.json

This file was deleted.

Loading

0 comments on commit d29158f

Please sign in to comment.