Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for Vitest workspace #377

Merged
merged 8 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(["./*"]);
Loading