diff --git a/.github/workflows/default_workflow.yml b/.github/workflows/default_workflow.yml index 7a6f1e3df3b3..ca260094c483 100644 --- a/.github/workflows/default_workflow.yml +++ b/.github/workflows/default_workflow.yml @@ -114,11 +114,6 @@ jobs: devextreme-react-playground devextreme-vue-playground - # The project's test target is the whole Playwright suite, so run-many leaves it out. The nx cache - # skips this one unless the tools changed. - - name: Test Playwright tools - run: pnpm exec nx run devextreme-playwright-tests:test-tools - - name: Save nx cache if: github.event_name != 'pull_request' uses: actions/cache/save@v5 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6069ff385acc..db06f6f2a773 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -125,6 +125,10 @@ jobs: working-directory: ./e2e/playwright run: pnpm exec nx type-check + - name: Type-check Playwright tools + working-directory: ./tools/playwright + run: pnpm exec nx type-check + - name: Save nx cache if: github.event_name != 'pull_request' uses: actions/cache/save@v5 diff --git a/.github/workflows/playwright_tests.yml b/.github/workflows/playwright_tests.yml index 16fc7e19a5ab..0302f052a55f 100644 --- a/.github/workflows/playwright_tests.yml +++ b/.github/workflows/playwright_tests.yml @@ -269,7 +269,7 @@ jobs: # The default blob name is built from the test paths only, so jobs that differ by theme or # timezone alone would write the same zip and overwrite each other once merged. PLAYWRIGHT_BLOB_OUTPUT_NAME: report-${{ env.JOB_NAME }}.zip - # tools/flakyReporter.ts stamps every flaky test it records with the job it ran in. + # tools/playwright/flakyReporter.ts stamps every flaky test it records with the job it ran in. FLAKY_REPORT_JOB: ${{ matrix.name }}${{ !matrix.theme && ' - fluent' || '' }} FLAKY_REPORT_COMPONENT_FOLDER: ${{ matrix.componentFolder }} FLAKY_REPORT_BASE_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref || github.ref_name }} @@ -320,7 +320,8 @@ jobs: if-no-files-found: ignore # One folder at repository paths: the new etalons the tests wrote, and the etalons of the failed - # shots that tools/etalonCollector.ts collected. Two paths would be rooted at their common ancestor. + # shots that tools/playwright/etalonCollector.ts collected. Two paths would be rooted at their + # common ancestor. - name: Collect etalons if: ${{ always() }} run: | @@ -415,8 +416,10 @@ jobs: path: ${{ github.workspace }}/playwright-report if-no-files-found: error + # The steps below do not need the HTML report, so they also run after a step above fails: an `if` + # without a status function such as !cancelled() gets an implicit success(). - name: Merge test traces - if: steps.mergeable-artifacts.outputs.traces == 'true' + if: ${{ !cancelled() && steps.mergeable-artifacts.outputs.traces == 'true' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: @@ -426,7 +429,7 @@ jobs: delete-merged: true - name: Merge etalons - if: steps.mergeable-artifacts.outputs.etalons == 'true' + if: ${{ !cancelled() && steps.mergeable-artifacts.outputs.etalons == 'true' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: @@ -435,7 +438,8 @@ jobs: delete-merged: true - name: Download flaky test reports - if: steps.mergeable-artifacts.outputs.flaky == 'true' + id: download-flaky-reports + if: ${{ !cancelled() && steps.mergeable-artifacts.outputs.flaky == 'true' }} uses: actions/download-artifact@v7 with: pattern: playwright-flaky-report-* @@ -443,7 +447,8 @@ jobs: # The file tools/flaky-test-reporter collects from every run of this workflow (repository-check.yml). - name: Build flaky candidates report - if: steps.mergeable-artifacts.outputs.flaky == 'true' + id: build-flaky-candidates + if: ${{ !cancelled() && steps.download-flaky-reports.outcome == 'success' }} run: | mkdir -p artifacts report=artifacts/flaky-candidates.json @@ -464,7 +469,7 @@ jobs: } >> "$GITHUB_STEP_SUMMARY" - name: Upload flaky candidates report - if: steps.mergeable-artifacts.outputs.flaky == 'true' + if: ${{ !cancelled() && steps.build-flaky-candidates.outcome == 'success' }} uses: actions/upload-artifact@v7 with: name: flaky-candidates diff --git a/.github/workflows/visual-tests-demos.yml b/.github/workflows/visual-tests-demos.yml index ae53bf3e65ce..3f40fe0c197d 100644 --- a/.github/workflows/visual-tests-demos.yml +++ b/.github/workflows/visual-tests-demos.yml @@ -533,6 +533,18 @@ jobs: DISPLAY: '' run: pnpm run test-playwright:accessibility + # A test that writes a missing etalon passes (updateSnapshots: 'missing'), so this step fails the job + # and names the new files. It comes before the blob upload, which runs only after a failure. + - name: Fail on new etalons + if: always() && matrix.STRATEGY == 'screenshots' + run: | + new_etalons=$(git ls-files --others --exclude-standard -- 'apps/demos/testing/*etalons/*.png') + if [ -n "$new_etalons" ]; then + echo "::error::The tests wrote etalons that are not in the repository. They are in the playwright-etalons-jquery artifact:" + echo "$new_etalons" + exit 1 + fi + - name: Upload Playwright blob report if: failure() uses: actions/upload-artifact@v7 @@ -549,32 +561,25 @@ jobs: path: ${{ github.workspace }}/apps/demos/testing/artifacts/playwright/test-results if-no-files-found: ignore - - name: Collect new etalons + # One folder at repository paths: the new etalons the tests wrote, and the etalons of the failed + # shots that tools/playwright/etalonCollector.ts collected. + - name: Collect etalons if: always() && matrix.STRATEGY == 'screenshots' run: | - mkdir -p "$RUNNER_TEMP/new-etalons" + mkdir -p "$RUNNER_TEMP/etalons" git ls-files --others --exclude-standard -z -- 'apps/demos/testing/*etalons/*.png' \ - | xargs -0 -r cp --parents -t "$RUNNER_TEMP/new-etalons" + | xargs -0 -r cp --parents -t "$RUNNER_TEMP/etalons" + collected=apps/demos/testing/artifacts/playwright/collected-etalons + if [ -d "$collected" ]; then cp -R "$collected/." "$RUNNER_TEMP/etalons"; fi - - name: Upload new etalons + - name: Upload etalons if: always() && matrix.STRATEGY == 'screenshots' uses: actions/upload-artifact@v7 with: name: playwright-etalons-${{ env.PLAYWRIGHT_JOB_NAME }} - path: ${{ runner.temp }}/new-etalons + path: ${{ runner.temp }}/etalons if-no-files-found: ignore - # A retry passes against the etalon its first attempt wrote, so new etalons fail the job here. - - name: Fail on new etalons - if: always() && matrix.STRATEGY == 'screenshots' - run: | - new_etalons=$(git ls-files --others --exclude-standard -- 'apps/demos/testing/*etalons/*.png') - if [ -n "$new_etalons" ]; then - echo "::error::The tests wrote etalons that are not in the repository. They are in the playwright-etalons artifact:" - echo "$new_etalons" - exit 1 - fi - - name: Sanitize job name if: ${{ failure() }} run: echo "JOB_NAME=$(echo "${{ matrix.CONSTEL }}-${{ matrix.THEME }}" | tr '/' '-')" >> $GITHUB_ENV @@ -735,6 +740,20 @@ jobs: PLAYWRIGHT_BLOB_OUTPUT_NAME: report-${{ env.PLAYWRIGHT_JOB_NAME }}.zip run: pnpm run test-playwright + # A test that writes a missing etalon passes (updateSnapshots: 'missing'), so this step fails the job + # and names the new files. It comes before the blob upload, which runs only after a failure. + - name: Fail on new etalons + if: always() + env: + CONSTEL: ${{ matrix.CONSTEL }} + run: | + new_etalons=$(git ls-files --others --exclude-standard -- 'apps/demos/testing/*etalons/*.png') + if [ -n "$new_etalons" ]; then + echo "::error::The tests wrote etalons that are not in the repository. They are in the playwright-etalons-${CONSTEL%%(*} artifact:" + echo "$new_etalons" + exit 1 + fi + - name: Upload Playwright blob report if: failure() uses: actions/upload-artifact@v7 @@ -751,32 +770,25 @@ jobs: path: ${{ github.workspace }}/apps/demos/testing/artifacts/playwright/test-results if-no-files-found: ignore - - name: Collect new etalons + # One folder at repository paths: the new etalons the tests wrote, and the etalons of the failed + # shots that tools/playwright/etalonCollector.ts collected. + - name: Collect etalons if: always() run: | - mkdir -p "$RUNNER_TEMP/new-etalons" + mkdir -p "$RUNNER_TEMP/etalons" git ls-files --others --exclude-standard -z -- 'apps/demos/testing/*etalons/*.png' \ - | xargs -0 -r cp --parents -t "$RUNNER_TEMP/new-etalons" + | xargs -0 -r cp --parents -t "$RUNNER_TEMP/etalons" + collected=apps/demos/testing/artifacts/playwright/collected-etalons + if [ -d "$collected" ]; then cp -R "$collected/." "$RUNNER_TEMP/etalons"; fi - - name: Upload new etalons + - name: Upload etalons if: always() uses: actions/upload-artifact@v7 with: name: playwright-etalons-${{ env.PLAYWRIGHT_JOB_NAME }} - path: ${{ runner.temp }}/new-etalons + path: ${{ runner.temp }}/etalons if-no-files-found: ignore - # A retry passes against the etalon its first attempt wrote, so new etalons fail the job here. - - name: Fail on new etalons - if: always() - run: | - new_etalons=$(git ls-files --others --exclude-standard -- 'apps/demos/testing/*etalons/*.png') - if [ -n "$new_etalons" ]; then - echo "::error::The tests wrote etalons that are not in the repository. They are in the playwright-etalons artifact:" - echo "$new_etalons" - exit 1 - fi - merge-artifacts: runs-on: ubuntu-latest timeout-minutes: 6 @@ -799,7 +811,10 @@ jobs: const artifactGroups = { blobs: /^playwright-blob-/, traces: /^playwright-traces-/, - etalons: /^playwright-etalons-/, + etalons_jquery: /^playwright-etalons-jquery\(/, + etalons_react: /^playwright-etalons-react\(/, + etalons_vue: /^playwright-etalons-vue\(/, + etalons_angular: /^playwright-etalons-angular\(/, }; for (const [outputName, pattern] of Object.entries(artifactGroups)) { @@ -853,8 +868,10 @@ jobs: path: ${{ github.workspace }}/playwright-report if-no-files-found: error + # The steps below do not need the HTML report, so they also run after a step above fails: an `if` + # without a status function such as !cancelled() gets an implicit success(). - name: Merge Playwright traces - if: steps.playwright-artifacts.outputs.traces == 'true' + if: ${{ !cancelled() && steps.playwright-artifacts.outputs.traces == 'true' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: @@ -863,17 +880,46 @@ jobs: separate-directories: true delete-merged: true - - name: Merge new etalons - if: steps.playwright-artifacts.outputs.etalons == 'true' + # One etalon serves every framework of a demo, so each framework gets its own artifact: merged + # together, a framework that renders differently would overwrite another's picture. + - name: Merge jQuery etalons + if: ${{ !cancelled() && steps.playwright-artifacts.outputs.etalons_jquery == 'true' }} + uses: actions/upload-artifact/merge@v7 + continue-on-error: true + with: + name: playwright-etalons-jquery + pattern: playwright-etalons-jquery(* + delete-merged: true + + - name: Merge React etalons + if: ${{ !cancelled() && steps.playwright-artifacts.outputs.etalons_react == 'true' }} + uses: actions/upload-artifact/merge@v7 + continue-on-error: true + with: + name: playwright-etalons-react + pattern: playwright-etalons-react(* + delete-merged: true + + - name: Merge Vue etalons + if: ${{ !cancelled() && steps.playwright-artifacts.outputs.etalons_vue == 'true' }} + uses: actions/upload-artifact/merge@v7 + continue-on-error: true + with: + name: playwright-etalons-vue + pattern: playwright-etalons-vue(* + delete-merged: true + + - name: Merge Angular etalons + if: ${{ !cancelled() && steps.playwright-artifacts.outputs.etalons_angular == 'true' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: - name: playwright-etalons - pattern: playwright-etalons-* + name: playwright-etalons-angular + pattern: playwright-etalons-angular(* delete-merged: true - name: Merge jQuery accessibility reports - if: needs.playwright-jquery.result == 'failure' + if: ${{ !cancelled() && needs.playwright-jquery.result == 'failure' }} uses: actions/upload-artifact/merge@v7 continue-on-error: true with: diff --git a/apps/demos/README.md b/apps/demos/README.md index 433a4e62c106..3b8692987543 100644 --- a/apps/demos/README.md +++ b/apps/demos/README.md @@ -157,18 +157,25 @@ done `--grep` takes test names, `-`, which also select the widget tests of that demo; without it every jQuery demo and widget test runs, about ten minutes per theme. Record etalons from the jQuery demos only; check a framework against them with `CONSTEL=react` (or `vue`, `angular`) and without `--update-snapshots`. The first run builds the image and takes a few minutes more. The second loop compares as CI does: exactly. +A verify run that fails has already collected the picture of every shot that failed the same way in both attempts into `testing/artifacts/playwright/collected-etalons`, and prints the command that applies them. The next run empties the folder, so apply it after each theme: + +``` +THEME=fluent.blue.light utils/visual-tests/playwright/docker/run.sh --grep DataGrid-Overview +pnpm run apply-etalons testing/artifacts/playwright/collected-etalons/apps +``` + The repository is mounted case-insensitively on macOS: a file that a demo requests in the wrong case loads in the container and is missing on CI. ### Etalons from CI -Without a container CI records the etalon: delete the file and push. The job fails on the missing etalon and uploads what it rendered: +A failed run collects the etalons too: the picture of every shot that failed the same way in both attempts, and the new etalons the tests wrote (delete an etalon and push to have CI record it; the job fails on it). Each framework gets its own artifact: `playwright-etalons-jquery`, `-react`, `-vue` and `-angular`. One etalon serves all frameworks of a demo, so apply the jQuery one; the others show what a framework renders, which matters when it differs from jQuery. Download the artifact outside the repository and apply its `apps` folder from `apps/demos`: ``` -gh run download -n playwright-etalons -D ci-etalons -cp -R ci-etalons/. ../.. # from apps/demos: the paths start at the repository root +gh run download -n playwright-etalons-jquery -D ~/Downloads/playwright-etalons-jquery- +pnpm run apply-etalons ~/Downloads/playwright-etalons-jquery-/apps ``` -Look at the image before you commit it. One etalon serves all frameworks of a demo. +The script writes only PNG files at an etalon path of this checkout and prints what it replaced, created, found up to date or did not apply. Look at the images before you commit them. A failed shot that was not collected is listed in the job summary with the reason; "Update etalons" in `e2e/playwright/README.md` explains the reasons. ### Files next to a demo diff --git a/apps/demos/package.json b/apps/demos/package.json index 932b460b9dd5..6e88209014b8 100644 --- a/apps/demos/package.json +++ b/apps/demos/package.json @@ -138,6 +138,7 @@ "lint": "pnpm exec nx run-many -t lint-js lint-demos lint-css lint-html -p devextreme-demos", "test-playwright": "playwright test", "test-playwright:accessibility": "playwright test --config playwright.accessibility.config.ts", + "apply-etalons": "node ../../tools/playwright/apply-etalons.mjs", "build-vendor-bundles": "node utils/server/build-vendor-bundles.js", "fix-lint": "prettier --write . && eslint --fix . && stylelint **/*.{css,vue} --fix", "prettier": "prettier", diff --git a/apps/demos/playwright.config.ts b/apps/demos/playwright.config.ts index 8eef02a0d087..28f2cee5e900 100644 --- a/apps/demos/playwright.config.ts +++ b/apps/demos/playwright.config.ts @@ -50,9 +50,20 @@ export default defineConfig({ fullyParallel: true, forbidOnly: !!process.env.CI, retries: process.env.CI ? 1 : 0, + // Playwright's default fails a test that writes a missing etalon and skips its retry, so the + // collector could not take the test's changed etalons in the same run. The job still fails on + // the new etalon. + updateSnapshots: process.env.CI ? 'missing' : undefined, workers: process.env.CONCURRENCY ? Number(process.env.CONCURRENCY) : undefined, reporter: process.env.CI - ? [['list'], ['blob', { outputDir: './testing/artifacts/playwright/blob-report' }]] + ? [ + ['list'], + ['blob', { outputDir: './testing/artifacts/playwright/blob-report' }], + ['../../tools/playwright/etalonCollector.ts', { + outputDir: './testing/artifacts/playwright/collected-etalons', + repositoryRoot: '../..', + }], + ] : [['list']], timeout: 60000, expect: { diff --git a/e2e/playwright/README.md b/e2e/playwright/README.md index 5a64ec861c79..1817ac3b2246 100644 --- a/e2e/playwright/README.md +++ b/e2e/playwright/README.md @@ -160,7 +160,9 @@ pnpm run apply-etalons The script writes only PNG files at an etalon path of this checkout and prints what it replaced, created, found up to date or did not apply. Look through the changes before committing them — an -etalon is only as right as the render it captured. +etalon is only as right as the render it captured. The collector and the script live in +`tools/playwright`, shared with the demo screenshot tests; apply their `apps` folder from +`apps/demos` (see `apps/demos/README.md`). A failed shot that was not collected is named with the reason, in the output of a local run and in the job summary on CI: @@ -312,7 +314,7 @@ in [Flaky tests](#flaky-tests). A test that passes only on its retry is flaky. It does not fail the job, but it is not forgotten either: -- the job annotates it ("Flaky test"), and `tools/flakyReporter.ts` records it; +- the job annotates it ("Flaky test"), and `tools/playwright/flakyReporter.ts` records it; - the run summary lists the flaky tests of every job, and the run keeps them in its `flaky-candidates` artifact; - `repository-check.yml` adds those up over 72 hours in the repository monitor issue, the tests that diff --git a/e2e/playwright/eslint.config.mjs b/e2e/playwright/eslint.config.mjs index a7f681014b92..ee2b81fefd94 100644 --- a/e2e/playwright/eslint.config.mjs +++ b/e2e/playwright/eslint.config.mjs @@ -73,9 +73,6 @@ export default [ ignores: [ 'playwright.config.ts', 'tests/scheduler/**/*.ts', - // The tools and their self-tests: the rules are for tests, and a nested Playwright run needs more - // than the default timeout. - 'tools/**', ], rules: { 'no-restricted-syntax': ['error', { diff --git a/e2e/playwright/package.json b/e2e/playwright/package.json index e82411eb7c4c..e42c71372b4a 100644 --- a/e2e/playwright/package.json +++ b/e2e/playwright/package.json @@ -3,8 +3,7 @@ "version": "26.2.2", "scripts": { "test": "node ./runner.mjs", - "test:tools": "playwright test -c tools/playwright.config.ts", - "apply-etalons": "node tools/apply-etalons.mjs", + "apply-etalons": "node ../../tools/playwright/apply-etalons.mjs", "lint": "eslint", "type-check": "tsc --noEmit -p tsconfig.json" }, diff --git a/e2e/playwright/playwright.config.ts b/e2e/playwright/playwright.config.ts index 38d3062f1e68..a5918d89b9f8 100644 --- a/e2e/playwright/playwright.config.ts +++ b/e2e/playwright/playwright.config.ts @@ -38,8 +38,8 @@ export default defineConfig({ ['list'], ['blob', { outputDir: './artifacts/blob-report' }], // Before the flaky reporter: its annotations share the step's limit of 10 warnings. - ['./tools/etalonCollector.ts', { outputDir: './artifacts/collected-etalons', repositoryRoot: '../..' }], - ['./tools/flakyReporter.ts', { outputFile: './artifacts/flaky-report.json' }], + ['../../tools/playwright/etalonCollector.ts', { outputDir: './artifacts/collected-etalons', repositoryRoot: '../..' }], + ['../../tools/playwright/flakyReporter.ts', { outputFile: './artifacts/flaky-report.json', defaultTheme: DEFAULT_THEME }], ] : [['list']], timeout: 60000, diff --git a/e2e/playwright/project.json b/e2e/playwright/project.json index dad9a55c3208..74b33a51bf03 100644 --- a/e2e/playwright/project.json +++ b/e2e/playwright/project.json @@ -34,24 +34,13 @@ "{projectRoot}/helpers/**/*", "{projectRoot}/models/**/*", "{projectRoot}/tests/**/*", - "{projectRoot}/tools/**/*", + "{workspaceRoot}/tools/playwright/**/*", "{projectRoot}/fixtures.ts", "{projectRoot}/playwright.config.ts", "{projectRoot}/runner.mjs", "{projectRoot}/serve.mjs", "{projectRoot}/tsconfig.json" ] - }, - "test-tools": { - "executor": "nx:run-script", - "cache": true, - "options": { - "script": "test:tools" - }, - "inputs": [ - "{projectRoot}/tools/**/*", - "{projectRoot}/package.json" - ] } }, "tags": [] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8d6bbc67de65..dcd4bcd35e21 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1946,6 +1946,42 @@ importers: specifier: catalog:tools version: 5.9.3 + tools/playwright: + devDependencies: + '@eslint/js': + specifier: 'catalog:' + version: 10.0.1(eslint@10.14.0(jiti@2.6.1)) + '@playwright/test': + specifier: 'catalog:' + version: 1.65.1 + '@stylistic/eslint-plugin': + specifier: 'catalog:' + version: 5.10.0(eslint@10.14.0(jiti@2.6.1)) + '@types/node': + specifier: catalog:tools + version: 20.19.37 + '@typescript-eslint/eslint-plugin': + specifier: 'catalog:' + version: 8.72.1(@typescript-eslint/parser@8.72.1(eslint@10.14.0(jiti@2.6.1))(typescript@5.8.3))(eslint@10.14.0(jiti@2.6.1))(typescript@5.8.3) + '@typescript-eslint/parser': + specifier: 'catalog:' + version: 8.72.1(eslint@10.14.0(jiti@2.6.1))(typescript@5.8.3) + eslint: + specifier: 'catalog:' + version: 10.14.0(jiti@2.6.1) + eslint-config-devextreme: + specifier: 'catalog:' + version: 2.0.2(a914e8db04ee3fa528d40cfecd7d6991) + eslint-plugin-import: + specifier: 'catalog:' + version: 2.32.0(@typescript-eslint/parser@8.72.1(eslint@10.14.0(jiti@2.6.1))(typescript@5.8.3))(eslint@10.14.0(jiti@2.6.1)) + eslint-plugin-no-only-tests: + specifier: 'catalog:' + version: 3.3.0 + typescript: + specifier: 5.8.3 + version: 5.8.3 + packages: '@adobe/css-tools@4.4.4': diff --git a/tools/playwright/.gitignore b/tools/playwright/.gitignore new file mode 100644 index 000000000000..d4f588edfef5 --- /dev/null +++ b/tools/playwright/.gitignore @@ -0,0 +1 @@ +artifacts/ diff --git a/e2e/playwright/tools/apply-etalons.mjs b/tools/playwright/apply-etalons.mjs similarity index 81% rename from e2e/playwright/tools/apply-etalons.mjs rename to tools/playwright/apply-etalons.mjs index 685f1c26032f..b0972e6d3dd5 100644 --- a/e2e/playwright/tools/apply-etalons.mjs +++ b/tools/playwright/apply-etalons.mjs @@ -1,17 +1,21 @@ -// Applies an e2e folder of etalons, each at its path in the repository's e2e/, to this checkout: a -// container run's collected etalons or the unpacked playwright-etalons artifact. A PR run controls -// what it uploads, so the folder is untrusted: only regular PNG files with printable ASCII names at an etalon path -// of this checkout are written, every file is checked before any is written, and nothing from the -// folder is run. +// Applies an e2e or apps folder of etalons, each at its path in the repository's e2e/ or apps/ (the +// demos), to this checkout: a container run's collected etalons or the unpacked playwright-etalons +// artifact. A PR run controls what it uploads, so the folder is untrusted: only regular PNG files +// with printable ASCII names at an etalon path of this checkout are written, every file is checked +// before any is written, and nothing from the folder is run. import fs from 'node:fs'; import path from 'node:path'; import process from 'node:process'; import { fileURLToPath } from 'node:url'; -const USAGE = 'Usage: pnpm run apply-etalons '; +const USAGE = 'Usage: pnpm run apply-etalons '; // The checkout this script belongs to, whatever the current folder. -const CHECKOUT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../..'); -const PREFIX = ['e2e', 'playwright', 'tests']; +const CHECKOUT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..'); +// The test folders, with how many folders lie between a test folder and its etalons at least. +const TEST_FOLDERS = [ + { prefix: ['e2e', 'playwright', 'tests'], minDepth: 1 }, + { prefix: ['apps', 'demos', 'testing'], minDepth: 0 }, +]; const ETALONS = 'etalons'; const NOT_ETALON_PATH = 'not an etalon path in the checkout'; @@ -27,6 +31,10 @@ const ASCII_NAME = /^[\x20-\x7e]+$/; // must not pass for another's escape: the backslash is escaped too. const printable = (text) => text.replace(/[^\x20-\x7e]|\\/gu, (char) => `\\u{${char.codePointAt(0).toString(16)}}`); +// The folder stands for a top folder of the repository, whatever its name (Finder unpacks a second +// copy of the artifact as `e2e 2`): apps/ when it holds demos/, e2e/ otherwise. +const topFolderOf = (name) => (TEST_FOLDERS.find(({ prefix }) => prefix[1] === name) ?? TEST_FOLDERS[0]).prefix[0]; + const byPath = (a, b) => { if (a.relative === b.relative) { return 0; @@ -44,18 +52,17 @@ function walk(folder) { if (entry.isDirectory()) { visit(path.join(dir, entry.name), entrySegments); } else if (entry.name.endsWith('.png')) { + const repositorySegments = [topFolderOf(entrySegments[0]), ...entrySegments]; found.push({ - segments: entrySegments, - relative: entrySegments.join('/'), + segments: repositorySegments, + relative: repositorySegments.join('/'), source: path.join(dir, entry.name), regular: entry.isFile(), }); } }); }; - // The folder stands for the repository's e2e/, whatever its name: Finder unpacks a second copy - // of the artifact as `e2e 2`. - visit(folder, [PREFIX[0]]); + visit(folder, []); return found.sort(byPath); } @@ -82,11 +89,11 @@ function createPlacer() { return { reason: NOT_ASCII }; } const etalonsIndex = segments.length - 2; - const isEtalonPath = etalonsIndex > PREFIX.length - && PREFIX.every((segment, index) => segments[index] === segment) - && segments.slice(PREFIX.length, etalonsIndex).every((segment) => segment !== ETALONS) - && segments[etalonsIndex] === ETALONS - && segments[etalonsIndex + 1] !== '.png'; + const isEtalonPath = segments[etalonsIndex] === ETALONS + && segments[etalonsIndex + 1] !== '.png' + && TEST_FOLDERS.some(({ prefix, minDepth }) => etalonsIndex >= prefix.length + minDepth + && prefix.every((segment, index) => segments[index] === segment) + && segments.slice(prefix.length, etalonsIndex).every((segment) => segment !== ETALONS)); if (!isEtalonPath) { return { reason: NOT_ETALON_PATH }; } diff --git a/e2e/playwright/tools/applyEtalons.spec.ts b/tools/playwright/applyEtalons.spec.ts similarity index 89% rename from e2e/playwright/tools/applyEtalons.spec.ts rename to tools/playwright/applyEtalons.spec.ts index 1e42e0eb872c..26a48c528276 100644 --- a/e2e/playwright/tools/applyEtalons.spec.ts +++ b/tools/playwright/applyEtalons.spec.ts @@ -6,9 +6,11 @@ import os from 'node:os'; import path from 'node:path'; import { expect, test } from '@playwright/test'; -const SCRIPT = 'e2e/playwright/tools/apply-etalons.mjs'; +const SCRIPT = 'tools/playwright/apply-etalons.mjs'; const GRID = 'e2e/playwright/tests/grid/etalons'; const EDITORS = 'e2e/playwright/tests/editors/etalons'; +const DEMOS = 'apps/demos/testing/etalons'; +const DEMO_GRID = 'apps/demos/testing/widgets/datagrid/etalons'; // Root reads and writes through any mode, as the container runs. const asRoot = process.getuid?.() === 0; @@ -140,6 +142,48 @@ test('replaces, creates and reports what is up to date; a second call changes no expect(snapshot(checkout)).toEqual(applied); }); +test('applies the apps folder of the demo etalons, whatever its name', () => { + write(checkout, `${DEMOS}/a.png`, 'a'); + write(checkout, 'apps/demos/testing/common.spec.ts', ''); + write(checkout, 'apps/demos/testing/widgets/datagrid/datagrid.spec.ts', ''); + write(input, `${DEMOS}/a.png`, 'a2'); + write(input, `${DEMOS}/b.png`, 'b'); + write(input, `${DEMO_GRID}/c.png`, 'c'); + const misplaced = [ + 'apps/demos/etalons/x.png', + `${DEMOS}/sub/x.png`, + 'apps/demos/testing/nope/etalons/x.png', + 'apps/demos/x.png', + ]; + misplaced.forEach((relative) => write(input, relative, 'x')); + const apps = path.join(input, 'apps'); + const demos = path.join(checkout, 'apps/demos'); + + const first = apply([apps], demos); + + expect(first.status, first.stderr).toBe(0); + expect(first.stdout).toBe([ + `Applying ${apps} to ${checkout}`, + 'Replaced (1):', + ` ${DEMOS}/a.png`, + 'Created (2):', + ` ${DEMOS}/b.png`, + ` ${DEMO_GRID}/c.png`, + `Not applied (${misplaced.length}):`, + ...misplaced.map((relative) => ` ${relative}: not an etalon path in the checkout`), + '', + ].join('\n')); + expect([`${DEMOS}/a.png`, `${DEMOS}/b.png`, `${DEMO_GRID}/c.png`].map(read)).toEqual(['a2', 'b', 'c']); + + const secondCopy = path.join(root, 'apps 2'); + fs.cpSync(apps, secondCopy, { recursive: true }); + const renamed = apply([secondCopy], demos); + + expect(renamed.status, renamed.stderr).toBe(0); + expect(renamed.stdout).toContain('Already up to date (3):'); + expect(renamed.stdout).toContain('Nothing applied.'); +}); + test('lists what is not at an etalon path, ignores other files and runs nothing', () => { const misplaced = [ 'e2e/playwright/tests/nope/etalons/x.png', @@ -304,7 +348,7 @@ test('rejects bad arguments and writes nothing', () => { const result = apply(args); expect(result.status).toBe(1); - expect(result.stderr).toBe('Usage: pnpm run apply-etalons \n'); + expect(result.stderr).toBe('Usage: pnpm run apply-etalons \n'); }); [[path.join(root, 'missing'), 'ENOENT'], [zip, 'is not a folder']].forEach(([folder, error]) => { const result = apply([folder]); diff --git a/e2e/playwright/tools/collector-fixture/fixture.spec.ts b/tools/playwright/collector-fixture/fixture.spec.ts similarity index 100% rename from e2e/playwright/tools/collector-fixture/fixture.spec.ts rename to tools/playwright/collector-fixture/fixture.spec.ts diff --git a/e2e/playwright/tools/collector-fixture/playwright.config.ts b/tools/playwright/collector-fixture/playwright.config.ts similarity index 81% rename from e2e/playwright/tools/collector-fixture/playwright.config.ts rename to tools/playwright/collector-fixture/playwright.config.ts index aef74e796138..2bad91877d69 100644 --- a/e2e/playwright/tools/collector-fixture/playwright.config.ts +++ b/tools/playwright/collector-fixture/playwright.config.ts @@ -4,10 +4,12 @@ import { defineConfig } from '@playwright/test'; // A throwaway repository for etalonCollector.spec.ts: the etalons, the results and the collected // etalons all live under FIXTURE_ROOT. const root = process.env.FIXTURE_ROOT ?? path.resolve('fixture-root'); +// The demos keep their etalons under apps/. +const etalons = process.env.FIXTURE_ETALONS ?? 'e2e/playwright/tests/fixture/etalons'; export default defineConfig({ testDir: '.', - snapshotPathTemplate: `${root}/e2e/playwright/tests/fixture/etalons/{arg}{ext}`, + snapshotPathTemplate: `${root}/${etalons}/{arg}{ext}`, outputDir: `${root}/test-results`, retries: 1, // As the CI runs have it. diff --git a/tools/playwright/eslint.config.mjs b/tools/playwright/eslint.config.mjs new file mode 100644 index 000000000000..be268fb75641 --- /dev/null +++ b/tools/playwright/eslint.config.mjs @@ -0,0 +1,71 @@ +/* eslint-disable spellcheck/spell-checker */ +import noOnlyTests from 'eslint-plugin-no-only-tests'; +import tsParser from '@typescript-eslint/parser'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import stylistic from '@stylistic/eslint-plugin'; +import spellCheckConfig from 'eslint-config-devextreme/spell-check'; +import typescriptConfig from 'eslint-config-devextreme/typescript'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +export default [ + { + ignores: [ + 'artifacts/**', + 'node_modules/**', + ], + }, + ...spellCheckConfig, + { + plugins: { + 'no-only-tests': noOnlyTests, + }, + settings: { + 'import/resolver': { + node: { + extensions: ['.js', '.mjs', '.ts'], + }, + }, + }, + }, + ...typescriptConfig.map((config) => ({ + ...config, + files: ['**/*.ts'], + })), + { + files: ['**/*.ts'], + plugins: { + '@stylistic': stylistic, + }, + languageOptions: { + parser: tsParser, + sourceType: 'module', + parserOptions: { + project: './tsconfig.json', + tsconfigRootDir: __dirname, + }, + }, + rules: { + '@typescript-eslint/no-unused-vars': ['error', { + ignoreRestSiblings: true, + caughtErrors: 'none', + }], + 'class-methods-use-this': 'warn', + 'no-only-tests/no-only-tests': 'error', + 'no-await-in-loop': 'off', + 'no-restricted-globals': 'off', + 'no-restricted-syntax': 'off', + 'require-await': 'off', + '@typescript-eslint/require-await': 'off', + 'import/no-extraneous-dependencies': 'off', + 'import/prefer-default-export': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/explicit-function-return-type': ['error', { allowExpressions: true }], + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + '@stylistic/no-extra-parens': 'off', + }, + }, +]; diff --git a/e2e/playwright/tools/etalonCollector.spec.ts b/tools/playwright/etalonCollector.spec.ts similarity index 97% rename from e2e/playwright/tools/etalonCollector.spec.ts rename to tools/playwright/etalonCollector.spec.ts index 23156eea96f8..0e6532fcb41b 100644 --- a/e2e/playwright/tools/etalonCollector.spec.ts +++ b/tools/playwright/etalonCollector.spec.ts @@ -506,6 +506,18 @@ test.describe('a real run', () => { expect(fs.existsSync(path.join(root, etalons, 'new.png'))).toBe(true); }); + test('points the apply command at the apps folder for the demos', () => { + const demoEtalons = 'apps/demos/testing/etalons'; + fs.mkdirSync(path.join(root, demoEtalons), { recursive: true }); + fs.copyFileSync(path.join(root, etalons, 'stable change.png'), path.join(root, demoEtalons, 'stable change.png')); + + const checked = runFixture(['--grep', 'stable change'], { FIXTURE_ETALONS: demoEtalons }); + + expect(checked.status, checked.output).toBe(1); + expect(checked.output).toMatch(/Apply them: pnpm run apply-etalons \S*\/collected\/apps\n/); + expect(fs.readdirSync(path.join(root, 'collected', demoEtalons))).toEqual(['stable change.png']); + }); + test('empties the folder on the next run', () => { const emptied = runFixture(['--grep', 'pass on retry']); diff --git a/e2e/playwright/tools/etalonCollector.ts b/tools/playwright/etalonCollector.ts similarity index 98% rename from e2e/playwright/tools/etalonCollector.ts rename to tools/playwright/etalonCollector.ts index d14fd849953c..d5a198f40790 100644 --- a/e2e/playwright/tools/etalonCollector.ts +++ b/tools/playwright/etalonCollector.ts @@ -380,7 +380,7 @@ export function report( } // Collects the etalons of the shots that failed the same way in every attempt, at their repository -// paths, so that their e2e folder can be applied as it is. +// paths, so that their e2e or apps folder can be applied as it is. export default class EtalonCollector implements Reporter { private readonly options: EtalonCollectorOptions; @@ -414,6 +414,9 @@ export default class EtalonCollector implements Reporter { onEnd(): void { const errors: string[] = []; let collected = 0; + // The top folder of the repository the etalons lie in, the folder apply-etalons takes: e2e/, or + // apps/ for the demos. + let topFolder = ''; let named: NamedShot[] = []; let shared: SharedEtalon[] = []; @@ -462,6 +465,7 @@ export default class EtalonCollector implements Reporter { fs.mkdirSync(path.dirname(target), { recursive: true }); fs.copyFileSync(picture, target); collected += 1; + [topFolder] = etalon.split('/'); } catch (error) { errors.push(`${etalon}: ${errorMessage(error)}`); } @@ -473,7 +477,7 @@ export default class EtalonCollector implements Reporter { // pnpm runs the script from the package folder, the config's; the container sees another // absolute path than the host. - const folder = path.relative(this.configDir, path.join(this.outputDir, 'e2e')); + const folder = path.relative(this.configDir, path.join(this.outputDir, topFolder)); const applyCommand = `pnpm run apply-etalons ${shellWord(folder)}`; try { diff --git a/e2e/playwright/tools/flakyReporter.ts b/tools/playwright/flakyReporter.ts similarity index 75% rename from e2e/playwright/tools/flakyReporter.ts rename to tools/playwright/flakyReporter.ts index 4261c45fa944..4bc38906eb92 100644 --- a/e2e/playwright/tools/flakyReporter.ts +++ b/tools/playwright/flakyReporter.ts @@ -3,7 +3,6 @@ import path from 'node:path'; import type { FullConfig, Reporter, Suite, TestCase, } from '@playwright/test/reporter'; -import { DEFAULT_THEME, readEnv } from '../helpers/const'; // The shape tools/flaky-test-reporter reads (FlakyCandidate there). interface FlakyCandidate { @@ -19,8 +18,15 @@ interface FlakyCandidate { interface FlakyReporterOptions { outputFile: string; + // The theme of a job that sets no THEME. + defaultTheme: string; } +const readEnv = (name: string, fallback = ''): string => { + const value = process.env[name]; + return value === undefined || value === '' ? fallback : value; +}; + // The title path starts with the root suite and the project; the file path that follows keeps two // tests with the same title apart. const getTestName = (test: TestCase): string => test.titlePath().slice(2).join(' › '); @@ -40,10 +46,13 @@ const annotateFlaky = (name: string): void => { export default class FlakyReporter implements Reporter { private outputFile: string; + private readonly defaultTheme: string; + private rootSuite?: Suite; - constructor({ outputFile }: FlakyReporterOptions) { + constructor({ outputFile, defaultTheme }: FlakyReporterOptions) { this.outputFile = outputFile; + this.defaultTheme = defaultTheme; } onBegin(config: FullConfig, suite: Suite): void { @@ -53,12 +62,12 @@ export default class FlakyReporter implements Reporter { } onEnd(): void { - const baseBranch = readEnv(process.env.FLAKY_REPORT_BASE_BRANCH, '').replace(/^refs\/heads\//, '') || undefined; + const baseBranch = readEnv('FLAKY_REPORT_BASE_BRANCH').replace(/^refs\/heads\//, '') || undefined; const context = { - sourceJob: readEnv(process.env.FLAKY_REPORT_JOB, ''), - theme: readEnv(process.env.THEME, DEFAULT_THEME), - componentFolder: readEnv(process.env.FLAKY_REPORT_COMPONENT_FOLDER, ''), - timezone: readEnv(process.env.TIMEZONE, ''), + sourceJob: readEnv('FLAKY_REPORT_JOB'), + theme: readEnv('THEME', this.defaultTheme), + componentFolder: readEnv('FLAKY_REPORT_COMPONENT_FOLDER'), + timezone: readEnv('TIMEZONE'), platform: '', baseBranch, }; diff --git a/tools/playwright/package.json b/tools/playwright/package.json new file mode 100644 index 000000000000..b7cd7d955690 --- /dev/null +++ b/tools/playwright/package.json @@ -0,0 +1,23 @@ +{ + "name": "devextreme-playwright-tools", + "version": "27.1.0", + "private": true, + "scripts": { + "test": "playwright test", + "lint": "eslint", + "type-check": "tsc --noEmit -p tsconfig.json" + }, + "devDependencies": { + "@eslint/js": "catalog:", + "@playwright/test": "catalog:", + "@stylistic/eslint-plugin": "catalog:", + "@types/node": "catalog:tools", + "@typescript-eslint/eslint-plugin": "catalog:", + "@typescript-eslint/parser": "catalog:", + "eslint": "catalog:", + "eslint-config-devextreme": "catalog:", + "eslint-plugin-import": "catalog:", + "eslint-plugin-no-only-tests": "catalog:", + "typescript": "5.8.3" + } +} diff --git a/e2e/playwright/tools/playwright.config.ts b/tools/playwright/playwright.config.ts similarity index 88% rename from e2e/playwright/tools/playwright.config.ts rename to tools/playwright/playwright.config.ts index 71c3eb950a77..eed8ed60c06b 100644 --- a/e2e/playwright/tools/playwright.config.ts +++ b/tools/playwright/playwright.config.ts @@ -5,7 +5,7 @@ import { defineConfig } from '@playwright/test'; export default defineConfig({ testDir: '.', testIgnore: 'collector-fixture/**', - outputDir: '../artifacts/tools-results', + outputDir: './artifacts/test-results', timeout: 180000, reporter: [['list']], }); diff --git a/tools/playwright/tsconfig.json b/tools/playwright/tsconfig.json new file mode 100644 index 000000000000..79c197507ab0 --- /dev/null +++ b/tools/playwright/tsconfig.json @@ -0,0 +1,21 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "target": "es2022", + "module": "esnext", + "moduleResolution": "bundler", + "lib": [ + "esnext", + "dom" + ], + "noEmit": true, + "noImplicitAny": true, + "types": [ + "node" + ] + }, + "exclude": [ + "artifacts", + "node_modules" + ] +}