2024-04-19 15:38:46 +00:00
|
|
|
import { describe, expect, test } from "vitest"
|
2025-10-27 12:19:58 +00:00
|
|
|
import { runTest } from "~/utils/test-helpers"
|
2022-02-18 20:50:28 +00:00
|
|
|
|
|
|
|
|
describe("pw.env.getResolve", () => {
|
|
|
|
|
test("returns the correct value for an existing selected environment value", () => {
|
|
|
|
|
return expect(
|
2025-10-27 12:19:58 +00:00
|
|
|
runTest(
|
2022-02-18 20:50:28 +00:00
|
|
|
`
|
|
|
|
|
const data = pw.env.getResolve("a")
|
|
|
|
|
pw.expect(data).toBe("b")
|
|
|
|
|
`,
|
|
|
|
|
{
|
|
|
|
|
global: [],
|
|
|
|
|
selected: [
|
|
|
|
|
{
|
|
|
|
|
key: "a",
|
2025-05-23 17:08:36 +00:00
|
|
|
currentValue: "b",
|
|
|
|
|
initialValue: "b",
|
2024-02-08 16:28:42 +00:00
|
|
|
secret: false,
|
2022-02-18 20:50:28 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
)()
|
|
|
|
|
).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(
|
2025-10-27 12:19:58 +00:00
|
|
|
runTest(
|
2022-02-18 20:50:28 +00:00
|
|
|
`
|
|
|
|
|
const data = pw.env.getResolve("a")
|
|
|
|
|
pw.expect(data).toBe("b")
|
|
|
|
|
`,
|
|
|
|
|
{
|
|
|
|
|
global: [
|
|
|
|
|
{
|
|
|
|
|
key: "a",
|
2025-05-23 17:08:36 +00:00
|
|
|
currentValue: "b",
|
|
|
|
|
initialValue: "b",
|
2024-02-08 16:28:42 +00:00
|
|
|
secret: false,
|
2022-02-18 20:50:28 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
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(
|
2025-10-27 12:19:58 +00:00
|
|
|
runTest(
|
2022-02-18 20:50:28 +00:00
|
|
|
`
|
|
|
|
|
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(
|
2025-10-27 12:19:58 +00:00
|
|
|
runTest(
|
2022-02-18 20:50:28 +00:00
|
|
|
`
|
|
|
|
|
const data = pw.env.getResolve("a")
|
|
|
|
|
pw.expect(data).toBe("selected val")
|
|
|
|
|
`,
|
|
|
|
|
{
|
|
|
|
|
global: [
|
|
|
|
|
{
|
|
|
|
|
key: "a",
|
2025-05-23 17:08:36 +00:00
|
|
|
currentValue: "global val",
|
|
|
|
|
initialValue: "global val",
|
2024-02-08 16:28:42 +00:00
|
|
|
secret: false,
|
2022-02-18 20:50:28 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
selected: [
|
|
|
|
|
{
|
|
|
|
|
key: "a",
|
2025-05-23 17:08:36 +00:00
|
|
|
currentValue: "selected val",
|
|
|
|
|
initialValue: "selected val",
|
2024-02-08 16:28:42 +00:00
|
|
|
secret: false,
|
2022-02-18 20:50:28 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
)()
|
|
|
|
|
).resolves.toEqualRight([
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
expectResults: [
|
|
|
|
|
{
|
|
|
|
|
status: "pass",
|
|
|
|
|
message: "Expected 'selected val' to be 'selected val'",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}),
|
|
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("resolve environment values", () => {
|
|
|
|
|
return expect(
|
2025-10-27 12:19:58 +00:00
|
|
|
runTest(
|
2022-02-18 20:50:28 +00:00
|
|
|
`
|
|
|
|
|
const data = pw.env.getResolve("a")
|
|
|
|
|
pw.expect(data).toBe("there")
|
|
|
|
|
`,
|
|
|
|
|
{
|
|
|
|
|
global: [],
|
|
|
|
|
selected: [
|
|
|
|
|
{
|
|
|
|
|
key: "a",
|
2025-05-23 17:08:36 +00:00
|
|
|
currentValue: "<<hello>>",
|
|
|
|
|
initialValue: "<<hello>>",
|
2024-02-08 16:28:42 +00:00
|
|
|
secret: false,
|
2022-02-18 20:50:28 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: "hello",
|
2025-05-23 17:08:36 +00:00
|
|
|
currentValue: "there",
|
|
|
|
|
initialValue: "there",
|
2024-02-08 16:28:42 +00:00
|
|
|
secret: false,
|
2022-02-18 20:50:28 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
)()
|
|
|
|
|
).resolves.toEqualRight([
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
expectResults: [
|
|
|
|
|
{
|
|
|
|
|
status: "pass",
|
|
|
|
|
message: "Expected 'there' to be 'there'",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}),
|
|
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("returns unresolved value on infinite loop in resolution", () => {
|
|
|
|
|
return expect(
|
2025-10-27 12:19:58 +00:00
|
|
|
runTest(
|
2022-02-18 20:50:28 +00:00
|
|
|
`
|
|
|
|
|
const data = pw.env.getResolve("a")
|
|
|
|
|
pw.expect(data).toBe("<<hello>>")
|
|
|
|
|
`,
|
|
|
|
|
{
|
|
|
|
|
global: [],
|
|
|
|
|
selected: [
|
|
|
|
|
{
|
|
|
|
|
key: "a",
|
2025-05-23 17:08:36 +00:00
|
|
|
currentValue: "<<hello>>",
|
|
|
|
|
initialValue: "<<hello>>",
|
2024-02-08 16:28:42 +00:00
|
|
|
secret: false,
|
2022-02-18 20:50:28 +00:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: "hello",
|
2025-05-23 17:08:36 +00:00
|
|
|
currentValue: "<<a>>",
|
|
|
|
|
initialValue: "<<a>>",
|
2024-02-08 16:28:42 +00:00
|
|
|
secret: false,
|
2022-02-18 20:50:28 +00:00
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
)()
|
|
|
|
|
).resolves.toEqualRight([
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
expectResults: [
|
|
|
|
|
{
|
|
|
|
|
status: "pass",
|
|
|
|
|
message: "Expected '<<hello>>' to be '<<hello>>'",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}),
|
|
|
|
|
])
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test("errors if the key is not a string", () => {
|
|
|
|
|
return expect(
|
2025-10-27 12:19:58 +00:00
|
|
|
runTest(
|
2022-02-18 20:50:28 +00:00
|
|
|
`
|
|
|
|
|
const data = pw.env.getResolve(5)
|
|
|
|
|
`,
|
|
|
|
|
{
|
|
|
|
|
global: [],
|
|
|
|
|
selected: [],
|
|
|
|
|
}
|
|
|
|
|
)()
|
|
|
|
|
).resolves.toBeLeft()
|
|
|
|
|
})
|
|
|
|
|
})
|