Skip to content

Commit

Permalink
feat: Add support for Vitest workspace (#377)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
xeho91 and davelosert committed Jun 25, 2024
1 parent a08ab64 commit 0b20990
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | '' |
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions src/inputs/getViteConfigPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
await expect(
getViteConfigPath(mockWorkingDirectory, "vitest.workspace.js")
).resolves.toMatch('test/mockConfig/vitest.workspace.js');
});
});
10 changes: 8 additions & 2 deletions src/inputs/getViteConfigPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions test/mockConfig/vitest.workspace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineWorkspace } from "vitest/config";

export default defineWorkspace(["./*"]);

0 comments on commit 0b20990

Please sign in to comment.