feat: introduce APIs to update envs from tests and recursive resolution
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
import { execTestScript, TestResponse, TestResult } from "../../../test-runner"
|
||||
|
||||
import "@relmify/jest-fp-ts"
|
||||
|
||||
const fakeResponse: TestResponse = {
|
||||
status: 200,
|
||||
body: "hoi",
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, envs: TestResult["envs"]) =>
|
||||
pipe(
|
||||
execTestScript(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",
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).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",
|
||||
},
|
||||
],
|
||||
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",
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "selected val",
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).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>>",
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).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()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,219 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
import { execTestScript, TestResponse, TestResult } from "../../../test-runner"
|
||||
|
||||
import "@relmify/jest-fp-ts"
|
||||
|
||||
const fakeResponse: TestResponse = {
|
||||
status: 200,
|
||||
body: "hoi",
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, envs: TestResult["envs"]) =>
|
||||
pipe(
|
||||
execTestScript(script, envs, fakeResponse),
|
||||
TE.map((x) => x.tests),
|
||||
TE.mapLeft((x) => {
|
||||
console.log(x)
|
||||
return x
|
||||
})
|
||||
)
|
||||
|
||||
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",
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).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",
|
||||
},
|
||||
],
|
||||
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",
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "selected val",
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).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>>",
|
||||
},
|
||||
{
|
||||
key: "hello",
|
||||
value: "there",
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).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>>",
|
||||
},
|
||||
{
|
||||
key: "hello",
|
||||
value: "<<a>>",
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).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()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,156 @@
|
||||
import { pipe } from "fp-ts/function"
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { execTestScript, TestResponse, TestResult } from "../../../test-runner"
|
||||
|
||||
const fakeResponse: TestResponse = {
|
||||
status: 200,
|
||||
body: "hoi",
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, envs: TestResult["envs"]) =>
|
||||
pipe(
|
||||
execTestScript(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",
|
||||
},
|
||||
],
|
||||
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",
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).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",
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "hello",
|
||||
value: "there",
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).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>>",
|
||||
},
|
||||
{
|
||||
key: "there",
|
||||
value: "<<hello>>",
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
{
|
||||
status: "pass",
|
||||
message: "Expected '<<hello>>' to be '<<hello>>'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,208 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
import { execTestScript, TestResponse, TestResult } from "../../../test-runner"
|
||||
|
||||
const fakeResponse: TestResponse = {
|
||||
status: 200,
|
||||
body: "hoi",
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, envs: TestResult["envs"]) =>
|
||||
pipe(
|
||||
execTestScript(script, envs, fakeResponse),
|
||||
TE.map((x) => x.envs)
|
||||
)
|
||||
|
||||
const funcTest = (script: string, envs: TestResult["envs"]) =>
|
||||
pipe(
|
||||
execTestScript(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",
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "c",
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test("updates the global environment variable correctly", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.set("a", "c")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "a",
|
||||
value: "b",
|
||||
},
|
||||
],
|
||||
selected: [],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
global: [
|
||||
{
|
||||
key: "a",
|
||||
value: "c",
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test("updates the selected environment if env present in both", () => {
|
||||
return expect(
|
||||
func(
|
||||
`
|
||||
pw.env.set("a", "c")
|
||||
`,
|
||||
{
|
||||
global: [
|
||||
{
|
||||
key: "a",
|
||||
value: "b",
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "d",
|
||||
},
|
||||
],
|
||||
}
|
||||
)()
|
||||
).resolves.toEqualRight(
|
||||
expect.objectContaining({
|
||||
global: [
|
||||
{
|
||||
key: "a",
|
||||
value: "b",
|
||||
},
|
||||
],
|
||||
selected: [
|
||||
{
|
||||
key: "a",
|
||||
value: "c",
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
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",
|
||||
},
|
||||
],
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
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'",
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -1,3 +1,5 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
import { execTestScript, TestResponse } from "../../../test-runner"
|
||||
import "@relmify/jest-fp-ts"
|
||||
|
||||
@@ -7,11 +9,17 @@ const fakeResponse: TestResponse = {
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, res: TestResponse) =>
|
||||
pipe(
|
||||
execTestScript(script, { global: [], selected: [] }, res),
|
||||
TE.map((x) => x.tests)
|
||||
)
|
||||
|
||||
describe("toBe", () => {
|
||||
describe("general assertion (no negation)", () => {
|
||||
test("expect equals expected passes assertion", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(2).toBe(2)
|
||||
`,
|
||||
@@ -28,7 +36,7 @@ describe("toBe", () => {
|
||||
|
||||
test("expect not equals expected fails assertion", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(2).toBe(4)
|
||||
`,
|
||||
@@ -47,7 +55,7 @@ describe("toBe", () => {
|
||||
describe("general assertion (with negation)", () => {
|
||||
test("expect equals expected fails assertion", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(2).not.toBe(2)
|
||||
`,
|
||||
@@ -67,7 +75,7 @@ describe("toBe", () => {
|
||||
|
||||
test("expect not equals expected passes assertion", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(2).not.toBe(4)
|
||||
`,
|
||||
@@ -89,7 +97,7 @@ describe("toBe", () => {
|
||||
|
||||
test("strict checks types", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(2).toBe("2")
|
||||
`,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
import { execTestScript, TestResponse } from "../../../test-runner"
|
||||
import "@relmify/jest-fp-ts"
|
||||
|
||||
@@ -7,11 +9,17 @@ const fakeResponse: TestResponse = {
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, res: TestResponse) =>
|
||||
pipe(
|
||||
execTestScript(script, { global: [], selected: [] }, res),
|
||||
TE.map((x) => x.tests)
|
||||
)
|
||||
|
||||
describe("toBeLevel2xx", () => {
|
||||
test("assertion passes for 200 series with no negation", async () => {
|
||||
for (let i = 200; i < 300; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).toBeLevel2xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).toBeLevel2xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -28,7 +36,7 @@ describe("toBeLevel2xx", () => {
|
||||
test("assertion fails for non 200 series with no negation", async () => {
|
||||
for (let i = 300; i < 500; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).toBeLevel2xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).toBeLevel2xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -44,7 +52,7 @@ describe("toBeLevel2xx", () => {
|
||||
|
||||
test("give error if the expect value was not a number with no negation", async () => {
|
||||
await expect(
|
||||
execTestScript(`pw.expect("foo").toBeLevel2xx()`, fakeResponse)()
|
||||
func(`pw.expect("foo").toBeLevel2xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -61,7 +69,7 @@ describe("toBeLevel2xx", () => {
|
||||
test("assertion fails for 200 series with negation", async () => {
|
||||
for (let i = 200; i < 300; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).not.toBeLevel2xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).not.toBeLevel2xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -78,7 +86,7 @@ describe("toBeLevel2xx", () => {
|
||||
test("assertion passes for non 200 series with negation", async () => {
|
||||
for (let i = 300; i < 500; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).not.toBeLevel2xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).not.toBeLevel2xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -94,7 +102,7 @@ describe("toBeLevel2xx", () => {
|
||||
|
||||
test("give error if the expect value was not a number with negation", async () => {
|
||||
await expect(
|
||||
execTestScript(`pw.expect("foo").not.toBeLevel2xx()`, fakeResponse)()
|
||||
func(`pw.expect("foo").not.toBeLevel2xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -113,7 +121,7 @@ describe("toBeLevel3xx", () => {
|
||||
test("assertion passes for 300 series with no negation", async () => {
|
||||
for (let i = 300; i < 400; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).toBeLevel3xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).toBeLevel3xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -130,7 +138,7 @@ describe("toBeLevel3xx", () => {
|
||||
test("assertion fails for non 300 series with no negation", async () => {
|
||||
for (let i = 400; i < 500; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).toBeLevel3xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).toBeLevel3xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -146,7 +154,7 @@ describe("toBeLevel3xx", () => {
|
||||
|
||||
test("give error if the expect value is not a number without negation", () => {
|
||||
return expect(
|
||||
execTestScript(`pw.expect("foo").toBeLevel3xx()`, fakeResponse)()
|
||||
func(`pw.expect("foo").toBeLevel3xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -163,7 +171,7 @@ describe("toBeLevel3xx", () => {
|
||||
test("assertion fails for 400 series with negation", async () => {
|
||||
for (let i = 300; i < 400; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).not.toBeLevel3xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).not.toBeLevel3xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -180,7 +188,7 @@ describe("toBeLevel3xx", () => {
|
||||
test("assertion passes for non 200 series with negation", async () => {
|
||||
for (let i = 400; i < 500; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).not.toBeLevel3xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).not.toBeLevel3xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -196,7 +204,7 @@ describe("toBeLevel3xx", () => {
|
||||
|
||||
test("give error if the expect value is not a number with negation", () => {
|
||||
return expect(
|
||||
execTestScript(`pw.expect("foo").not.toBeLevel3xx()`, fakeResponse)()
|
||||
func(`pw.expect("foo").not.toBeLevel3xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -215,7 +223,7 @@ describe("toBeLevel4xx", () => {
|
||||
test("assertion passes for 400 series with no negation", async () => {
|
||||
for (let i = 400; i < 500; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).toBeLevel4xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).toBeLevel4xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -232,7 +240,7 @@ describe("toBeLevel4xx", () => {
|
||||
test("assertion fails for non 400 series with no negation", async () => {
|
||||
for (let i = 500; i < 600; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).toBeLevel4xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).toBeLevel4xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -248,7 +256,7 @@ describe("toBeLevel4xx", () => {
|
||||
|
||||
test("give error if the expected value is not a number without negation", () => {
|
||||
return expect(
|
||||
execTestScript(`pw.expect("foo").toBeLevel4xx()`, fakeResponse)()
|
||||
func(`pw.expect("foo").toBeLevel4xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -265,7 +273,7 @@ describe("toBeLevel4xx", () => {
|
||||
test("assertion fails for 400 series with negation", async () => {
|
||||
for (let i = 400; i < 500; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).not.toBeLevel4xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).not.toBeLevel4xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -282,7 +290,7 @@ describe("toBeLevel4xx", () => {
|
||||
test("assertion passes for non 400 series with negation", async () => {
|
||||
for (let i = 500; i < 600; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).not.toBeLevel4xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).not.toBeLevel4xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -298,7 +306,7 @@ describe("toBeLevel4xx", () => {
|
||||
|
||||
test("give error if the expected value is not a number with negation", () => {
|
||||
return expect(
|
||||
execTestScript(`pw.expect("foo").not.toBeLevel4xx()`, fakeResponse)()
|
||||
func(`pw.expect("foo").not.toBeLevel4xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -317,7 +325,7 @@ describe("toBeLevel5xx", () => {
|
||||
test("assertion passes for 500 series with no negation", async () => {
|
||||
for (let i = 500; i < 600; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).toBeLevel5xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).toBeLevel5xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -334,7 +342,7 @@ describe("toBeLevel5xx", () => {
|
||||
test("assertion fails for non 500 series with no negation", async () => {
|
||||
for (let i = 200; i < 500; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).toBeLevel5xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).toBeLevel5xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -350,7 +358,7 @@ describe("toBeLevel5xx", () => {
|
||||
|
||||
test("give error if the expect value is not a number with no negation", () => {
|
||||
return expect(
|
||||
execTestScript(`pw.expect("foo").toBeLevel5xx()`, fakeResponse)()
|
||||
func(`pw.expect("foo").toBeLevel5xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -367,7 +375,7 @@ describe("toBeLevel5xx", () => {
|
||||
test("assertion fails for 500 series with negation", async () => {
|
||||
for (let i = 500; i < 600; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).not.toBeLevel5xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).not.toBeLevel5xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -384,7 +392,7 @@ describe("toBeLevel5xx", () => {
|
||||
test("assertion passes for non 500 series with negation", async () => {
|
||||
for (let i = 200; i < 500; i++) {
|
||||
await expect(
|
||||
execTestScript(`pw.expect(${i}).not.toBeLevel5xx()`, fakeResponse)()
|
||||
func(`pw.expect(${i}).not.toBeLevel5xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
@@ -400,7 +408,7 @@ describe("toBeLevel5xx", () => {
|
||||
|
||||
test("give error if the expect value is not a number with negation", () => {
|
||||
return expect(
|
||||
execTestScript(`pw.expect("foo").not.toBeLevel5xx()`, fakeResponse)()
|
||||
func(`pw.expect("foo").not.toBeLevel5xx()`, fakeResponse)()
|
||||
).resolves.toEqualRight([
|
||||
expect.objectContaining({
|
||||
expectResults: [
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
import { execTestScript, TestResponse } from "../../../test-runner"
|
||||
|
||||
const fakeResponse: TestResponse = {
|
||||
@@ -6,10 +8,16 @@ const fakeResponse: TestResponse = {
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, res: TestResponse) =>
|
||||
pipe(
|
||||
execTestScript(script, { global: [], selected: [] }, res),
|
||||
TE.map((x) => x.tests)
|
||||
)
|
||||
|
||||
describe("toBeType", () => {
|
||||
test("asserts true for valid type expectations with no negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(2).toBeType("number")
|
||||
pw.expect("2").toBeType("string")
|
||||
@@ -40,7 +48,7 @@ describe("toBeType", () => {
|
||||
|
||||
test("asserts false for invalid type expectations with no negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(2).toBeType("string")
|
||||
pw.expect("2").toBeType("number")
|
||||
@@ -71,7 +79,7 @@ describe("toBeType", () => {
|
||||
|
||||
test("asserts false for valid type expectations with negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(2).not.toBeType("number")
|
||||
pw.expect("2").not.toBeType("string")
|
||||
@@ -105,7 +113,7 @@ describe("toBeType", () => {
|
||||
|
||||
test("asserts true for invalid type expectations with negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(2).not.toBeType("string")
|
||||
pw.expect("2").not.toBeType("number")
|
||||
@@ -139,7 +147,7 @@ describe("toBeType", () => {
|
||||
|
||||
test("gives error for invalid type names without negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(2).toBeType("foo")
|
||||
pw.expect("2").toBeType("bar")
|
||||
@@ -179,7 +187,7 @@ describe("toBeType", () => {
|
||||
|
||||
test("gives error for invalid type names with negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(2).not.toBeType("foo")
|
||||
pw.expect("2").not.toBeType("bar")
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
import { execTestScript, TestResponse } from "../../../test-runner"
|
||||
|
||||
const fakeResponse: TestResponse = {
|
||||
@@ -6,10 +8,16 @@ const fakeResponse: TestResponse = {
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, res: TestResponse) =>
|
||||
pipe(
|
||||
execTestScript(script, { global: [], selected: [] }, res),
|
||||
TE.map((x) => x.tests)
|
||||
)
|
||||
|
||||
describe("toHaveLength", () => {
|
||||
test("asserts true for valid lengths with no negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect([1, 2, 3, 4]).toHaveLength(4)
|
||||
pw.expect([]).toHaveLength(0)
|
||||
@@ -28,7 +36,7 @@ describe("toHaveLength", () => {
|
||||
|
||||
test("asserts false for invalid lengths with no negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect([]).toHaveLength(4)
|
||||
pw.expect([1, 2, 3, 4]).toHaveLength(0)
|
||||
@@ -47,7 +55,7 @@ describe("toHaveLength", () => {
|
||||
|
||||
test("asserts false for valid lengths with negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect([1, 2, 3, 4]).not.toHaveLength(4)
|
||||
pw.expect([]).not.toHaveLength(0)
|
||||
@@ -72,7 +80,7 @@ describe("toHaveLength", () => {
|
||||
|
||||
test("asserts true for invalid lengths with negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect([]).not.toHaveLength(4)
|
||||
pw.expect([1, 2, 3, 4]).not.toHaveLength(0)
|
||||
@@ -97,7 +105,7 @@ describe("toHaveLength", () => {
|
||||
|
||||
test("gives error if not called on an array or a string with no negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(5).toHaveLength(0)
|
||||
pw.expect(true).toHaveLength(0)
|
||||
@@ -124,7 +132,7 @@ describe("toHaveLength", () => {
|
||||
|
||||
test("gives error if not called on an array or a string with negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect(5).not.toHaveLength(0)
|
||||
pw.expect(true).not.toHaveLength(0)
|
||||
@@ -151,7 +159,7 @@ describe("toHaveLength", () => {
|
||||
|
||||
test("gives an error if toHaveLength parameter is not a number without negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect([1, 2, 3, 4]).toHaveLength("a")
|
||||
`,
|
||||
@@ -171,7 +179,7 @@ describe("toHaveLength", () => {
|
||||
|
||||
test("gives an error if toHaveLength parameter is not a number with negation", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.expect([1, 2, 3, 4]).not.toHaveLength("a")
|
||||
`,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import * as TE from "fp-ts/TaskEither"
|
||||
import { pipe } from "fp-ts/function"
|
||||
import { execTestScript, TestResponse } from "../../test-runner"
|
||||
|
||||
const fakeResponse: TestResponse = {
|
||||
@@ -6,10 +8,16 @@ const fakeResponse: TestResponse = {
|
||||
headers: [],
|
||||
}
|
||||
|
||||
const func = (script: string, res: TestResponse) =>
|
||||
pipe(
|
||||
execTestScript(script, { global: [], selected: [] }, res),
|
||||
TE.map((x) => x.tests)
|
||||
)
|
||||
|
||||
describe("execTestScript function behavior", () => {
|
||||
test("returns a resolved promise for a valid test scripts with all green", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.test("Arithmetic operations", () => {
|
||||
const size = 500 + 500;
|
||||
@@ -26,7 +34,7 @@ describe("execTestScript function behavior", () => {
|
||||
|
||||
test("resolves for tests with failed expectations", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.test("Arithmetic operations", () => {
|
||||
const size = 500 + 500;
|
||||
@@ -44,7 +52,7 @@ describe("execTestScript function behavior", () => {
|
||||
// TODO: We need a more concrete behavior for this
|
||||
test("rejects for invalid syntax on tests", () => {
|
||||
return expect(
|
||||
execTestScript(
|
||||
func(
|
||||
`
|
||||
pw.test("Arithmetic operations", () => {
|
||||
const size = 500 + 500;
|
||||
|
||||
Reference in New Issue
Block a user