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

fix: Only warn on missing vite-config and improve warning message #260

Merged
merged 1 commit into from
Jul 30, 2023
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
6 changes: 3 additions & 3 deletions src/getViteConfigPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ describe("getViteConfigPath", () => {
);
});

it("rejects if config file can not be found", async (): Promise<void> => {
vi.spyOn(core, 'setFailed').mockImplementationOnce(() => { })
it("returns null if config file can not be found", async (): Promise<void> => {
vi.spyOn(core, 'warning').mockImplementationOnce(() => { })
await expect(
getViteConfigPath(mockWorkingDirectory, "doesNotExist")
).rejects.toThrow(/unable to find config file/i);
).resolves.toBeNull();
});
});
17 changes: 9 additions & 8 deletions src/getViteConfigPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ const getViteConfigPath = async (workingDirectory: string, input: string) => {

return await testFilePath(workingDirectory, input);
} catch (error) {
core.setFailed(stripIndent`
Failed to read vite config file"${workingDirectory}/${input}" or any of the default locations.
const searchPath = input ?
`"${workingDirectory}/${input}"` :
`any default location in "${workingDirectory}"`;

core.warning(stripIndent`
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.
`);
throw new Error(
`Unable to find config file "${workingDirectory}/${input}".`,
{
cause: error,
}
);
return null;
}
};

Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const run = async () => {
workingDirectory
} = await readOptions();


const jsonSummary = await parseVitestJsonSummary(jsonSummaryPath);
const tableData = generateSummaryTableHtml(jsonSummary.total, thresholds);
const summary = core.summary
Expand Down Expand Up @@ -78,4 +77,4 @@ run().then(() => {
core.info('Report generated successfully.');
}).catch((err) => {
core.error(err);
});
});
11 changes: 6 additions & 5 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ async function readOptions() {
const fileCoverageMode = getCoverageModeFrom(fileCoverageModeRaw);

const jsonSummaryPath = path.resolve(workingDirectory, core.getInput('json-summary-path'));
const viteConfigPath = await getViteConfigPath(workingDirectory, core.getInput("vite-config-path"));

const thresholds = await parseCoverageThresholds(viteConfigPath);

const jsonFinalPath = path.resolve(workingDirectory, core.getInput('json-final-path'));

const name = core.getInput('name');

// ViteConfig is optional, as it is only required for thresholds. If no vite config is provided, we will not include thresholds in the final report.
const viteConfigPath = await getViteConfigPath(workingDirectory, core.getInput("vite-config-path"));
const thresholds = viteConfigPath ? await parseCoverageThresholds(viteConfigPath) : {};

return {
fileCoverageMode,
Expand All @@ -31,4 +32,4 @@ async function readOptions() {

export {
readOptions
}
}
Loading