From cbc5350035eab09d3ae0b1b7622c7dd7abea5493 Mon Sep 17 00:00:00 2001 From: Hans Christian Winther-Sorensen Date: Sat, 20 Apr 2024 14:19:25 +0200 Subject: [PATCH] TEST-1234 Add configuration and updated workflow --- .github/workflows/playwright.yml | 49 ++++++++++++++------------ .vscode/settings.json | 7 +++- tests/playwright/eslint.config.mjs | 20 ++++++++--- tests/playwright/package.json | 1 + tests/playwright/tests/example.spec.ts | 2 ++ tests/playwright/tsconfig.json | 10 ++++++ 6 files changed, 62 insertions(+), 27 deletions(-) create mode 100644 tests/playwright/tsconfig.json diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 46ed93fe..8c460833 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -51,16 +51,19 @@ jobs: name: Setup node with: node-version: ${{ env.NODE_VERSION }} - cache: "npm" - cache-dependency-path: "${{ env.PLAYWRIGHT_PATH }}/package-lock.json" + cache: "yarn" + cache-dependency-path: "${{ env.PLAYWRIGHT_PATH }}/yarn.lock" + # cache: "npm" + # cache-dependency-path: "${{ env.PLAYWRIGHT_PATH }}/package-lock.json" - name: Install dependencies - run: npm ci + run: yarn install --immutable --immutable-cache --check-cache # yarn install --frozen-lockfile # npm ci - name: Build - id: npm-build + id: node-build run: | - npm run build 1>build.out 2>&1 || (exit 0) + yarn build 1>build.out 2>&1 || (exit 0) + # npm run build 1>build.out 2>&1 || (exit 0) grep "): error " build.out > build.err || (exit 0) if [ ! -s build.err ] @@ -96,37 +99,38 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} comment-identifier: "${{ env.WORKFLOW_SHORT_NAME }}-build-results" - comment-content: ${{ steps.npm-build.outputs.result }} + comment-content: ${{ steps.node-build.outputs.result }} - name: Lint if: always() - id: yarn-lint + id: node-lint run: | - (npm run lint -- -f compact | grep ": line " | sed -e 's|${{ env.TRAILING_AGENT_WORK_PATH }}||') 1>yarn-lint.err 2>&1 || (exit 0) + (yarn lint -- -f compact | grep ": line " | sed -e 's|${{ env.TRAILING_AGENT_WORK_PATH }}||') 1>lint.err 2>&1 || (exit 0) + # (npm run lint -- -f compact | grep ": line " | sed -e 's|${{ env.TRAILING_AGENT_WORK_PATH }}||') 1>lint.err 2>&1 || (exit 0) - if [ ! -s yarn-lint.err ] + if [ ! -s lint.err ] then - echo "## ✅ No linting issues 🎊" > yarn-lint.md + echo "## ✅ No linting issues 🎊" > lint.md else # Reformat lint output as github error annotations error_regex="(.+): line ([0-9]+), col [0-9]+, [A-Za-z]+ - (.+)" - cat yarn-lint.err | while read line + cat lint.err | while read line do if [[ $line =~ $error_regex ]]; then echo "::error file=${BASH_REMATCH[1]},line=${BASH_REMATCH[2]}::${BASH_REMATCH[3]}" fi done - cp yarn-lint.err yarn-lint.md - sed -i '/^$/d' yarn-lint.md # removes empty lines - sed -i -e 's/^/- ❌ /' yarn-lint.md # prefix with markdown list item and cross mark emoji - echo "## ❌ The following linting issues should be fixed:" | cat - yarn-lint.md > yarn-lint.md.temp && mv yarn-lint.md.temp yarn-lint.md + cp lint.err lint.md + sed -i '/^$/d' lint.md # removes empty lines + sed -i -e 's/^/- ❌ /' lint.md # prefix with markdown list item and cross mark emoji + echo "## ❌ The following linting issues should be fixed:" | cat - lint.md > lint.md.temp && mv lint.md.temp lint.md fi - echo "result<> $GITHUB_OUTPUT - cat yarn-lint.md >> $GITHUB_STEP_SUMMARY + echo "result<> $GITHUB_OUTPUT + cat lint.md >> $GITHUB_STEP_SUMMARY - if [ -s yarn-lint.err ] + if [ -s lint.err ] then exit 1 fi @@ -137,7 +141,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} comment-identifier: "${{ env.WORKFLOW_SHORT_NAME }}-lint-results" - comment-content: ${{ steps.yarn-lint.outputs.result }} + comment-content: ${{ steps.node-lint.outputs.result }} run-e2e-tests: runs-on: ubuntu-latest @@ -180,9 +184,9 @@ jobs: with: path: ~/.cache/ms-playwright key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.PLAYWRIGHT_VERSION }} - - run: npx playwright install --with-deps + - run: yarn playwright install --with-deps # npx playwright install --with-deps if: steps.playwright-cache.outputs.cache-hit != 'true' - - run: npx playwright install-deps + - run: yarn playwright install-deps # npx playwright install-deps if: steps.playwright-cache.outputs.cache-hit != 'true' - name: Run Playwright tests @@ -192,7 +196,8 @@ jobs: run: | echo "Using BASIL_URL: $BASIL_URL" echo "Using BASIL_API_URL: $BASIL_API_URL" - npx playwright test + yarn playwright test + # npx playwright test - uses: daun/playwright-report-summary@v3 if: ${{ (github.event_name == 'pull_request' || github.event_name == 'pull_request_target' || github.event_name == 'push') && always() }} diff --git a/.vscode/settings.json b/.vscode/settings.json index ad92582b..fa799d74 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,8 @@ { - "editor.formatOnSave": true + "editor.formatOnType": false, + "editor.formatOnPaste": true, + "editor.formatOnSave": true, + "editor.formatOnSaveMode": "file", + "files.autoSave": "onFocusChange", // optional but recommended + "explorer.fileNesting.enabled": true } diff --git a/tests/playwright/eslint.config.mjs b/tests/playwright/eslint.config.mjs index 01b80f5d..8d9f8242 100644 --- a/tests/playwright/eslint.config.mjs +++ b/tests/playwright/eslint.config.mjs @@ -8,15 +8,27 @@ import { FlatCompat } from '@eslint/eslintrc'; import pluginJs from '@eslint/js'; // mimic CommonJS variables -- not needed if using CommonJS -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); +const compatFilename = fileURLToPath(import.meta.url); +const compatDirname = path.dirname(compatFilename); const compat = new FlatCompat({ - baseDirectory: __dirname, + baseDirectory: compatDirname, recommendedConfig: pluginJs.configs.recommended, }); export default [ - { languageOptions: { globals: globals.browser } }, + { + languageOptions: { + globals: globals.browser, + }, + files: ['*.ts'], + ignores: [ + 'node_modules/', + 'playwright-report/', + 'test-results/', + '!tests/*', + '!test-examples/*', + ], + }, ...compat.extends('standard-with-typescript'), pluginReactConfig, eslintConfigPrettier, diff --git a/tests/playwright/package.json b/tests/playwright/package.json index 4e1ff6ca..cca3aeaa 100644 --- a/tests/playwright/package.json +++ b/tests/playwright/package.json @@ -22,6 +22,7 @@ "typescript": "*" }, "scripts": { + "build": "tsc --noEmit", "lint": "eslint \"**/*.{ts,tsx}\"" }, "description": "playwright test project", diff --git a/tests/playwright/tests/example.spec.ts b/tests/playwright/tests/example.spec.ts index 7c90d85c..cde7dafe 100644 --- a/tests/playwright/tests/example.spec.ts +++ b/tests/playwright/tests/example.spec.ts @@ -13,6 +13,8 @@ test('get started link', async ({ page }) => { // Click the get started link. await page.getByRole('link', { name: 'Get started' }).click(); + const s = null; + // Expects page to have a heading with the name of Installation. await expect( page.getByRole('heading', { name: 'Installation' }) diff --git a/tests/playwright/tsconfig.json b/tests/playwright/tsconfig.json new file mode 100644 index 00000000..bee792b0 --- /dev/null +++ b/tests/playwright/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@tests/*": ["tests/*"] + }, + "strictNullChecks": true + }, + "exclude": ["node_modules", "playwright-report", "test-results"] +}