chore: migrate Node.js implementation for js-sandbox to isolated-vm (#3973)
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com>
This commit is contained in:
185
packages/hoppscotch-js-sandbox/src/__tests__/env/get.spec.ts
vendored
Normal file
185
packages/hoppscotch-js-sandbox/src/__tests__/env/get.spec.ts
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
|
||||
import { describe, expect, test } from "vitest"
|
||||
|
||||
import { runTestScript } from "~/node"
|
||||
import { TestResponse, TestResult } from "~/types"
|
||||
|
||||
const fakeResponse: TestResponse = {
|
||||
status: 200,
|
||||
body: "hoi",
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, envs: TestResult["envs"]) =>
|
||||
pipe(
|
||||
runTestScript(script, envs, fakeResponse),
|
||||
TE.map((x) => x.tests)
|
||||
)
|
||||
|
||||
describe("pw.env.get", () => {
|
||||
test("returns the correct value for an existing selected environment value", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.get("a")
|
||||
pw.expect(data).toBe("b")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "b",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'b' to be 'b'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("returns the correct value for an existing global environment value", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.get("a")
|
||||
pw.expect(data).toBe("b")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "a",
|
||||
value: "b",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'b' to be 'b'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("returns undefined for a key that is not present in both selected or environment", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.get("a")
|
||||
pw.expect(data).toBe(undefined)
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'undefined' to be 'undefined'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("returns the value defined in selected environment if it is also present in global", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.get("a")
|
||||
pw.expect(data).toBe("selected val")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "a",
|
||||
value: "global val",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "selected val",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'selected val' to be 'selected val'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("does not resolve environment values", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.get("a")
|
||||
pw.expect(data).toBe("<<hello>>")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "<<hello>>",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected '<<hello>>' to be '<<hello>>'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("errors if the key is not a string", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.get(5)
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toBeLeft()
|
||||
})
|
||||
})
|
||||
225
packages/hoppscotch-js-sandbox/src/__tests__/env/getResolve.spec.ts
vendored
Normal file
225
packages/hoppscotch-js-sandbox/src/__tests__/env/getResolve.spec.ts
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
|
||||
import { describe, expect, test } from "vitest"
|
||||
|
||||
import { runTestScript } from "~/node"
|
||||
import { TestResponse, TestResult } from "~/types"
|
||||
|
||||
const fakeResponse: TestResponse = {
|
||||
status: 200,
|
||||
body: "hoi",
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, envs: TestResult["envs"]) =>
|
||||
pipe(
|
||||
runTestScript(script, envs, fakeResponse),
|
||||
TE.map((x) => x.tests)
|
||||
)
|
||||
|
||||
describe("pw.env.getResolve", () => {
|
||||
test("returns the correct value for an existing selected environment value", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.getResolve("a")
|
||||
pw.expect(data).toBe("b")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "b",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'b' to be 'b'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("returns the correct value for an existing global environment value", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.getResolve("a")
|
||||
pw.expect(data).toBe("b")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "a",
|
||||
value: "b",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'b' to be 'b'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("returns undefined for a key that is not present in both selected or environment", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.getResolve("a")
|
||||
pw.expect(data).toBe(undefined)
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'undefined' to be 'undefined'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("returns the value defined in selected environment if it is also present in global", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.getResolve("a")
|
||||
pw.expect(data).toBe("selected val")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "a",
|
||||
value: "global val",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "selected val",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'selected val' to be 'selected val'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("resolve environment values", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.getResolve("a")
|
||||
pw.expect(data).toBe("there")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "<<hello>>",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "hello",
|
||||
value: "there",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'there' to be 'there'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("returns unresolved value on infinite loop in resolution", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.getResolve("a")
|
||||
pw.expect(data).toBe("<<hello>>")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "<<hello>>",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "hello",
|
||||
value: "<<a>>",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected '<<hello>>' to be '<<hello>>'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("errors if the key is not a string", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.getResolve(5)
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toBeLeft()
|
||||
})
|
||||
})
|
||||
166
packages/hoppscotch-js-sandbox/src/__tests__/env/resolve.spec.ts
vendored
Normal file
166
packages/hoppscotch-js-sandbox/src/__tests__/env/resolve.spec.ts
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
|
||||
import { describe, expect, test } from "vitest"
|
||||
|
||||
import { runTestScript } from "~/node"
|
||||
import { TestResponse, TestResult } from "~/types"
|
||||
|
||||
const fakeResponse: TestResponse = {
|
||||
status: 200,
|
||||
body: "hoi",
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, envs: TestResult["envs"]) =>
|
||||
pipe(
|
||||
runTestScript(script, envs, fakeResponse),
|
||||
TE.map((x) => x.tests)
|
||||
)
|
||||
|
||||
describe("pw.env.resolve", () => {
|
||||
test("value should be a string", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.resolve(5)
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toBeLeft()
|
||||
})
|
||||
|
||||
test("resolves global variables correctly", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.resolve("<<hello>>")
|
||||
pw.expect(data).toBe("there")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "hello",
|
||||
value: "there",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'there' to be 'there'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("resolves selected env variables correctly", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.resolve("<<hello>>")
|
||||
pw.expect(data).toBe("there")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [
|
||||
{
|
||||
key: "hello",
|
||||
value: "there",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'there' to be 'there'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("chooses selected env variable over global variables when both have same variable", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.resolve("<<hello>>")
|
||||
pw.expect(data).toBe("there")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "hello",
|
||||
value: "yo",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "hello",
|
||||
value: "there",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'there' to be 'there'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
test("if infinite loop in resolution, abandons resolutions altogether", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
const data = pw.env.resolve("<<hello>>")
|
||||
pw.expect(data).toBe("<<hello>>")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [
|
||||
{
|
||||
key: "hello",
|
||||
value: "<<there>>",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "there",
|
||||
value: "<<hello>>",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected '<<hello>>' to be '<<hello>>'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
221
packages/hoppscotch-js-sandbox/src/__tests__/env/set.spec.ts
vendored
Normal file
221
packages/hoppscotch-js-sandbox/src/__tests__/env/set.spec.ts
vendored
Normal file
@@ -0,0 +1,221 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
|
||||
import { describe, expect, test } from "vitest"
|
||||
|
||||
import { runTestScript } from "~/node"
|
||||
import { TestResponse, TestResult } from "~/types"
|
||||
|
||||
const fakeResponse: TestResponse = {
|
||||
status: 200,
|
||||
body: "hoi",
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, envs: TestResult["envs"]) =>
|
||||
pipe(
|
||||
runTestScript(script, envs, fakeResponse),
|
||||
TE.map((x) => x.envs)
|
||||
)
|
||||
|
||||
const funcTest = (script: string, envs: TestResult["envs"]) =>
|
||||
pipe(
|
||||
runTestScript(script, envs, fakeResponse),
|
||||
TE.map((x) => x.tests)
|
||||
)
|
||||
|
||||
describe("pw.env.set", () => {
|
||||
test("updates the selected environment variable correctly", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.set("a", "c")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "b",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "c",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test("updates the global environment variable correctly", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.set("a", "c")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "a",
|
||||
value: "b",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
global: [
|
||||
{
|
||||
key: "a",
|
||||
value: "c",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test("updates the selected environment if env present in both", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.set("a", "c")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "a",
|
||||
value: "b",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "d",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
global: [
|
||||
{
|
||||
key: "a",
|
||||
value: "b",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "c",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test("non existent keys are created in the selected environment", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.set("a", "c")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
global: [],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "c",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test("keys should be a string", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.set(5, "c")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toBeLeft()
|
||||
})
|
||||
|
||||
test("values should be a string", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.set("a", 5)
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toBeLeft()
|
||||
})
|
||||
|
||||
test("both keys and values should be strings", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.set(5, 5)
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toBeLeft()
|
||||
})
|
||||
|
||||
test("set environment values are reflected in the script execution", () => {
|
||||
return expect(
|
||||
funcTest(
|
||||
`
|
||||
pw.env.set("a", "b")
|
||||
pw.expect(pw.env.get("a")).toBe("b")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'b' to be 'b'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
259
packages/hoppscotch-js-sandbox/src/__tests__/env/unset.spec.ts
vendored
Normal file
259
packages/hoppscotch-js-sandbox/src/__tests__/env/unset.spec.ts
vendored
Normal file
@@ -0,0 +1,259 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
|
||||
import { describe, expect, test } from "vitest"
|
||||
|
||||
import { runTestScript } from "~/node"
|
||||
import { TestResponse, TestResult } from "~/types"
|
||||
|
||||
const fakeResponse: TestResponse = {
|
||||
status: 200,
|
||||
body: "hoi",
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, envs: TestResult["envs"]) =>
|
||||
pipe(
|
||||
runTestScript(script, envs, fakeResponse),
|
||||
TE.map((x) => x.envs)
|
||||
)
|
||||
|
||||
const funcTest = (script: string, envs: TestResult["envs"]) =>
|
||||
pipe(
|
||||
runTestScript(script, envs, fakeResponse),
|
||||
TE.map((x) => x.tests)
|
||||
)
|
||||
|
||||
describe("pw.env.unset", () => {
|
||||
test("removes the variable set in selected environment correctly", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.unset("baseUrl")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://echo.hoppscotch.io",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
selected: [],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test("removes the variable set in global environment correctly", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.unset("baseUrl")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://echo.hoppscotch.io",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
global: [],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test("removes the variable from selected environment if the entry is present in both selected and global environments", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.unset("baseUrl")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://httpbin.org",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://echo.hoppscotch.io",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
global: [
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://httpbin.org",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test("removes the initial occurrence of an entry if duplicate entries exist in the selected environment", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.unset("baseUrl")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://echo.hoppscotch.io",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://httpbin.org",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://echo.hoppscotch.io",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
global: [
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://echo.hoppscotch.io",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://echo.hoppscotch.io",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test("removes the initial occurrence of an entry if duplicate entries exist in the global environment", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.unset("baseUrl")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://httpbin.org/",
|
||||
secret: false,
|
||||
},
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://echo.hoppscotch.io",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
global: [
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://echo.hoppscotch.io",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
selected: [],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test("no change if attempting to delete non-existent keys", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.unset("baseUrl")
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
global: [],
|
||||
selected: [],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test("keys should be a string", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.unset(5)
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toBeLeft()
|
||||
})
|
||||
|
||||
test("set environment values are reflected in the script execution", () => {
|
||||
return expect(
|
||||
funcTest(
|
||||
`
|
||||
pw.env.unset("baseUrl")
|
||||
pw.expect(pw.env.get("baseUrl")).toBe(undefined)
|
||||
`,
|
||||
{
|
||||
global: [],
|
||||
selected: [
|
||||
{
|
||||
key: "baseUrl",
|
||||
value: "https://echo.hoppscotch.io",
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected 'undefined' to be 'undefined'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user