mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Previously this was done by lens-webpack-build, which is awkward for build-scripts that watch. Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
94 lines
2.7 KiB
TypeScript
94 lines
2.7 KiB
TypeScript
import { getDi } from "./get-di";
|
|
import { Exec, execInjectable } from "./exec.injectable";
|
|
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();
|
|
|
|
execMock = asyncFn();
|
|
di.override(execInjectable, () => execMock);
|
|
logSuccessMock = asyncFn();
|
|
di.override(logSuccessInjectable, () => logSuccessMock);
|
|
logWarningMock = asyncFn();
|
|
di.override(logWarningInjectable, () => logWarningMock);
|
|
|
|
doWebpackBuild = di.inject(doWebpackBuildInjectable);
|
|
});
|
|
|
|
describe("when called", () => {
|
|
let actualPromise: Promise<void>;
|
|
|
|
beforeEach(() => {
|
|
actualPromise = doWebpackBuild();
|
|
});
|
|
|
|
it("calls webpack", () => {
|
|
expect(execMock).toHaveBeenCalledWith("webpack");
|
|
});
|
|
|
|
it("does not resolve yet", async () => {
|
|
const promiseStatus = await getPromiseStatus(actualPromise);
|
|
|
|
expect(promiseStatus.fulfilled).toBe(false);
|
|
});
|
|
|
|
describe("when webpack resolves with stdout", () => {
|
|
beforeEach(async () => {
|
|
await execMock.resolve({ stdout: "some-stdout", stderr: "" });
|
|
});
|
|
|
|
it("logs the stdout", () => {
|
|
expect(logSuccessMock).toHaveBeenCalledWith("some-stdout");
|
|
});
|
|
|
|
it("script is done", async () => {
|
|
const promiseStatus = await getPromiseStatus(actualPromise);
|
|
|
|
expect(promiseStatus.fulfilled).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("when webpack resolves with stderr", () => {
|
|
beforeEach(() => {
|
|
execMock.resolve({ stdout: "", stderr: "some-stderr" });
|
|
});
|
|
|
|
it("does not log success", () => {
|
|
actualPromise.catch(() => {});
|
|
|
|
expect(logSuccessMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("logs a warning", () => {
|
|
expect(logWarningMock).toBeCalledWith("Warning while executing \"webpack\": some-stderr");
|
|
});
|
|
});
|
|
|
|
describe("when webpack rejects", () => {
|
|
beforeEach(async () => {
|
|
execMock.reject(new Error("some-error"));
|
|
});
|
|
|
|
it("does not log success", () => {
|
|
actualPromise.catch(() => {});
|
|
|
|
expect(logSuccessMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("throws", () => {
|
|
return expect(actualPromise).rejects.toThrow("some-error");
|
|
});
|
|
});
|
|
});
|
|
});
|