From 0b20990fae05a1035108fc7b9979ecf52e581f59 Mon Sep 17 00:00:00 2001 From: Mateusz Kadlubowski Date: Tue, 25 Jun 2024 23:52:19 +0800 Subject: [PATCH] feat: Add support for Vitest workspace (#377) Vitest's Workspace Configurations are now parsed by default by this action. * feat: Add support for Vitest workspace Resolves #376 * fix: replace `config` -> `workspace` and move to the bottom * Update `README.md` - options table * Update `README.md` - add warning * Revert unwanted auto-format * fix: Undo paths which werent supposed to be removed * Remove duplication * Update README.md --------- Co-authored-by: David Losert --- README.md | 5 ++++- src/inputs/getViteConfigPath.test.ts | 6 ++++++ src/inputs/getViteConfigPath.ts | 10 ++++++++-- test/mockConfig/vitest.workspace.js | 3 +++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 test/mockConfig/vitest.workspace.js diff --git a/README.md b/README.md index b9a2d0b..c6e9a6c 100644 --- a/README.md +++ b/README.md @@ -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. | '' | @@ -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: 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..6c04f19 100644 --- a/src/inputs/getViteConfigPath.ts +++ b/src/inputs/getViteConfigPath.ts @@ -22,6 +22,12 @@ 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", ]; const getViteConfigPath = async (workingDirectory: string, input: string) => { @@ -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(["./*"]);