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
47df54d828
commit
be89b91025
@ -98,7 +98,7 @@ const computeUnixShellEnvironmentInjectable = getInjectable({
|
|||||||
|
|
||||||
logger.info(`[UNIX-SHELL-ENV]: running against ${shellPath}`, { command, shellArgs });
|
logger.info(`[UNIX-SHELL-ENV]: running against ${shellPath}`, { command, shellArgs });
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve) => {
|
||||||
const shellProcess = spawn(shellPath, shellArgs, {
|
const shellProcess = spawn(shellPath, shellArgs, {
|
||||||
signal: opts.signal,
|
signal: opts.signal,
|
||||||
env,
|
env,
|
||||||
@ -109,7 +109,10 @@ const computeUnixShellEnvironmentInjectable = getInjectable({
|
|||||||
shellProcess.stdout.on("data", b => stdout.push(b));
|
shellProcess.stdout.on("data", b => stdout.push(b));
|
||||||
shellProcess.stderr.on("data", b => stderr.push(b));
|
shellProcess.stderr.on("data", b => stderr.push(b));
|
||||||
|
|
||||||
shellProcess.on("error", (err) => reject(err));
|
shellProcess.on("error", (err) => resolve({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: `Failed to spawn ${shellPath}: ${err}`,
|
||||||
|
}));
|
||||||
shellProcess.on("close", (code, signal) => {
|
shellProcess.on("close", (code, signal) => {
|
||||||
if (code || signal) {
|
if (code || signal) {
|
||||||
const context = {
|
const context = {
|
||||||
|
|||||||
@ -16,7 +16,6 @@ import computeUnixShellEnvironmentInjectable from "./compute-unix-shell-environm
|
|||||||
import processEnvInjectable from "./env.injectable";
|
import processEnvInjectable from "./env.injectable";
|
||||||
import processExecPathInjectable from "./execPath.injectable";
|
import processExecPathInjectable from "./execPath.injectable";
|
||||||
import MemoryStream from "memorystream";
|
import MemoryStream from "memorystream";
|
||||||
import type { EnvironmentVariables } from "./compute-shell-environment.injectable";
|
|
||||||
|
|
||||||
const expectedEnv = {
|
const expectedEnv = {
|
||||||
SOME_ENV_VAR: "some-env-value",
|
SOME_ENV_VAR: "some-env-value",
|
||||||
@ -34,7 +33,7 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
let shellStdin: MemoryStream;
|
let shellStdin: MemoryStream;
|
||||||
let shellStdout: MemoryStream;
|
let shellStdout: MemoryStream;
|
||||||
let shellStderr: MemoryStream;
|
let shellStderr: MemoryStream;
|
||||||
let unixShellEnv: Promise<EnvironmentVariables>;
|
let unixShellEnv: ReturnType<ComputeUnixShellEnvironment>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
di = getDiForUnitTesting({
|
di = getDiForUnitTesting({
|
||||||
@ -121,8 +120,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
shellProcessFake.emit("error", new Error("some-error"));
|
shellProcessFake.emit("error", new Error("some-error"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject the promise with the error", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).rejects.toThrow("some-error");
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: `Failed to spawn ${shellPath}: Error: some-error`,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -131,8 +133,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
shellProcessFake.emit("close", 1, null);
|
shellProcessFake.emit("close", 1, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject the promise with the error", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).rejects.toThrow("Unexpected return code from spawned shell (code: 1, signal: null)");
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: 'Shell did not exit sucessfully: {\n "code": 1,\n "signal": null,\n "stdout": "",\n "stderr": ""\n}',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -141,8 +146,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
shellProcessFake.emit("close", 0, "SIGKILL");
|
shellProcessFake.emit("close", 0, "SIGKILL");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject the promise with the error", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).rejects.toThrow("Unexpected return code from spawned shell (code: 0, signal: SIGKILL)");
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: 'Shell did not exit sucessfully: {\n "code": 0,\n "signal": "SIGKILL",\n "stdout": "",\n "stderr": ""\n}',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -162,10 +170,13 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should resolve the env", async () => {
|
it("should resolve the env", async () => {
|
||||||
await expect(unixShellEnv).resolves.toMatchObject({
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
PATH: "/bin",
|
callWasSuccessful: true,
|
||||||
SOME_ENV_VAR: "some-env-value",
|
response: {
|
||||||
TERM: "some-other-value",
|
PATH: "/bin",
|
||||||
|
SOME_ENV_VAR: "some-env-value",
|
||||||
|
TERM: "some-other-value",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -208,8 +219,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
shellProcessFake.emit("error", new Error("some-error"));
|
shellProcessFake.emit("error", new Error("some-error"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject the promise with the error", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).rejects.toThrow("some-error");
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: `Failed to spawn ${shellPath}: Error: some-error`,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -218,8 +232,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
shellProcessFake.emit("close", 1, null);
|
shellProcessFake.emit("close", 1, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject the promise with the error", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).rejects.toThrow("Unexpected return code from spawned shell (code: 1, signal: null)");
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: 'Shell did not exit sucessfully: {\n "code": 1,\n "signal": null,\n "stdout": "",\n "stderr": ""\n}',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -228,8 +245,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
shellProcessFake.emit("close", 0, "SIGKILL");
|
shellProcessFake.emit("close", 0, "SIGKILL");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject the promise with the error", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).rejects.toThrow("Unexpected return code from spawned shell (code: 0, signal: SIGKILL)");
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: 'Shell did not exit sucessfully: {\n "code": 0,\n "signal": "SIGKILL",\n "stdout": "",\n "stderr": ""\n}',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -249,10 +269,13 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should resolve the env", async () => {
|
it("should resolve the env", async () => {
|
||||||
await expect(unixShellEnv).resolves.toMatchObject({
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
PATH: "/bin",
|
callWasSuccessful: true,
|
||||||
SOME_ENV_VAR: "some-env-value",
|
response: {
|
||||||
TERM: "some-other-value",
|
PATH: "/bin",
|
||||||
|
SOME_ENV_VAR: "some-env-value",
|
||||||
|
TERM: "some-other-value",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -294,8 +317,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
shellProcessFake.emit("error", new Error("some-error"));
|
shellProcessFake.emit("error", new Error("some-error"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject the promise with the error", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).rejects.toThrow("some-error");
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: `Failed to spawn ${shellPath}: Error: some-error`,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -304,8 +330,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
shellProcessFake.emit("close", 1, null);
|
shellProcessFake.emit("close", 1, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject the promise with the error", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).rejects.toThrow("Unexpected return code from spawned shell (code: 1, signal: null)");
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: 'Shell did not exit sucessfully: {\n "code": 1,\n "signal": null,\n "stdout": "",\n "stderr": ""\n}',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -314,8 +343,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
shellProcessFake.emit("close", 0, "SIGKILL");
|
shellProcessFake.emit("close", 0, "SIGKILL");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject the promise with the error", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).rejects.toThrow("Unexpected return code from spawned shell (code: 0, signal: SIGKILL)");
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: 'Shell did not exit sucessfully: {\n "code": 0,\n "signal": "SIGKILL",\n "stdout": "",\n "stderr": ""\n}',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -335,10 +367,13 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should resolve the env", async () => {
|
it("should resolve the env", async () => {
|
||||||
await expect(unixShellEnv).resolves.toMatchObject({
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
PATH: "/bin",
|
callWasSuccessful: true,
|
||||||
SOME_ENV_VAR: "some-env-value",
|
response: {
|
||||||
TERM: "some-other-value",
|
PATH: "/bin",
|
||||||
|
SOME_ENV_VAR: "some-env-value",
|
||||||
|
TERM: "some-other-value",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -379,8 +414,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
shellProcessFake.emit("error", new Error("some-error"));
|
shellProcessFake.emit("error", new Error("some-error"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject the promise with the error", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).rejects.toThrow("some-error");
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: `Failed to spawn ${shellPath}: Error: some-error`,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -389,8 +427,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
shellProcessFake.emit("close", 1, null);
|
shellProcessFake.emit("close", 1, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject the promise with the error", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).rejects.toThrow("Unexpected return code from spawned shell (code: 1, signal: null)");
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: 'Shell did not exit sucessfully: {\n "code": 1,\n "signal": null,\n "stdout": "",\n "stderr": ""\n}',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -399,8 +440,11 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
shellProcessFake.emit("close", 0, "SIGKILL");
|
shellProcessFake.emit("close", 0, "SIGKILL");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should reject the promise with the error", async () => {
|
it("should resolve with a failed call", async () => {
|
||||||
await expect(unixShellEnv).rejects.toThrow("Unexpected return code from spawned shell (code: 0, signal: SIGKILL)");
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
|
callWasSuccessful: false,
|
||||||
|
error: 'Shell did not exit sucessfully: {\n "code": 0,\n "signal": "SIGKILL",\n "stdout": "",\n "stderr": ""\n}',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -420,10 +464,13 @@ describe("computeUnixShellEnvironment technical tests", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should resolve the env", async () => {
|
it("should resolve the env", async () => {
|
||||||
await expect(unixShellEnv).resolves.toMatchObject({
|
await expect(unixShellEnv).resolves.toEqual({
|
||||||
PATH: "/bin",
|
callWasSuccessful: true,
|
||||||
SOME_ENV_VAR: "some-env-value",
|
response: {
|
||||||
TERM: "some-other-value",
|
PATH: "/bin",
|
||||||
|
SOME_ENV_VAR: "some-env-value",
|
||||||
|
TERM: "some-other-value",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user