mirror of
https://github.com/lensapp/lens.git
synced 2024-11-28 11:53:41 +03:00
chore: Fix lens-webpack-build failing due to warnings
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
208262a447
commit
4b63bc238e
@ -4,11 +4,13 @@ import asyncFn, { AsyncFnMock } from "@async-fn/jest";
|
||||
import { DoWebpackBuild, doWebpackBuildInjectable } 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";
|
||||
|
||||
describe("do-webpack-build", () => {
|
||||
let execMock: AsyncFnMock<Exec>;
|
||||
let doWebpackBuild: DoWebpackBuild;
|
||||
let logSuccessMock: AsyncFnMock<LogSuccess>;
|
||||
let logWarningMock: AsyncFnMock<LogWarning>;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDi();
|
||||
@ -17,6 +19,8 @@ describe("do-webpack-build", () => {
|
||||
di.override(execInjectable, () => execMock);
|
||||
logSuccessMock = asyncFn();
|
||||
di.override(logSuccessInjectable, () => logSuccessMock);
|
||||
logWarningMock = asyncFn();
|
||||
di.override(logWarningInjectable, () => logWarningMock);
|
||||
|
||||
doWebpackBuild = di.inject(doWebpackBuildInjectable);
|
||||
});
|
||||
@ -88,8 +92,8 @@ describe("do-webpack-build", () => {
|
||||
expect(logSuccessMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("throws", () => {
|
||||
return expect(actualPromise).rejects.toThrow("some-other-stderr");
|
||||
it("logs a warning", () => {
|
||||
expect(logWarningMock).toBeCalledWith("Warning while executing \"linkable-push\": some-other-stderr");
|
||||
});
|
||||
});
|
||||
|
||||
@ -123,13 +127,13 @@ describe("do-webpack-build", () => {
|
||||
expect(logSuccessMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("throws", () => {
|
||||
return expect(actualPromise).rejects.toThrow("some-stderr");
|
||||
it("logs a warning", () => {
|
||||
expect(logWarningMock).toBeCalledWith("Warning while executing \"webpack\": some-stderr");
|
||||
});
|
||||
});
|
||||
|
||||
describe("when webpack rejects", () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
execMock.reject(new Error("some-error"));
|
||||
});
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { execInjectable } from "./exec.injectable";
|
||||
import { logSuccessInjectable } from "./log-success.injectable";
|
||||
import { logWarningInjectable } from "./log-warning.injectable";
|
||||
|
||||
export type DoWebpackBuild = () => Promise<void>;
|
||||
|
||||
@ -10,15 +11,16 @@ export const doWebpackBuildInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const exec = di.inject(execInjectable);
|
||||
const logSuccess = di.inject(logSuccessInjectable);
|
||||
const logWarning = di.inject(logWarningInjectable);
|
||||
|
||||
const execWithResultHandling = async (command: string) => {
|
||||
const { stdout, stderr } = await exec(command);
|
||||
|
||||
if (stderr) {
|
||||
throw new Error(stderr);
|
||||
logWarning(`Warning while executing "${command}": ${stderr}`);
|
||||
} else if (stdout) {
|
||||
logSuccess(stdout);
|
||||
}
|
||||
|
||||
logSuccess(stdout);
|
||||
};
|
||||
|
||||
return async () => {
|
||||
|
@ -2,11 +2,12 @@ import { createContainer } from "@ogre-tools/injectable";
|
||||
import { execInjectable } from "./exec.injectable";
|
||||
import { doWebpackBuildInjectable } from "./do-webpack-build";
|
||||
import { logSuccessInjectable } from "./log-success.injectable";
|
||||
import { logWarningInjectable } from "./log-warning.injectable";
|
||||
|
||||
export const getDi = () => {
|
||||
const di = createContainer("do-webpack-build");
|
||||
|
||||
di.register(execInjectable, doWebpackBuildInjectable, logSuccessInjectable);
|
||||
di.register(execInjectable, doWebpackBuildInjectable, logSuccessInjectable, logWarningInjectable);
|
||||
|
||||
return di;
|
||||
};
|
||||
|
@ -0,0 +1,8 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
|
||||
export type LogWarning = typeof console.warn;
|
||||
|
||||
export const logWarningInjectable = getInjectable({
|
||||
id: "log-warning",
|
||||
instantiate: (di): LogWarning => console.warn,
|
||||
});
|
Loading…
Reference in New Issue
Block a user