From d9c452f3a2f9b6c7d41a39df2d736f97d7ca09fa Mon Sep 17 00:00:00 2001 From: xeho91 Date: Fri, 21 Jun 2024 01:47:37 +0800 Subject: [PATCH 1/8] feat: Add support for Vitest workspace Resolves #376 --- src/inputs/getViteConfigPath.test.ts | 6 ++++++ src/inputs/getViteConfigPath.ts | 10 ++++++++-- test/mockConfig/vitest.workspace.js | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/mockConfig/vitest.workspace.js diff --git a/src/inputs/getViteConfigPath.test.ts b/src/inputs/getViteConfigPath.test.ts index 1ede6f2..8d892d9 100644 --- a/src/inputs/getViteConfigPath.test.ts +++ b/src/inputs/getViteConfigPath.test.ts @@ -34,4 +34,10 @@ describe("getViteConfigPath", () => { const warningMessage = vi.mocked(core.warning).mock.calls[0][0]; expect(warningMessage).toContain(`${mockWorkingDirectory}/doesNotExist`); }); + + it("resolves Vitest workspace file", async (): Promise => { + await expect( + getViteConfigPath(mockWorkingDirectory, "vitest.workspace.js") + ).resolves.toMatch('test/mockConfig/vitest.workspace.js'); + }); }); diff --git a/src/inputs/getViteConfigPath.ts b/src/inputs/getViteConfigPath.ts index 9f2e59f..4248d98 100644 --- a/src/inputs/getViteConfigPath.ts +++ b/src/inputs/getViteConfigPath.ts @@ -10,6 +10,12 @@ const testFilePath = async (workingDirectory: string, filePath: string) => { }; const defaultPaths = [ + "vitest.config.ts", + "vitest.config.mts", + "vitest.config.cts", + "vitest.config.js", + "vitest.config.mjs", + "vitest.config.cjs", "vitest.config.ts", "vitest.config.mts", "vitest.config.cts", @@ -39,9 +45,9 @@ const getViteConfigPath = async (workingDirectory: string, input: string) => { : `any default location in "${workingDirectory}"`; core.warning(stripIndent` - Failed to read vite config file at ${searchPath}. + Failed to read vite config file at ${searchPath}. Make sure you provide the vite-config-path option if you're using a non-default location or name of your config file. - + Will not include thresholds in the final report. `); return null; diff --git a/test/mockConfig/vitest.workspace.js b/test/mockConfig/vitest.workspace.js new file mode 100644 index 0000000..8f02e3f --- /dev/null +++ b/test/mockConfig/vitest.workspace.js @@ -0,0 +1,3 @@ +import { defineWorkspace } from "vitest/config"; + +export default defineWorkspace(["./*"]); From f4fbe2ec5ad0a5cdc7617963006ffe1344b05a5f Mon Sep 17 00:00:00 2001 From: xeho91 Date: Tue, 25 Jun 2024 15:00:55 +0800 Subject: [PATCH 2/8] fix: replace `config` -> `workspace` and move to the bottom --- src/inputs/getViteConfigPath.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/inputs/getViteConfigPath.ts b/src/inputs/getViteConfigPath.ts index 4248d98..09de2be 100644 --- a/src/inputs/getViteConfigPath.ts +++ b/src/inputs/getViteConfigPath.ts @@ -10,15 +10,6 @@ const testFilePath = async (workingDirectory: string, filePath: string) => { }; const defaultPaths = [ - "vitest.config.ts", - "vitest.config.mts", - "vitest.config.cts", - "vitest.config.js", - "vitest.config.mjs", - "vitest.config.cjs", - "vitest.config.ts", - "vitest.config.mts", - "vitest.config.cts", "vitest.config.js", "vitest.config.mjs", "vitest.config.cjs", @@ -28,6 +19,15 @@ const defaultPaths = [ "vite.config.js", "vite.config.mjs", "vite.config.cjs", + "vitest.workspace.ts", + "vitest.workspace.mts", + "vitest.workspace.cts", + "vitest.workspace.js", + "vitest.workspace.mjs", + "vitest.workspace.cjs", + "vitest.workspace.ts", + "vitest.workspace.mts", + "vitest.workspace.cts", ]; const getViteConfigPath = async (workingDirectory: string, input: string) => { From 4a46d2aba119aa4e813a579b187db0392618a61a Mon Sep 17 00:00:00 2001 From: xeho91 Date: Tue, 25 Jun 2024 15:11:03 +0800 Subject: [PATCH 3/8] Update `README.md` - options table --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b9a2d0b..ac8a282 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ Then execute `npx vitest --coverage.enabled true` in a step before this action. ```yml name: 'Test' -on: +on: pull_request: jobs: test: runs-on: ubuntu-latest - + permissions: # Required to checkout the code contents: read @@ -62,7 +62,7 @@ jobs: - name: 'Report Coverage' # Set if: always() to also generate the report if tests are failing # Only works if you set `reportOnFailure: true` in your vite config as specified above - if: always() + if: always() uses: davelosert/vitest-coverage-report-action@v2 ``` @@ -80,7 +80,7 @@ This action requires the `pull-request: write` permission to add a comment to yo | `working-directory` | The main path to search for coverage- and configuration files (adjusting this is especially useful in monorepos). | `./` | | `json-summary-path` | The path to the json summary file. | `${working-directory}/coverage/coverage-summary.json` | | `json-final-path` | The path to the json final file. | `${working-directory}/coverage/coverage-final.json` | -| `vite-config-path` | The path to the vite config file. Will check the same paths as vite and vitest | Checks pattern `${working-directory}/vite[st].config.{t\|mt\|ct\|j\|mj\|cj}s` | +| `vite-config-path` | The path to the vite config file. Will check the same paths as vite and vitest | Checks pattern `${working-directory}/vite[st].{config|workspace}.{t\|mt\|ct\|j\|mj\|cj}s` | | `github-token` | A GitHub access token with permissions to write to issues (defaults to `secrets.GITHUB_TOKEN`). | `${{ github.token }}` | | `file-coverage-mode` | Defines how file-based coverage is reported. Possible values are `all`, `changes` or `none`. | `changes` | | `name` | Give the report a custom name. This is useful if you want multiple reports for different test suites within the same PR. Needs to be unique. | '' | From c97a4b15ee315d1d6d12cc969e33c6af526d0a5c Mon Sep 17 00:00:00 2001 From: xeho91 Date: Tue, 25 Jun 2024 15:13:49 +0800 Subject: [PATCH 4/8] Update `README.md` - add warning --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ac8a282..6bb8750 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,9 @@ If your project includes multiple test suites and you want to consolidate their ### Coverage Thresholds +> [!WARNING] +| Currently, this action does not import the vite-configuration, but parses it as string to extract the coverage-thresholds by an regexp. In other words: All thresholds need to be directly defined in the config-file given to this action through the vite-config-path input. E.g., when using workspace to extend a parent-configuration, the thresholds can not be defined in the parent-config. + This action reads the coverage thresholds specified in the `coverage` property of the Vite configuration file. It then uses these thresholds to determine the status of the generated report. For instance, consider the following configuration: From 832ce60093ba4e413bb209d5c812256a4c7eee49 Mon Sep 17 00:00:00 2001 From: xeho91 Date: Tue, 25 Jun 2024 15:28:37 +0800 Subject: [PATCH 5/8] Revert unwanted auto-format --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6bb8750..0addcd7 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,13 @@ Then execute `npx vitest --coverage.enabled true` in a step before this action. ```yml name: 'Test' -on: +on: pull_request: jobs: test: runs-on: ubuntu-latest - + permissions: # Required to checkout the code contents: read @@ -62,7 +62,7 @@ jobs: - name: 'Report Coverage' # Set if: always() to also generate the report if tests are failing # Only works if you set `reportOnFailure: true` in your vite config as specified above - if: always() + if: always() uses: davelosert/vitest-coverage-report-action@v2 ``` From 613144df0130427d55252f79d8eb363ff7535910 Mon Sep 17 00:00:00 2001 From: xeho91 Date: Tue, 25 Jun 2024 15:33:15 +0800 Subject: [PATCH 6/8] fix: Undo paths which werent supposed to be removed --- src/inputs/getViteConfigPath.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/inputs/getViteConfigPath.ts b/src/inputs/getViteConfigPath.ts index 09de2be..48c719d 100644 --- a/src/inputs/getViteConfigPath.ts +++ b/src/inputs/getViteConfigPath.ts @@ -10,6 +10,9 @@ const testFilePath = async (workingDirectory: string, filePath: string) => { }; const defaultPaths = [ + "vitest.config.ts", + "vitest.config.mts", + "vitest.config.cts", "vitest.config.js", "vitest.config.mjs", "vitest.config.cjs", From ef660eaff3bfd4a5cf83ac3cfab9be6c257862e2 Mon Sep 17 00:00:00 2001 From: Mateusz Kadlubowski Date: Tue, 25 Jun 2024 22:22:50 +0800 Subject: [PATCH 7/8] Remove duplication --- src/inputs/getViteConfigPath.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/inputs/getViteConfigPath.ts b/src/inputs/getViteConfigPath.ts index 48c719d..6c04f19 100644 --- a/src/inputs/getViteConfigPath.ts +++ b/src/inputs/getViteConfigPath.ts @@ -28,9 +28,6 @@ const defaultPaths = [ "vitest.workspace.js", "vitest.workspace.mjs", "vitest.workspace.cjs", - "vitest.workspace.ts", - "vitest.workspace.mts", - "vitest.workspace.cts", ]; const getViteConfigPath = async (workingDirectory: string, input: string) => { From 9037ae12d931210270568d319ebd713a6c267874 Mon Sep 17 00:00:00 2001 From: David Losert Date: Tue, 25 Jun 2024 17:49:58 +0200 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0addcd7..c6e9a6c 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ If your project includes multiple test suites and you want to consolidate their ### Coverage Thresholds > [!WARNING] -| Currently, this action does not import the vite-configuration, but parses it as string to extract the coverage-thresholds by an regexp. In other words: All thresholds need to be directly defined in the config-file given to this action through the vite-config-path input. E.g., when using workspace to extend a parent-configuration, the thresholds can not be defined in the parent-config. +> Currently, this action does not import the vite-configuration, but parses it as string to extract the coverage-thresholds by an regexp. In other words: All thresholds need to be directly defined in the config-file given to this action through the vite-config-path input. E.g., when using workspace to extend a parent-configuration, the thresholds can not be defined in the parent-config. This action reads the coverage thresholds specified in the `coverage` property of the Vite configuration file. It then uses these thresholds to determine the status of the generated report.