mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Update tests
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
46eae048d4
commit
dc7de44fab
@ -56,6 +56,14 @@ const execFileWithInputInjectable = getInjectable({
|
|||||||
|
|
||||||
execution.on("exit", (code, signal) => {
|
execution.on("exit", (code, signal) => {
|
||||||
if (!isNumber(code)) {
|
if (!isNumber(code)) {
|
||||||
|
/**
|
||||||
|
* According to https://nodejs.org/api/child_process.html#class-childprocess (section about the "exit" event)
|
||||||
|
* it says the following:
|
||||||
|
*
|
||||||
|
* If the process exited, code is the final exit code of the process, otherwise null.
|
||||||
|
* If the process terminated due to receipt of a signal, signal is the string name of the signal, otherwise null.
|
||||||
|
* One of the two will always be non-null.
|
||||||
|
*/
|
||||||
resolve({
|
resolve({
|
||||||
callWasSuccessful: false,
|
callWasSuccessful: false,
|
||||||
error: `Exited via ${signal}`,
|
error: `Exited via ${signal}`,
|
||||||
|
|||||||
@ -15,7 +15,7 @@ describe("exec-file-with-input", () => {
|
|||||||
let execFileMock: jest.Mock;
|
let execFileMock: jest.Mock;
|
||||||
|
|
||||||
let executionStub: EventEmitter & {
|
let executionStub: EventEmitter & {
|
||||||
stdin: { end: jest.Mock };
|
stdin: { end: (chunk: any) => void };
|
||||||
stdout: EventEmitter;
|
stdout: EventEmitter;
|
||||||
stderr: EventEmitter;
|
stderr: EventEmitter;
|
||||||
};
|
};
|
||||||
@ -25,10 +25,11 @@ describe("exec-file-with-input", () => {
|
|||||||
|
|
||||||
di.unoverride(execFileWithInputInjectable);
|
di.unoverride(execFileWithInputInjectable);
|
||||||
|
|
||||||
executionStub = new EventEmitter() as any;
|
executionStub = Object.assign(new EventEmitter(), {
|
||||||
executionStub.stdin = { end: jest.fn() };
|
stdin: { end: jest.fn() },
|
||||||
executionStub.stdout = new EventEmitter();
|
stdout: new EventEmitter(),
|
||||||
executionStub.stderr = new EventEmitter();
|
stderr: new EventEmitter(),
|
||||||
|
});
|
||||||
|
|
||||||
execFileMock = jest.fn(() => executionStub);
|
execFileMock = jest.fn(() => executionStub);
|
||||||
|
|
||||||
@ -66,10 +67,14 @@ describe("exec-file-with-input", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("calls for file with arguments", () => {
|
it("calls for file with arguments", () => {
|
||||||
expect(execFileMock).toHaveBeenCalledWith("./some-file-path", [
|
expect(execFileMock).toHaveBeenCalledWith(
|
||||||
"some-arg",
|
"./some-file-path",
|
||||||
"some-other-arg",
|
[
|
||||||
]);
|
"some-arg",
|
||||||
|
"some-other-arg",
|
||||||
|
],
|
||||||
|
{ "maxBuffer": 8589934592 },
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("calls with input", () => {
|
it("calls with input", () => {
|
||||||
@ -116,13 +121,13 @@ describe("exec-file-with-input", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("when execution exits without exit code, resolves with failure", async () => {
|
it("when execution exits without exit code, resolves with failure", async () => {
|
||||||
executionStub.emit("exit");
|
executionStub.emit("exit", null, "SIGKILL");
|
||||||
|
|
||||||
const actual = await actualPromise;
|
const actual = await actualPromise;
|
||||||
|
|
||||||
expect(actual).toEqual({
|
expect(actual).toEqual({
|
||||||
callWasSuccessful: false,
|
callWasSuccessful: false,
|
||||||
error: "Exited without exit code",
|
error: "Exited via SIGKILL",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -171,13 +176,13 @@ describe("exec-file-with-input", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("when execution exits without exit code, resolves with failure", async () => {
|
it("when execution exits without exit code, resolves with failure", async () => {
|
||||||
executionStub.emit("exit");
|
executionStub.emit("exit", null, "some-signal");
|
||||||
|
|
||||||
const actual = await actualPromise;
|
const actual = await actualPromise;
|
||||||
|
|
||||||
expect(actual).toEqual({
|
expect(actual).toEqual({
|
||||||
callWasSuccessful: false,
|
callWasSuccessful: false,
|
||||||
error: "Exited without exit code",
|
error: "Exited via some-signal",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user