From 448f80db2ee58992e14b049a6787961579153d7f Mon Sep 17 00:00:00 2001 From: krisbitney Date: Tue, 7 Mar 2023 22:37:16 +0530 Subject: [PATCH 1/2] added check in `polywrap test` command so it will exit process with exit code 1 if a test fails --- packages/cli/src/commands/test.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index c603713b3f..933e037bae 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -150,6 +150,7 @@ const _run = async (options: Required) => { if (!quiet) { printJobOutput(output); } + workflowOutput.push(output); }; @@ -182,4 +183,8 @@ const _run = async (options: Required) => { ); } } + + if (workflowOutput.some((val) => val.status === Status.FAILED)) { + process.exit(1); + } }; From 733b0e40cbfe72a4115e152dbdcd290c36211905 Mon Sep 17 00:00:00 2001 From: krisbitney Date: Wed, 8 Mar 2023 00:04:39 +0530 Subject: [PATCH 2/2] added test case for `polywrap test` CLI command --- packages/cli/src/__tests__/e2e/test.spec.ts | 14 ++++++++++++++ packages/cli/src/commands/test.ts | 7 ++++++- .../cli/test/013-uri-error/polywrap.test.yaml | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 packages/test-cases/cases/cli/test/013-uri-error/polywrap.test.yaml diff --git a/packages/cli/src/__tests__/e2e/test.spec.ts b/packages/cli/src/__tests__/e2e/test.spec.ts index c136820180..0beaa18232 100644 --- a/packages/cli/src/__tests__/e2e/test.spec.ts +++ b/packages/cli/src/__tests__/e2e/test.spec.ts @@ -328,4 +328,18 @@ describe("e2e tests for test command", () => { expect(output[0].status).toBe("FAILED"); expect(output[0].validation.status).toBe("SUCCEED"); }) + + it("Should close with exit code 1 if any test fails", async () => { + const testCaseDir = getTestCaseDir(12); + const { exitCode, stdout } = await Commands.test(undefined, { + cwd: testCaseDir, + cli: polywrapCli, + }); + + expect(exitCode).toEqual(1); + + const output = parseOutput(stdout); + expect(output.find(v => v.id === "bad.0")?.status).toBe("FAILED"); + expect(output.find(v => v.id === "good.0")?.status).toBe("SUCCEED"); + }) }); diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index 933e037bae..8d90663891 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -184,7 +184,12 @@ const _run = async (options: Required) => { } } - if (workflowOutput.some((val) => val.status === Status.FAILED)) { + const isFailed = (val: WorkflowOutput) => + val.status === Status.FAILED && + (val.validation.status === Status.SKIPPED || + val.validation.status === Status.FAILED); + + if (workflowOutput.some(isFailed)) { process.exit(1); } }; diff --git a/packages/test-cases/cases/cli/test/013-uri-error/polywrap.test.yaml b/packages/test-cases/cases/cli/test/013-uri-error/polywrap.test.yaml new file mode 100644 index 0000000000..6a330d2656 --- /dev/null +++ b/packages/test-cases/cases/cli/test/013-uri-error/polywrap.test.yaml @@ -0,0 +1,17 @@ +name: run-test-wrapper +format: 0.2.0 +jobs: + bad: + steps: + - uri: fs/../run-test-wrapper/buildd + method: add + args: + x: 1 + y: 1 + good: + steps: + - uri: fs/../run-test-wrapper/build + method: add + args: + x: 1 + y: 1 \ No newline at end of file