1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

fix: Make the shared build script return non-zero status on errors

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Mikko Aspiala <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2023-06-02 14:43:45 +03:00
parent 801e8c6229
commit 9f68169f08
4 changed files with 32 additions and 17 deletions

View File

@ -1,4 +1,8 @@
#!/usr/bin/env node
const { doWebpackBuild } = require("../dist/index");
doWebpackBuild({ watch: process.argv.includes("--watch") });
doWebpackBuild({
watch: process.argv.includes("--watch"),
}).then(({ statusCode }) => {
process.exit(statusCode);
});

View File

@ -6,5 +6,5 @@ export const doWebpackBuild = ({ watch }: { watch: boolean }) => {
const doWebpackBuild = di.inject(doWebpackBuildInjectable);
doWebpackBuild({ watch });
return doWebpackBuild({ watch });
};

View File

@ -1,7 +1,11 @@
import { getDi } from "./get-di";
import { execInjectable } from "./exec.injectable";
import asyncFn, { AsyncFnMock } from "@async-fn/jest";
import { DoWebpackBuild, doWebpackBuildInjectable } from "./do-webpack-build";
import {
DoWebpackBuild,
doWebpackBuildInjectable,
DoWebpackBuildResult,
} from "./do-webpack-build";
import { getPromiseStatus } from "@ogre-tools/test-utils";
import { LogSuccess, logSuccessInjectable } from "./log-success.injectable";
import { LogWarning, logWarningInjectable } from "./log-warning.injectable";
@ -31,20 +35,20 @@ describe("do-webpack-build", () => {
doWebpackBuild = di.inject(doWebpackBuildInjectable);
});
it('given watching, when called, calls webpack with watch', () => {
it("given watching, when called, calls webpack with watch", () => {
doWebpackBuild({ watch: true });
expect(execMock).toHaveBeenCalledWith("webpack --watch");
});
it('given not watching, when called, calls webpack without watch', () => {
it("given not watching, when called, calls webpack without watch", () => {
doWebpackBuild({ watch: false });
expect(execMock).toHaveBeenCalledWith("webpack");
});
describe("normally, when called", () => {
let actualPromise: Promise<void>;
let actualPromise: Promise<DoWebpackBuildResult>;
beforeEach(() => {
actualPromise = doWebpackBuild({ watch: true });
@ -72,14 +76,13 @@ describe("do-webpack-build", () => {
expect(promiseStatus.fulfilled).toBe(false);
});
it("when execution of webpack exits, script is done", async () => {
it("when execution of webpack exits with a status-code, script resolves with the status-code", async () => {
const [[eventName, finishWebpack]] = execResultStub.on.mock.calls;
eventName === "exit" && finishWebpack();
const withoutError = 42;
eventName === "exit" && finishWebpack(withoutError);
const promiseStatus = await getPromiseStatus(actualPromise);
expect(promiseStatus.fulfilled).toBe(true);
expect(await actualPromise).toEqual({ statusCode: 42 });
});
});
});

View File

@ -3,7 +3,13 @@ import { execInjectable } from "./exec.injectable";
import { logSuccessInjectable } from "./log-success.injectable";
import { logWarningInjectable } from "./log-warning.injectable";
export type DoWebpackBuild = ({ watch }: { watch: boolean }) => Promise<void>;
export type DoWebpackBuildResult = { statusCode: number };
export type DoWebpackBuild = ({
watch,
}: {
watch: boolean;
}) => Promise<DoWebpackBuildResult>;
export const doWebpackBuildInjectable = getInjectable({
id: "do-webpack-build",
@ -19,8 +25,10 @@ export const doWebpackBuildInjectable = getInjectable({
execResult.stdout?.on("data", logSuccess);
execResult.stderr?.on("data", logWarning);
return new Promise<void>((resolve) => {
execResult.on("exit", resolve);
return new Promise<DoWebpackBuildResult>((resolve) => {
execResult.on("exit", (statusCode: number) => {
resolve({ statusCode });
});
});
};
},