Skip to content

Commit e041721

Browse files
authored
fix: Removed unneeded e2e tests + improved GH action (#1596)
1 parent 0fae3a4 commit e041721

File tree

4 files changed

+87
-171
lines changed

4 files changed

+87
-171
lines changed

.github/workflows/playwright.yml

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,68 @@
1-
name: UI validation on prod
1+
name: Running Playwright test on UI
22
on:
3-
workflow_dispatch:
4-
3+
push:
4+
branches: [main]
5+
paths:
6+
- 'static/nginxaas-azure/js/cost-calculator_v2.js'
7+
- 'content/nginxaas-azure/billing/usage-and-cost-estimator.md'
8+
pull_request:
9+
paths:
10+
- 'static/nginxaas-azure/js/cost-calculator_v2.js'
11+
- 'content/nginxaas-azure/billing/usage-and-cost-estimator.md'
12+
permissions:
13+
contents: read
514
jobs:
15+
get-playwright-version:
16+
name: Get Playwright Version
17+
runs-on: ubuntu-latest
18+
outputs:
19+
version: ${{ steps.get-playwright-version.outputs.version }}
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
23+
- name: Get version from package.json
24+
id: get-playwright-version
25+
run: |
26+
version=$(jq -r '.devDependencies["@playwright/test"] // .dependencies["@playwright/test"]' package.json)
27+
test -n "$version" || { echo "No @playwright/test version found in package.json"; exit 1; }
28+
echo "version=$version" >> $GITHUB_OUTPUT
29+
echo "Version: " $version
630
run-playwright-tests:
31+
name: Run Playwright
32+
needs: get-playwright-version
733
runs-on: ubuntu-latest
34+
container:
35+
image: mcr.microsoft.com/playwright:v${{needs.get-playwright-version.outputs.version}}-jammy
836
steps:
9-
- uses: actions/checkout@v4
10-
- uses: actions/setup-node@v6
37+
- name: Checkout code
38+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
39+
- name: Setup Hugo
40+
uses: peaceiris/actions-hugo@75d2e84710de30f6ff7268e08f310b60ef14033f # v3.0.0
1141
with:
12-
node-version: lts/*
42+
hugo-version: '0.147.8'
43+
extended: true
44+
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 #v6.0.0
45+
with:
46+
go-version: '1.24.6'
1347
- name: Install dependencies
1448
run: npm ci
15-
- name: Install Playwright Browsers
16-
run: npx playwright install --with-deps
1749
- name: Run Playwright tests
18-
run: npx playwright test --retries=2
19-
- uses: actions/upload-artifact@v6
20-
if: ${{ !cancelled() }}
50+
id: test-ui
51+
# Check done to set the home variable. Workaround as browser is unable to launch if the $HOME folder isn't owned by the current user.
52+
if: ${{ runner.os == 'Linux' }}
53+
env:
54+
HOME: /root
55+
run: |
56+
git config --global --add safe.directory /__w/nginx-hugo-theme/nginx-hugo-theme
57+
cd tests && npx playwright test | tee output.log
58+
if grep -q "failed" output.log; then
59+
echo "Playwright tests failed. Please view the Playwright report to see full error."
60+
exit 1
61+
fi
62+
- uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
63+
id: artifact-upload
64+
if: ${{ !cancelled() && failure() && steps.test-ui.conclusion == 'failure' }}
2165
with:
2266
name: playwright-report
2367
path: tests/playwright-report/
24-
retention-days: 30
25-
- uses: actions/upload-artifact@v6
26-
if: ${{ !cancelled() }}
27-
with:
28-
name: test-results
29-
path: tests/test-results/
30-
retention-days: 30
68+
retention-days: 3

tests/n4a-calculator.spec.ts

Lines changed: 0 additions & 150 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { defineConfig, devices } from '@playwright/test';
22
export default defineConfig({
3-
testDir: 'tests',
3+
testDir: './src',
44
fullyParallel: true,
55
workers: 1,
6-
outputDir: 'tests/test-results',
7-
reporter: [['html', { outputFolder: 'tests/playwright-report' }]],
6+
outputDir: './test-results',
7+
reporter: [['html', { outputFolder: './playwright-report' }]],
88
projects: [
99
{
1010
name: 'chromium',

tests/src/n4a-calculator.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { expect, test } from "@playwright/test";
2+
import { handleConsentPopup, waitFor } from "../util";
3+
4+
test.describe("Testing for N4A calculator page", () => {
5+
test.beforeEach(async ({ page }) => {
6+
await page.goto("/nginxaas/azure/billing/usage-and-cost-estimator/");
7+
await page.waitForLoadState("load");
8+
await waitFor(async () => await handleConsentPopup(page));
9+
});
10+
11+
test("calculator renders", async ({ page }) => {
12+
const header = page.getByTestId("calculator-section-heading");
13+
const content = page.getByTestId("calculator-section-content");
14+
15+
await expect(header).toBeVisible();
16+
await expect(content).toBeVisible();
17+
});
18+
19+
test("calculator values render", async ({ page }) => {
20+
// Conjunction - If outputs are rendered, it is safe to say the inputs are rendered.
21+
// NOT testing changing numbers will impact the total values as that should be the job of unit tests. This is just a smoke tests.
22+
const ncuEstimateValue = page.getByTestId("ncuEstimateValue");
23+
const totalValue = page.getByTestId("total-value");
24+
25+
expect(await ncuEstimateValue.textContent()).toBeTruthy();
26+
expect(await totalValue.textContent()).toBeTruthy();
27+
});
28+
});

0 commit comments

Comments
 (0)