From 034e11abe7f6e98e5cc7301edf21d73ed86c2e51 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 9 Jan 2025 13:59:27 +0000 Subject: [PATCH] Use @tenbin/jest Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .github/workflows/end-to-end-tests.yaml | 11 ++++------ .github/workflows/tests.yml | 29 +++++++++++++++++++++++++ jest.config.ts | 3 ++- knip.ts | 2 ++ package.json | 1 + yarn.lock | 12 +++++++++- 6 files changed, 49 insertions(+), 9 deletions(-) diff --git a/.github/workflows/end-to-end-tests.yaml b/.github/workflows/end-to-end-tests.yaml index f95922a5d9..99a43cd749 100644 --- a/.github/workflows/end-to-end-tests.yaml +++ b/.github/workflows/end-to-end-tests.yaml @@ -164,16 +164,13 @@ jobs: if: matrix.project == 'WebKit' && steps.playwright-cache.outputs.cache-hit == 'true' run: yarn playwright install-deps webkit - # Restore test-results.json file, which records the execution time of each test file. - # splitTests function uses this file for sharding. + # Restore playwright-results.json file, which records the execution time of each test file. + # The splitTests function uses this file for sharding. - name: Restore playwright-results.json uses: actions/cache/restore@v4 with: path: playwright-results.json - key: playwright-results-${{ github.ref_name }} - restore-keys: | - playwright-results-${{ github.base_ref }} - playwright-results-develop + key: playwright-results # We skip tests tagged with @mergequeue when running on PRs, but run them in MQ and everywhere else - name: Run Playwright tests @@ -234,7 +231,7 @@ jobs: uses: actions/cache/save@v4 with: path: playwright-results.json - key: playwright-results-${{ github.ref_name }} + key: playwright-results # Upload the HTML report even if one of our reporters fails, this can happen when stale screenshots are detected - name: Upload HTML report diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dfb92e8ba0..fee25f97e5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -64,6 +64,14 @@ jobs: id: cpu-cores uses: SimenB/github-actions-cpu-cores@97ba232459a8e02ff6121db9362b09661c875ab8 # v2 + # Restore tenbin-report.json file, which records the execution time of each test file. + # @tenbin/jest/sequencer uses this file for sharding. + - name: Restore tenbin-report.json + uses: actions/cache/restore@v4 + with: + path: tenbin-report.json + key: tenbin-report + - name: Run tests run: | yarn test \ @@ -78,6 +86,14 @@ jobs: # tell jest to use coloured output FORCE_COLOR: true + # @tenbin/jest/reporter generates tenbin-report.json for each shard. + - name: Upload tenbin-report.json + if: github.ref_name == 'main' + uses: actions/upload-artifact@v4 + with: + name: tenbin-report-${{ matrix.runner }} + path: tenbin-report.json + - name: Move coverage files into place if: env.ENABLE_COVERAGE == 'true' run: mv coverage/lcov.info coverage/${{ steps.setupNode.outputs.node-version }}-${{ matrix.runner }}.lcov.info @@ -112,3 +128,16 @@ jobs: context: SonarCloud Code Analysis sha: ${{ github.sha }} target_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + + # Download, merge & upload tenbin-report.json + - uses: actions/download-artifact@v4 + with: + path: tenbin-report + pattern: tenbin-report-* + - name: Merge tenbin-report + run: jq -s add tenbin-report/**/tenbin-report.json > tenbin-report.json + - name: Cache tenbin-report.json + uses: actions/cache/save@v4 + with: + path: tenbin-report.json + key: tenbin-report diff --git a/jest.config.ts b/jest.config.ts index b70b21bc97..e620981ccc 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -52,11 +52,12 @@ const config: Config = { testResultsProcessor: "@casualbot/jest-sonar-reporter", prettierPath: null, moduleDirectories: ["node_modules", "test/test-utils"], + testSequencer: "@tenbin/jest/sequencer", }; // if we're running under GHA, enable the GHA reporter if (env["GITHUB_ACTIONS"] !== undefined) { - const reporters: Config["reporters"] = [["github-actions", { silent: false }], "summary"]; + const reporters: Config["reporters"] = [["github-actions", { silent: false }], "summary", "@tenbin/jest/reporter"]; // if we're running against the develop branch, also enable the slow test reporter if (env["GITHUB_REF"] == "refs/heads/develop") { diff --git a/knip.ts b/knip.ts index 247f9d9789..0b40c92cab 100644 --- a/knip.ts +++ b/knip.ts @@ -21,6 +21,8 @@ export default { "src/hooks/useLocalStorageState.ts", "src/components/views/elements/InfoTooltip.tsx", "src/components/views/elements/StyledCheckbox.tsx", + // This throws an error trying to load tenbin for an unknown reason + "src/playwright.config.ts", ], ignoreDependencies: [ // Required for `action-validator` diff --git a/package.json b/package.json index b849f263c5..8fed91ea55 100644 --- a/package.json +++ b/package.json @@ -182,6 +182,7 @@ "@sentry/webpack-plugin": "^2.7.1", "@stylistic/eslint-plugin": "^2.9.0", "@svgr/webpack": "^8.0.0", + "@tenbin/jest": "^0.5.0", "@tenbin/playwright": "^0.5.0", "@testcontainers/postgresql": "^10.16.0", "@testing-library/dom": "^10.4.0", diff --git a/yarn.lock b/yarn.lock index 9b11c629fb..5a6c93ad1e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2722,6 +2722,15 @@ resolved "https://registry.yarnpkg.com/@tenbin/core/-/core-0.5.0.tgz#394f74d90e618e9c15a1f376871a5247b06e35d7" integrity sha512-QawJTsn1svoLDJipr0dDl/L3npkiMmA1pO5OfveoV6/hajQSrEI0QJtxg/kXMyi0P+EUJ55KL0BVsDkh78OvZA== +"@tenbin/jest@^0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@tenbin/jest/-/jest-0.5.0.tgz#5f89396de18d5aa1f78d91926cf8941be89aa2e5" + integrity sha512-CWjyHGMzibiQWJYXuXEsiPgEmXPjoPfRJItTFbvNEmW4lWazuMsQcihxs4ZpyCUq8LxDDMFYf2Egt7ZMjsTEQA== + dependencies: + "@jest/test-sequencer" "^29.7.0" + "@tenbin/core" "0.5.0" + picocolors "^1.1.0" + "@tenbin/playwright@^0.5.0": version "0.5.0" resolved "https://registry.yarnpkg.com/@tenbin/playwright/-/playwright-0.5.0.tgz#8203d3419144fb812430663cc6362658df462abd" @@ -3560,13 +3569,14 @@ "@vector-im/matrix-wysiwyg-wasm@link:../../.cache/yarn/v6/npm-@vector-im-matrix-wysiwyg-2.38.0-af862ffd231dc0a6b8d6f2cb3601e68456c0ff24-integrity/node_modules/bindings/wysiwyg-wasm": version "0.0.0" + uid "" "@vector-im/matrix-wysiwyg@2.38.0": version "2.38.0" resolved "https://registry.yarnpkg.com/@vector-im/matrix-wysiwyg/-/matrix-wysiwyg-2.38.0.tgz#af862ffd231dc0a6b8d6f2cb3601e68456c0ff24" integrity sha512-cMEVicFYVzFxuSyWON0aVGjAJMcgJZ+LxuLTEp8EGuu8cRacuh0RN5rapb11YVZygzFvE7X1cMedJ/fKd5vRLA== dependencies: - "@vector-im/matrix-wysiwyg-wasm" "link:../../.cache/yarn/v6/npm-@vector-im-matrix-wysiwyg-2.38.0-af862ffd231dc0a6b8d6f2cb3601e68456c0ff24-integrity/node_modules/bindings/wysiwyg-wasm" + "@vector-im/matrix-wysiwyg-wasm" "link:../../Library/Caches/Yarn/v6/npm-@vector-im-matrix-wysiwyg-2.38.0-af862ffd231dc0a6b8d6f2cb3601e68456c0ff24-integrity/node_modules/bindings/wysiwyg-wasm" "@webassemblyjs/ast@1.14.1", "@webassemblyjs/ast@^1.14.1": version "1.14.1"