Skip to content

Commit

Permalink
fix: Only warn on missing vite-config and improve warning message (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
davelosert authored Jul 30, 2023
1 parent d7cf394 commit 746b700
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
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
}
}

0 comments on commit 746b700

Please sign in to comment.