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:
parent
801e8c6229
commit
9f68169f08
@ -1,4 +1,8 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
const { doWebpackBuild } = require("../dist/index");
|
const { doWebpackBuild } = require("../dist/index");
|
||||||
|
|
||||||
doWebpackBuild({ watch: process.argv.includes("--watch") });
|
doWebpackBuild({
|
||||||
|
watch: process.argv.includes("--watch"),
|
||||||
|
}).then(({ statusCode }) => {
|
||||||
|
process.exit(statusCode);
|
||||||
|
});
|
||||||
|
|||||||
@ -6,5 +6,5 @@ export const doWebpackBuild = ({ watch }: { watch: boolean }) => {
|
|||||||
|
|
||||||
const doWebpackBuild = di.inject(doWebpackBuildInjectable);
|
const doWebpackBuild = di.inject(doWebpackBuildInjectable);
|
||||||
|
|
||||||
doWebpackBuild({ watch });
|
return doWebpackBuild({ watch });
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
import { getDi } from "./get-di";
|
import { getDi } from "./get-di";
|
||||||
import { execInjectable } from "./exec.injectable";
|
import { execInjectable } from "./exec.injectable";
|
||||||
import asyncFn, { AsyncFnMock } from "@async-fn/jest";
|
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 { getPromiseStatus } from "@ogre-tools/test-utils";
|
||||||
import { LogSuccess, logSuccessInjectable } from "./log-success.injectable";
|
import { LogSuccess, logSuccessInjectable } from "./log-success.injectable";
|
||||||
import { LogWarning, logWarningInjectable } from "./log-warning.injectable";
|
import { LogWarning, logWarningInjectable } from "./log-warning.injectable";
|
||||||
@ -31,23 +35,23 @@ describe("do-webpack-build", () => {
|
|||||||
doWebpackBuild = di.inject(doWebpackBuildInjectable);
|
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});
|
doWebpackBuild({ watch: true });
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledWith("webpack --watch");
|
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});
|
doWebpackBuild({ watch: false });
|
||||||
|
|
||||||
expect(execMock).toHaveBeenCalledWith("webpack");
|
expect(execMock).toHaveBeenCalledWith("webpack");
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("normally, when called", () => {
|
describe("normally, when called", () => {
|
||||||
let actualPromise: Promise<void>;
|
let actualPromise: Promise<DoWebpackBuildResult>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
actualPromise = doWebpackBuild({ watch: true});
|
actualPromise = doWebpackBuild({ watch: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
it("calls webpack", () => {
|
it("calls webpack", () => {
|
||||||
@ -72,14 +76,13 @@ describe("do-webpack-build", () => {
|
|||||||
expect(promiseStatus.fulfilled).toBe(false);
|
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;
|
const [[eventName, finishWebpack]] = execResultStub.on.mock.calls;
|
||||||
|
|
||||||
eventName === "exit" && finishWebpack();
|
const withoutError = 42;
|
||||||
|
eventName === "exit" && finishWebpack(withoutError);
|
||||||
|
|
||||||
const promiseStatus = await getPromiseStatus(actualPromise);
|
expect(await actualPromise).toEqual({ statusCode: 42 });
|
||||||
|
|
||||||
expect(promiseStatus.fulfilled).toBe(true);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,7 +3,13 @@ import { execInjectable } from "./exec.injectable";
|
|||||||
import { logSuccessInjectable } from "./log-success.injectable";
|
import { logSuccessInjectable } from "./log-success.injectable";
|
||||||
import { logWarningInjectable } from "./log-warning.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({
|
export const doWebpackBuildInjectable = getInjectable({
|
||||||
id: "do-webpack-build",
|
id: "do-webpack-build",
|
||||||
@ -19,8 +25,10 @@ export const doWebpackBuildInjectable = getInjectable({
|
|||||||
execResult.stdout?.on("data", logSuccess);
|
execResult.stdout?.on("data", logSuccess);
|
||||||
execResult.stderr?.on("data", logWarning);
|
execResult.stderr?.on("data", logWarning);
|
||||||
|
|
||||||
return new Promise<void>((resolve) => {
|
return new Promise<DoWebpackBuildResult>((resolve) => {
|
||||||
execResult.on("exit", resolve);
|
execResult.on("exit", (statusCode: number) => {
|
||||||
|
resolve({ statusCode });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user