From 77a562e0f26f70a9b7d4a110c66159c233ac1521 Mon Sep 17 00:00:00 2001 From: Marais Rossouw Date: Wed, 21 Aug 2024 11:25:46 +1000 Subject: [PATCH 1/7] chore: allow dapr start scripts to run outside of .vscode --- .vscode/tasks.json | 6 +++--- scripts/dev | 11 +++++++++++ scripts/dev-backend | 5 +++++ scripts/dev-frontend | 5 +++++ 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100755 scripts/dev create mode 100755 scripts/dev-backend create mode 100755 scripts/dev-frontend diff --git a/.vscode/tasks.json b/.vscode/tasks.json index cc3c94a..8f4256b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -40,7 +40,7 @@ { "label": "dapr-up-frontend", "type": "shell", - "command": [ "dapr run --app-id frontend --app-port 5114 --components-path ./iac/dapr/local --dapr-http-port 3501 --dapr-grpc-port 50001"], + "command": ["scripts/dev-frontend"], "isBackground": true, "dependsOn": "build", "problemMatcher": [ @@ -72,7 +72,7 @@ { "label": "dapr-up-backend", "type": "shell", - "command": [ "dapr run --app-id backend --app-port 5000 --components-path ./iac/dapr/local --dapr-http-port 3502 --dapr-grpc-port 50002"], + "command": ["scripts/dev-backend"], "isBackground": true, "dependsOn": "build", "problemMatcher": [ @@ -102,4 +102,4 @@ } } ] -} \ No newline at end of file +} diff --git a/scripts/dev b/scripts/dev new file mode 100755 index 0000000..f4d9813 --- /dev/null +++ b/scripts/dev @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +set -e + +lsof -ti :5114,5000 | xargs kill || true + +dotnet watch --project "$(dirname "$0")/../src/frontend/PetSpotR/PetSpotR.csproj" run & +$(dirname "$0")/dev-backend & +$(dirname "$0")/dev-frontend & + +wait diff --git a/scripts/dev-backend b/scripts/dev-backend new file mode 100755 index 0000000..7b6af7e --- /dev/null +++ b/scripts/dev-backend @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +dapr run --app-id backend --app-port 5000 --components-path ./iac/dapr/local --dapr-http-port 3502 --dapr-grpc-port 50002 diff --git a/scripts/dev-frontend b/scripts/dev-frontend new file mode 100755 index 0000000..5e4ba01 --- /dev/null +++ b/scripts/dev-frontend @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -e + +dapr run --app-id frontend --app-port 5114 --components-path ./iac/dapr/local --dapr-http-port 3501 --dapr-grpc-port 50001 From e9d917481ef4258f7a2f4484df999d2e08384ed6 Mon Sep 17 00:00:00 2001 From: Marais Rossouw Date: Wed, 21 Aug 2024 11:27:10 +1000 Subject: [PATCH 2/7] chore: setup the codebase with this script too --- .devcontainer/devcontainer.json | 1 + .devcontainer/on-setup.sh | 7 +------ scripts/setup | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) mode change 100644 => 100755 .devcontainer/on-setup.sh create mode 100755 scripts/setup diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ca8b37a..6c52f8c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -14,6 +14,7 @@ // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers/features/python:1": {}, + "ghcr.io/devcontainers/features/node:1": {}, "ghcr.io/devcontainers/features/docker-in-docker:2": {} }, diff --git a/.devcontainer/on-setup.sh b/.devcontainer/on-setup.sh old mode 100644 new mode 100755 index 76e7d8d..0b3a24d --- a/.devcontainer/on-setup.sh +++ b/.devcontainer/on-setup.sh @@ -3,10 +3,5 @@ wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O # Initialize dapr dapr uninstall --all # clean if needed -dapr init -# Install python dependencies -pip install -r ./src/backend/requirements.txt - -# dotnet restore -dotnet restore ./src/frontend/PetSpotR/PetSpotR.csproj +scripts/setup diff --git a/scripts/setup b/scripts/setup new file mode 100755 index 0000000..e9db221 --- /dev/null +++ b/scripts/setup @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -e + +dapr init + +# Install python dependencies +pip install -r ./src/backend/requirements.txt + +# dotnet restore +dotnet restore ./src/frontend/PetSpotR/PetSpotR.csproj + +# install playwright browsers +cd tests/playwright +npm install +npx playwright install --with-deps \ No newline at end of file From 1483783fee8b74a0dc5261b6cbc34b868372b4bd Mon Sep 17 00:00:00 2001 From: Marais Rossouw Date: Wed, 21 Aug 2024 11:27:32 +1000 Subject: [PATCH 3/7] chore: update playwright --- tests/playwright/package-lock.json | 99 +++++++++++++++++++++--------- tests/playwright/package.json | 2 +- 2 files changed, 70 insertions(+), 31 deletions(-) diff --git a/tests/playwright/package-lock.json b/tests/playwright/package-lock.json index 11bdfe6..d6a6f46 100644 --- a/tests/playwright/package-lock.json +++ b/tests/playwright/package-lock.json @@ -9,65 +9,104 @@ "version": "1.0.0", "license": "ISC", "devDependencies": { - "@playwright/test": "^1.30.0" + "@playwright/test": "^1.46.1" } }, "node_modules/@playwright/test": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.30.0.tgz", - "integrity": "sha512-SVxkQw1xvn/Wk/EvBnqWIq6NLo1AppwbYOjNLmyU0R1RoQ3rLEBtmjTnElcnz8VEtn11fptj1ECxK0tgURhajw==", + "version": "1.46.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.46.1.tgz", + "integrity": "sha512-Fq6SwLujA/DOIvNC2EL/SojJnkKf/rAwJ//APpJJHRyMi1PdKrY3Az+4XNQ51N4RTbItbIByQ0jgd1tayq1aeA==", "dev": true, + "license": "Apache-2.0", "dependencies": { - "@types/node": "*", - "playwright-core": "1.30.0" + "playwright": "1.46.1" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=14" + "node": ">=18" } }, - "node_modules/@types/node": { - "version": "18.11.18", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz", - "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==", - "dev": true + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } }, - "node_modules/playwright-core": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.30.0.tgz", - "integrity": "sha512-7AnRmTCf+GVYhHbLJsGUtskWTE33SwMZkybJ0v6rqR1boxq2x36U7p1vDRV7HO2IwTZgmycracLxPEJI49wu4g==", + "node_modules/playwright": { + "version": "1.46.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.46.1.tgz", + "integrity": "sha512-oPcr1yqoXLCkgKtD5eNUPLiN40rYEM39odNpIb6VE6S7/15gJmA1NzVv6zJYusV0e7tzvkU/utBFNa/Kpxmwng==", "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.46.1" + }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=14" + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.46.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.46.1.tgz", + "integrity": "sha512-h9LqIQaAv+CYvWzsZ+h3RsrqCStkBHlgo6/TJlFst3cOTlLghBQlJwPOZKQJTKNaD3QIB7aAVQ+gfWbN3NXB7A==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" } } }, "dependencies": { "@playwright/test": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.30.0.tgz", - "integrity": "sha512-SVxkQw1xvn/Wk/EvBnqWIq6NLo1AppwbYOjNLmyU0R1RoQ3rLEBtmjTnElcnz8VEtn11fptj1ECxK0tgURhajw==", + "version": "1.46.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.46.1.tgz", + "integrity": "sha512-Fq6SwLujA/DOIvNC2EL/SojJnkKf/rAwJ//APpJJHRyMi1PdKrY3Az+4XNQ51N4RTbItbIByQ0jgd1tayq1aeA==", "dev": true, "requires": { - "@types/node": "*", - "playwright-core": "1.30.0" + "playwright": "1.46.1" } }, - "@types/node": { - "version": "18.11.18", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz", - "integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==", - "dev": true + "fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "optional": true + }, + "playwright": { + "version": "1.46.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.46.1.tgz", + "integrity": "sha512-oPcr1yqoXLCkgKtD5eNUPLiN40rYEM39odNpIb6VE6S7/15gJmA1NzVv6zJYusV0e7tzvkU/utBFNa/Kpxmwng==", + "dev": true, + "requires": { + "fsevents": "2.3.2", + "playwright-core": "1.46.1" + } }, "playwright-core": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.30.0.tgz", - "integrity": "sha512-7AnRmTCf+GVYhHbLJsGUtskWTE33SwMZkybJ0v6rqR1boxq2x36U7p1vDRV7HO2IwTZgmycracLxPEJI49wu4g==", + "version": "1.46.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.46.1.tgz", + "integrity": "sha512-h9LqIQaAv+CYvWzsZ+h3RsrqCStkBHlgo6/TJlFst3cOTlLghBQlJwPOZKQJTKNaD3QIB7aAVQ+gfWbN3NXB7A==", "dev": true } } diff --git a/tests/playwright/package.json b/tests/playwright/package.json index 82927f5..bfb7ede 100644 --- a/tests/playwright/package.json +++ b/tests/playwright/package.json @@ -8,6 +8,6 @@ "author": "", "license": "ISC", "devDependencies": { - "@playwright/test": "^1.30.0" + "@playwright/test": "^1.46.1" } } From aaa9e6f979e9b6d3e8c6fd54c71c5a35f7682e8b Mon Sep 17 00:00:00 2001 From: Marais Rossouw Date: Wed, 21 Aug 2024 11:27:54 +1000 Subject: [PATCH 4/7] chore: playwright should take its baseUrl from a config --- tests/playwright/playwright.config.ts | 15 +++++++++------ tests/playwright/tests/homepage.spec.ts | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/playwright/playwright.config.ts b/tests/playwright/playwright.config.ts index 57859e6..2a11b22 100644 --- a/tests/playwright/playwright.config.ts +++ b/tests/playwright/playwright.config.ts @@ -35,8 +35,9 @@ const config: PlaywrightTestConfig = { use: { /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ actionTimeout: 0, + /* Base URL to use in actions like `await page.goto('/')`. */ - // baseURL: 'http://localhost:3000', + baseURL: process.env.TEST_URL ?? `http://localhost:5114/`, /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', @@ -96,12 +97,14 @@ const config: PlaywrightTestConfig = { /* Folder for test artifacts such as screenshots, videos, traces, etc. */ // outputDir: 'test-results/', +}; +if (process.env.TEST_URL?.includes('localhost')) { /* Run your local dev server before starting the tests */ - // webServer: { - // command: 'npm run start', - // port: 3000, - // }, -}; + config.webServer = { + command: '../../scripts/dev', + url: 'http://localhost:5114/' + }; +} export default config; diff --git a/tests/playwright/tests/homepage.spec.ts b/tests/playwright/tests/homepage.spec.ts index 1bf0b21..633d8c5 100644 --- a/tests/playwright/tests/homepage.spec.ts +++ b/tests/playwright/tests/homepage.spec.ts @@ -1,14 +1,14 @@ import { test, expect } from '@playwright/test'; test('has title', async ({ page }) => { - await page.goto('http://app.9e5524d3a2474ae58276.westus3.aksapp.io/'); + await page.goto('/'); // Expect a title "to contain" a substring. await expect(page).toHaveTitle(/PetSpotR/); }); test('get started link', async ({ page }) => { - await page.goto('http://app.9e5524d3a2474ae58276.westus3.aksapp.io/'); + await page.goto('/'); // Click the get started link. await page.getByRole('button', { name: 'I lost my pet' }).click(); From 3b904151d701fabdbc4e762696877e2099370314 Mon Sep 17 00:00:00 2001 From: Marais Rossouw Date: Wed, 21 Aug 2024 11:28:09 +1000 Subject: [PATCH 5/7] chore: run playwright tests in ci with running app --- .github/workflows/playwright.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 3db1ddb..5594e09 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -8,6 +8,11 @@ on: branches: - main workflow_dispatch: + inputs: + url: + description: URL to test + required: false + default: http://localhost:5114/ jobs: test: @@ -19,6 +24,17 @@ jobs: - uses: actions/setup-node@v3 with: node-version: 16 + - name: Cache Playwright Browsers + uses: actions/cache@v2 + with: + path: ~/.cache/ms-playwright + key: ${{ runner.os }}-node-${{ hashFiles('tests/playwright/package.json') }}-${{ hashFiles('tests/playwright/playwright.config.ts') }} + - name: Dapr tool installer + if: ${{ github.event.inputs.url == 'http://localhost:5114/' }} + uses: dapr/setup-dapr@v1 + - name: Setup app locally + if: ${{ github.event.inputs.url == 'http://localhost:5114/' }} + run: scripts/setup - name: Install dependencies run: | cd tests/playwright @@ -28,6 +44,8 @@ jobs: cd tests/playwright npx playwright install --with-deps - name: Run Playwright tests + env: + TEST_URL: ${{ github.event.inputs.url }} run: | cd tests/playwright npx playwright test From f9a71c1810ad8d76a508d129f6ad0492e6618357 Mon Sep 17 00:00:00 2001 From: Marais Rossouw Date: Wed, 21 Aug 2024 11:39:15 +1000 Subject: [PATCH 6/7] chore: the url can be blank in CI --- .github/workflows/playwright.yml | 4 ++-- tests/playwright/playwright.config.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 5594e09..c117849 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -30,10 +30,10 @@ jobs: path: ~/.cache/ms-playwright key: ${{ runner.os }}-node-${{ hashFiles('tests/playwright/package.json') }}-${{ hashFiles('tests/playwright/playwright.config.ts') }} - name: Dapr tool installer - if: ${{ github.event.inputs.url == 'http://localhost:5114/' }} + if: ${{ github.event.inputs.url == 'http://localhost:5114/' || github.event.inputs.url == '' }} uses: dapr/setup-dapr@v1 - name: Setup app locally - if: ${{ github.event.inputs.url == 'http://localhost:5114/' }} + if: ${{ github.event.inputs.url == 'http://localhost:5114/' || github.event.inputs.url == '' }} run: scripts/setup - name: Install dependencies run: | diff --git a/tests/playwright/playwright.config.ts b/tests/playwright/playwright.config.ts index 2a11b22..cfa4d74 100644 --- a/tests/playwright/playwright.config.ts +++ b/tests/playwright/playwright.config.ts @@ -7,6 +7,8 @@ import { devices } from '@playwright/test'; */ // require('dotenv').config(); +const test_url = process.env.TEST_URL?.trim() || undefined; + /** * See https://playwright.dev/docs/test-configuration. */ @@ -37,7 +39,7 @@ const config: PlaywrightTestConfig = { actionTimeout: 0, /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: process.env.TEST_URL ?? `http://localhost:5114/`, + baseURL: test_url ?? `http://localhost:5114/`, /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ trace: 'on-first-retry', @@ -99,7 +101,7 @@ const config: PlaywrightTestConfig = { // outputDir: 'test-results/', }; -if (process.env.TEST_URL?.includes('localhost')) { +if (test_url?.includes('localhost')) { /* Run your local dev server before starting the tests */ config.webServer = { command: '../../scripts/dev', From fa9f74dd4dc99e8d479b79bcc481368afe97b253 Mon Sep 17 00:00:00 2001 From: Marais Rossouw Date: Wed, 21 Aug 2024 11:44:05 +1000 Subject: [PATCH 7/7] chore: log some of the testing urls --- .github/workflows/playwright.yml | 10 +++++----- tests/playwright/playwright.config.ts | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index c117849..236f0e6 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,5 +1,4 @@ name: Playwright Tests - on: push: branches: @@ -14,6 +13,9 @@ on: required: false default: http://localhost:5114/ +env: + TEST_URL: ${{ github.event.inputs.url || 'http://localhost:5114/' }} + jobs: test: name: Run Playwright tests @@ -30,10 +32,10 @@ jobs: path: ~/.cache/ms-playwright key: ${{ runner.os }}-node-${{ hashFiles('tests/playwright/package.json') }}-${{ hashFiles('tests/playwright/playwright.config.ts') }} - name: Dapr tool installer - if: ${{ github.event.inputs.url == 'http://localhost:5114/' || github.event.inputs.url == '' }} + if: ${{ env.TEST_URL == 'http://localhost:5114/' }} uses: dapr/setup-dapr@v1 - name: Setup app locally - if: ${{ github.event.inputs.url == 'http://localhost:5114/' || github.event.inputs.url == '' }} + if: ${{ env.TEST_URL == 'http://localhost:5114/'}} run: scripts/setup - name: Install dependencies run: | @@ -44,8 +46,6 @@ jobs: cd tests/playwright npx playwright install --with-deps - name: Run Playwright tests - env: - TEST_URL: ${{ github.event.inputs.url }} run: | cd tests/playwright npx playwright test diff --git a/tests/playwright/playwright.config.ts b/tests/playwright/playwright.config.ts index cfa4d74..c0bd824 100644 --- a/tests/playwright/playwright.config.ts +++ b/tests/playwright/playwright.config.ts @@ -9,6 +9,10 @@ import { devices } from '@playwright/test'; const test_url = process.env.TEST_URL?.trim() || undefined; +if (test_url) { + console.log(`Testing against ${test_url}`); +} + /** * See https://playwright.dev/docs/test-configuration. */