From 746b7006164523f1e4e03f1315123489d00828ea Mon Sep 17 00:00:00 2001 From: David Losert Date: Sun, 30 Jul 2023 20:07:43 +0200 Subject: [PATCH] fix: Only warn on missing vite-config and improve warning message (#260) --- src/getViteConfigPath.test.ts | 6 +++--- src/getViteConfigPath.ts | 17 +++++++++-------- src/index.ts | 3 +-- src/options.ts | 11 ++++++----- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/getViteConfigPath.test.ts b/src/getViteConfigPath.test.ts index d6a6e1c..5450934 100644 --- a/src/getViteConfigPath.test.ts +++ b/src/getViteConfigPath.test.ts @@ -23,10 +23,10 @@ describe("getViteConfigPath", () => { ); }); - it("rejects if config file can not be found", async (): Promise => { - vi.spyOn(core, 'setFailed').mockImplementationOnce(() => { }) + it("returns null if config file can not be found", async (): Promise => { + vi.spyOn(core, 'warning').mockImplementationOnce(() => { }) await expect( getViteConfigPath(mockWorkingDirectory, "doesNotExist") - ).rejects.toThrow(/unable to find config file/i); + ).resolves.toBeNull(); }); }); diff --git a/src/getViteConfigPath.ts b/src/getViteConfigPath.ts index 16031fc..44ddc3e 100644 --- a/src/getViteConfigPath.ts +++ b/src/getViteConfigPath.ts @@ -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; } }; diff --git a/src/index.ts b/src/index.ts index 4877f85..0fc5779 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 @@ -78,4 +77,4 @@ run().then(() => { core.info('Report generated successfully.'); }).catch((err) => { core.error(err); -}); \ No newline at end of file +}); diff --git a/src/options.ts b/src/options.ts index 134b5f4..bcbbceb 100644 --- a/src/options.ts +++ b/src/options.ts @@ -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, @@ -31,4 +32,4 @@ async function readOptions() { export { readOptions -} \ No newline at end of file +}