From 6020590b2f7d236cbad247fff4270c7936b520fa Mon Sep 17 00:00:00 2001 From: Cesar Celis Hernandez Date: Tue, 25 Apr 2023 10:19:00 -0600 Subject: [PATCH] Make playwright run faster (#2737) --- .github/workflows/jobs.yaml | 94 +++++++++++++++++-- portal-ui/Makefile | 5 + portal-ui/check-warnings-istanbul-coverage.sh | 19 ++++ portal-ui/e2e/auth.setup.ts | 3 +- portal-ui/e2e/buckets.spec.ts | 3 +- portal-ui/e2e/consts.ts | 1 + portal-ui/e2e/groups.spec.ts | 3 +- portal-ui/e2e/lifecycle.spec.ts | 3 +- portal-ui/e2e/login.spec.ts | 3 +- portal-ui/e2e/policies.spec.ts | 3 +- portal-ui/package.json | 1 + portal-ui/playwright/jobs.yaml | 39 ++++---- 12 files changed, 141 insertions(+), 36 deletions(-) create mode 100755 portal-ui/check-warnings-istanbul-coverage.sh diff --git a/.github/workflows/jobs.yaml b/.github/workflows/jobs.yaml index 356301c32..2a74ff30f 100644 --- a/.github/workflows/jobs.yaml +++ b/.github/workflows/jobs.yaml @@ -1308,9 +1308,92 @@ jobs: exit 1 fi + ui-assets-istanbul-coverage: + name: "Assets with Istanbul Plugin for coverage" + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [1.19.x] + os: [ubuntu-latest] + steps: + - name: Check out code + uses: actions/checkout@v3 + - name: Read .nvmrc + id: node_version + run: echo "$(cat .nvmrc)" && echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_ENV + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.NVMRC }} + cache: "yarn" + cache-dependency-path: portal-ui/yarn.lock + - uses: actions/cache@v3 + id: assets-cache-istanbul-coverage + name: Assets Cache Istanbul Coverage + with: + path: | + ./portal-ui/build/ + key: ${{ runner.os }}-assets-istanbul-coverage-${{ github.run_id }} + - name: Install Dependencies + working-directory: ./portal-ui + continue-on-error: false + run: | + yarn install --frozen-lockfile --immutable + - name: Check for Warnings in build output + working-directory: ./portal-ui + continue-on-error: false + run: | + ./check-warnings-istanbul-coverage.sh + - name: Check if Files are Prettified + working-directory: ./portal-ui + continue-on-error: false + run: | + ./check-prettier.sh + + compile-binary-istanbul-coverage: + name: "Compile Console Binary with Istanbul Plugin for Coverage" + needs: + - lint-job + - ui-assets-istanbul-coverage + - reuse-golang-dependencies + - semgrep-static-code-analysis + runs-on: ${{ matrix.os }} + strategy: + matrix: + go-version: [1.19.x] + os: [ubuntu-latest] + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }} + uses: actions/setup-go@v3 + with: + go-version: ${{ matrix.go-version }} + cache: true + id: go + - uses: actions/cache@v3 + name: Console Binary Cache Istanbul Coverage + with: + path: | + ./console + key: ${{ runner.os }}-binary-istanbul-coverage-${{ github.run_id }} + - uses: actions/cache@v3 + id: assets-cache-istanbul-coverage + name: Assets Cache Istanbul Coverage + with: + path: | + ./portal-ui/build/ + key: ${{ runner.os }}-assets-istanbul-coverage-${{ github.run_id }} + - name: Build on ${{ matrix.os }} + env: + GO111MODULE: on + GOOS: linux + run: | + make console + playwright: needs: - - compile-binary + - compile-binary-istanbul-coverage timeout-minutes: 60 runs-on: ubuntu-latest steps: @@ -1337,21 +1420,16 @@ jobs: run: npx playwright install --with-deps - uses: actions/cache@v3 - name: Console Binary Cache + name: Console Binary Cache Istanbul Coverage with: path: | ./console - key: ${{ runner.os }}-binary-${{ github.run_id }} + key: ${{ runner.os }}-binary-istanbul-coverage-${{ github.run_id }} - name: Start Console, front-end app and initialize users/policies run: | (./console server) & (make initialize-permissions) - - name: Start Browser at port 5005 - run: | - echo "yarn playwright" - (cd $GITHUB_WORKSPACE/portal-ui; yarn playwright) & (sleep 120) # To start port 5005 with Istanbul Plugin Injected - - name: Run Playwright tests run: | echo "Run tests under playwright folder only" diff --git a/portal-ui/Makefile b/portal-ui/Makefile index 1fd676e0d..decca12b9 100644 --- a/portal-ui/Makefile +++ b/portal-ui/Makefile @@ -5,6 +5,11 @@ build-static: @if [ -f "${NVM_DIR}/nvm.sh" ]; then \. "${NVM_DIR}/nvm.sh" && nvm install && nvm use; fi && \ NODE_OPTIONS=--openssl-legacy-provider yarn build +build-static-istanbul-coverage: + @echo "Building frontend static assets to 'build'" + @if [ -f "${NVM_DIR}/nvm.sh" ]; then \. "${NVM_DIR}/nvm.sh" && nvm install && nvm use; fi && \ + NODE_OPTIONS=--openssl-legacy-provider yarn buildistanbulcoverage + test-warnings: ./check-warnings.sh diff --git a/portal-ui/check-warnings-istanbul-coverage.sh b/portal-ui/check-warnings-istanbul-coverage.sh new file mode 100755 index 000000000..d47243fb4 --- /dev/null +++ b/portal-ui/check-warnings-istanbul-coverage.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +yell() { echo "$0: $*" >&2; } + +die() { + yell "$*" + cat yarn.log + exit 111 +} + +try() { "$@" &> yarn.log || die "cannot $*"; } + +rm -f yarn.log +try make build-static-istanbul-coverage + +if cat yarn.log | grep "Compiled with warnings"; then + echo "There are warnings in the code" + exit 1 +fi diff --git a/portal-ui/e2e/auth.setup.ts b/portal-ui/e2e/auth.setup.ts index 46bbd5a50..891b508ea 100644 --- a/portal-ui/e2e/auth.setup.ts +++ b/portal-ui/e2e/auth.setup.ts @@ -15,10 +15,11 @@ // along with this program. If not, see . import { test as setup } from "@playwright/test"; import { minioadminFile } from "./consts"; +import { pagePort } from "./consts"; setup("authenticate as admin", async ({ page }) => { // Perform authentication steps. Replace these actions with your own. - await page.goto("http://localhost:5005"); + await page.goto(pagePort); await page.getByPlaceholder("Username").click(); await page.getByPlaceholder("Username").fill("minioadmin"); await page.getByPlaceholder("Password").click(); diff --git a/portal-ui/e2e/buckets.spec.ts b/portal-ui/e2e/buckets.spec.ts index db6bf0b27..f9931c281 100644 --- a/portal-ui/e2e/buckets.spec.ts +++ b/portal-ui/e2e/buckets.spec.ts @@ -16,11 +16,12 @@ import { expect } from "@playwright/test"; import { generateUUID, test } from "./fixtures/baseFixture"; import { minioadminFile } from "./consts"; +import { pagePort } from "./consts"; test.use({ storageState: minioadminFile }); test.beforeEach(async ({ page }) => { - await page.goto("http://localhost:5005/"); + await page.goto(pagePort); }); test("create a new bucket", async ({ page }) => { diff --git a/portal-ui/e2e/consts.ts b/portal-ui/e2e/consts.ts index f18a3efb0..2e02b39f2 100644 --- a/portal-ui/e2e/consts.ts +++ b/portal-ui/e2e/consts.ts @@ -15,3 +15,4 @@ // along with this program. If not, see . export const minioadminFile = "playwright/.auth/admin.json"; +export const pagePort = "http://localhost:9090/buckets"; diff --git a/portal-ui/e2e/groups.spec.ts b/portal-ui/e2e/groups.spec.ts index 9044ef619..b89b46452 100644 --- a/portal-ui/e2e/groups.spec.ts +++ b/portal-ui/e2e/groups.spec.ts @@ -17,11 +17,12 @@ import { expect } from "@playwright/test"; import { generateUUID, test } from "./fixtures/baseFixture"; import { minioadminFile } from "./consts"; +import { pagePort } from "./consts"; test.use({ storageState: minioadminFile }); test.beforeEach(async ({ page }) => { - await page.goto("http://localhost:5005/"); + await page.goto(pagePort); }); test("Add a new group", async ({ page }) => { diff --git a/portal-ui/e2e/lifecycle.spec.ts b/portal-ui/e2e/lifecycle.spec.ts index a31368820..44b42cf35 100644 --- a/portal-ui/e2e/lifecycle.spec.ts +++ b/portal-ui/e2e/lifecycle.spec.ts @@ -17,11 +17,12 @@ import { expect } from "@playwright/test"; import { test } from "./fixtures/baseFixture"; import { minioadminFile } from "./consts"; +import { pagePort } from "./consts"; test.use({ storageState: minioadminFile }); test.beforeEach(async ({ page }) => { - await page.goto("http://localhost:5005/buckets"); + await page.goto(pagePort); }); test("Test if Object Version selector is present in Lifecycle rule modal", async ({ diff --git a/portal-ui/e2e/login.spec.ts b/portal-ui/e2e/login.spec.ts index 3bb46e5c7..ede922cf7 100644 --- a/portal-ui/e2e/login.spec.ts +++ b/portal-ui/e2e/login.spec.ts @@ -1,7 +1,8 @@ import { test, expect } from "@playwright/test"; +import { pagePort } from "./consts"; test("Basic `minioadmin` Login", async ({ page, context }) => { - await page.goto("http://localhost:5005"); + await page.goto(pagePort); await page.getByPlaceholder("Username").click(); await page.getByPlaceholder("Username").fill("minioadmin"); await page.getByPlaceholder("Password").click(); diff --git a/portal-ui/e2e/policies.spec.ts b/portal-ui/e2e/policies.spec.ts index c48ed7b97..e2376fbe8 100644 --- a/portal-ui/e2e/policies.spec.ts +++ b/portal-ui/e2e/policies.spec.ts @@ -16,11 +16,12 @@ import { expect } from "@playwright/test"; import { generateUUID, test } from "./fixtures/baseFixture"; import { minioadminFile } from "./consts"; +import { pagePort } from "./consts"; test.use({ storageState: minioadminFile }); test.beforeEach(async ({ page }) => { - await page.goto("http://localhost:5005/"); + await page.goto(pagePort); }); test("Can create a policy", async ({ page }) => { diff --git a/portal-ui/package.json b/portal-ui/package.json index b0d7bcbc6..2d40484e8 100644 --- a/portal-ui/package.json +++ b/portal-ui/package.json @@ -39,6 +39,7 @@ "scripts": { "start": "PORT=5005 react-scripts start", "build": "react-scripts build", + "buildistanbulcoverage": "PORT=9090 USE_BABEL_PLUGIN_ISTANBUL=1 react-app-rewired build", "test": "react-scripts test", "eject": "react-scripts eject", "playwright": "PORT=5005 USE_BABEL_PLUGIN_ISTANBUL=1 react-app-rewired start" diff --git a/portal-ui/playwright/jobs.yaml b/portal-ui/playwright/jobs.yaml index 7296de9ef..63fc5c821 100644 --- a/portal-ui/playwright/jobs.yaml +++ b/portal-ui/playwright/jobs.yaml @@ -40,8 +40,8 @@ jobs: run: | make verifiers - ui-assets: - name: "React Code Has No Warnings & Prettified" + ui-assets-istanbul-coverage: + name: "Assets with Istanbul Plugin for coverage" runs-on: ubuntu-latest strategy: matrix: @@ -59,12 +59,12 @@ jobs: cache: "yarn" cache-dependency-path: portal-ui/yarn.lock - uses: actions/cache@v3 - id: assets-cache - name: Assets Cache + id: assets-cache-istanbul-coverage + name: Assets Cache Istanbul Coverage with: path: | ./portal-ui/build/ - key: ${{ runner.os }}-assets-${{ github.run_id }} + key: ${{ runner.os }}-assets-istanbul-coverage-${{ github.run_id }} - name: Install Dependencies working-directory: ./portal-ui continue-on-error: false @@ -74,7 +74,7 @@ jobs: working-directory: ./portal-ui continue-on-error: false run: | - ./check-warnings.sh + ./check-warnings-istanbul-coverage.sh - name: Check if Files are Prettified working-directory: ./portal-ui continue-on-error: false @@ -122,11 +122,11 @@ jobs: pip3 install semgrep semgrep --config semgrep.yaml $(pwd)/portal-ui --error - compile-binary: - name: Compiles on Go ${{ matrix.go-version }} and ${{ matrix.os }} + compile-binary-istanbul-coverage: + name: "Compile Console Binary with Istanbul Plugin for Coverage" needs: - lint-job - - ui-assets + - ui-assets-istanbul-coverage - reuse-golang-dependencies - semgrep-static-code-analysis runs-on: ${{ matrix.os }} @@ -145,18 +145,18 @@ jobs: cache: true id: go - uses: actions/cache@v3 - name: Console Binary Cache + name: Console Binary Cache Istanbul Coverage with: path: | ./console - key: ${{ runner.os }}-binary-${{ github.run_id }} + key: ${{ runner.os }}-binary-istanbul-coverage-${{ github.run_id }} - uses: actions/cache@v3 - id: assets-cache - name: Assets Cache + id: assets-cache-istanbul-coverage + name: Assets Cache Istanbul Coverage with: path: | ./portal-ui/build/ - key: ${{ runner.os }}-assets-${{ github.run_id }} + key: ${{ runner.os }}-assets-istanbul-coverage-${{ github.run_id }} - name: Build on ${{ matrix.os }} env: GO111MODULE: on @@ -166,7 +166,7 @@ jobs: playwright: needs: - - compile-binary + - compile-binary-istanbul-coverage timeout-minutes: 60 runs-on: ubuntu-latest steps: @@ -193,21 +193,16 @@ jobs: run: npx playwright install --with-deps - uses: actions/cache@v3 - name: Console Binary Cache + name: Console Binary Cache Istanbul Coverage with: path: | ./console - key: ${{ runner.os }}-binary-${{ github.run_id }} + key: ${{ runner.os }}-binary-istanbul-coverage-${{ github.run_id }} - name: Start Console, front-end app and initialize users/policies run: | (./console server) & (make initialize-permissions) - - name: Start Browser at port 5005 - run: | - echo "yarn playwright" - (cd $GITHUB_WORKSPACE/portal-ui; yarn playwright) & (sleep 120) # To start port 5005 with Istanbul Plugin Injected - - name: Run Playwright tests run: | echo "Run tests under playwright folder only"