chore: lint + bump deps

This commit is contained in:
liyasthomas
2021-11-04 18:23:50 +05:30
parent ad76d100ee
commit 9e74a8c2e7
32 changed files with 1248 additions and 1265 deletions

View File

@@ -8,11 +8,14 @@ describe("execPreRequestScript", () => {
`
pw.env.set("bob", "newbob")
`,
[{ key: "bob", value: "oldbob" }, { key: "foo", value: "bar" }]
[
{ key: "bob", value: "oldbob" },
{ key: "foo", value: "bar" },
]
)()
).resolves.toEqualRight([
{ key: "bob", value: "newbob" },
{ key: "foo", value: "bar" }
{ key: "foo", value: "bar" },
])
})
@@ -22,7 +25,10 @@ describe("execPreRequestScript", () => {
`
pw.env.set(10, "newbob")
`,
[{ key: "bob", value: "oldbob" }, { key: "foo", value: "bar" }]
[
{ key: "bob", value: "oldbob" },
{ key: "foo", value: "bar" },
]
)()
).resolves.toBeLeft()
})
@@ -33,7 +39,10 @@ describe("execPreRequestScript", () => {
`
pw.env.set("bob", 10)
`,
[{ key: "bob", value: "oldbob" }, { key: "foo", value: "bar" }]
[
{ key: "bob", value: "oldbob" },
{ key: "foo", value: "bar" },
]
)()
).resolves.toBeLeft()
})
@@ -44,7 +53,10 @@ describe("execPreRequestScript", () => {
`
pw.env.set("bob",
`,
[{ key: "bob", value: "oldbob" }, { key: "foo", value: "bar" }]
[
{ key: "bob", value: "oldbob" },
{ key: "foo", value: "bar" },
]
)()
).resolves.toBeLeft()
})
@@ -57,8 +69,6 @@ describe("execPreRequestScript", () => {
`,
[]
)()
).resolves.toEqualRight(
[{ key: "foo", value: "bar" }]
)
).resolves.toEqualRight([{ key: "foo", value: "bar" }])
})
})
})

View File

@@ -4,7 +4,7 @@ import "@relmify/jest-fp-ts"
const fakeResponse: TestResponse = {
status: 200,
body: "hoi",
headers: []
headers: [],
}
describe("toBe", () => {
@@ -19,7 +19,9 @@ describe("toBe", () => {
)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{ status: "pass", message: "Expected '2' to be '2'" }],
expectResults: [
{ status: "pass", message: "Expected '2' to be '2'" },
],
}),
])
})
@@ -34,7 +36,9 @@ describe("toBe", () => {
)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{ status: "fail", message: "Expected '2' to be '4'" }],
expectResults: [
{ status: "fail", message: "Expected '2' to be '4'" },
],
}),
])
})
@@ -51,10 +55,12 @@ describe("toBe", () => {
)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "fail",
message: "Expected '2' to not be '2'",
}],
expectResults: [
{
status: "fail",
message: "Expected '2' to not be '2'",
},
],
}),
])
})
@@ -69,10 +75,12 @@ describe("toBe", () => {
)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "pass",
message: "Expected '2' to not be '4'",
}],
expectResults: [
{
status: "pass",
message: "Expected '2' to not be '4'",
},
],
}),
])
})
@@ -85,14 +93,16 @@ test("strict checks types", () => {
`
pw.expect(2).toBe("2")
`,
fakeResponse
fakeResponse
)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "fail",
message: "Expected '2' to be '2'",
}],
expectResults: [
{
status: "fail",
message: "Expected '2' to be '2'",
},
],
}),
])
})

View File

@@ -4,7 +4,7 @@ import "@relmify/jest-fp-ts"
const fakeResponse: TestResponse = {
status: 200,
body: "hoi",
headers: []
headers: [],
}
describe("toBeLevel2xx", () => {
@@ -14,10 +14,12 @@ describe("toBeLevel2xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel2xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "pass",
message: `Expected '${i}' to be 200-level status`,
}],
expectResults: [
{
status: "pass",
message: `Expected '${i}' to be 200-level status`,
},
],
}),
])
}
@@ -29,10 +31,12 @@ describe("toBeLevel2xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel2xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "fail",
message: `Expected '${i}' to be 200-level status`,
}],
expectResults: [
{
status: "fail",
message: `Expected '${i}' to be 200-level status`,
},
],
}),
])
}
@@ -43,11 +47,14 @@ describe("toBeLevel2xx", () => {
execTestScript(`pw.expect("foo").toBeLevel2xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 200-level status but could not parse value 'foo'",
}],
})
expectResults: [
{
status: "error",
message:
"Expected 200-level status but could not parse value 'foo'",
},
],
}),
])
})
@@ -57,10 +64,12 @@ describe("toBeLevel2xx", () => {
execTestScript(`pw.expect(${i}).not.toBeLevel2xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "fail",
message: `Expected '${i}' to not be 200-level status`,
}],
expectResults: [
{
status: "fail",
message: `Expected '${i}' to not be 200-level status`,
},
],
}),
])
}
@@ -72,10 +81,12 @@ describe("toBeLevel2xx", () => {
execTestScript(`pw.expect(${i}).not.toBeLevel2xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "pass",
message: `Expected '${i}' to not be 200-level status`,
}],
expectResults: [
{
status: "pass",
message: `Expected '${i}' to not be 200-level status`,
},
],
}),
])
}
@@ -86,11 +97,14 @@ describe("toBeLevel2xx", () => {
execTestScript(`pw.expect("foo").not.toBeLevel2xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 200-level status but could not parse value 'foo'",
}],
})
expectResults: [
{
status: "error",
message:
"Expected 200-level status but could not parse value 'foo'",
},
],
}),
])
})
})
@@ -102,10 +116,12 @@ describe("toBeLevel3xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel3xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "pass",
message: `Expected '${i}' to be 300-level status`,
}],
expectResults: [
{
status: "pass",
message: `Expected '${i}' to be 300-level status`,
},
],
}),
])
}
@@ -117,10 +133,12 @@ describe("toBeLevel3xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel3xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "fail",
message: `Expected '${i}' to be 300-level status`,
}],
expectResults: [
{
status: "fail",
message: `Expected '${i}' to be 300-level status`,
},
],
}),
])
}
@@ -131,11 +149,14 @@ describe("toBeLevel3xx", () => {
execTestScript(`pw.expect("foo").toBeLevel3xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 300-level status but could not parse value 'foo'",
}],
})
expectResults: [
{
status: "error",
message:
"Expected 300-level status but could not parse value 'foo'",
},
],
}),
])
})
@@ -145,10 +166,12 @@ describe("toBeLevel3xx", () => {
execTestScript(`pw.expect(${i}).not.toBeLevel3xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "fail",
message: `Expected '${i}' to not be 300-level status`,
}],
expectResults: [
{
status: "fail",
message: `Expected '${i}' to not be 300-level status`,
},
],
}),
])
}
@@ -160,10 +183,12 @@ describe("toBeLevel3xx", () => {
execTestScript(`pw.expect(${i}).not.toBeLevel3xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "pass",
message: `Expected '${i}' to not be 300-level status`,
}],
expectResults: [
{
status: "pass",
message: `Expected '${i}' to not be 300-level status`,
},
],
}),
])
}
@@ -174,14 +199,16 @@ describe("toBeLevel3xx", () => {
execTestScript(`pw.expect("foo").not.toBeLevel3xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 300-level status but could not parse value 'foo'",
}]
})
expectResults: [
{
status: "error",
message:
"Expected 300-level status but could not parse value 'foo'",
},
],
}),
])
})
})
describe("toBeLevel4xx", () => {
@@ -191,10 +218,12 @@ describe("toBeLevel4xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel4xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "pass",
message: `Expected '${i}' to be 400-level status`,
}],
expectResults: [
{
status: "pass",
message: `Expected '${i}' to be 400-level status`,
},
],
}),
])
}
@@ -206,10 +235,12 @@ describe("toBeLevel4xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel4xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "fail",
message: `Expected '${i}' to be 400-level status`,
}],
expectResults: [
{
status: "fail",
message: `Expected '${i}' to be 400-level status`,
},
],
}),
])
}
@@ -220,11 +251,14 @@ describe("toBeLevel4xx", () => {
execTestScript(`pw.expect("foo").toBeLevel4xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 400-level status but could not parse value 'foo'",
}],
})
expectResults: [
{
status: "error",
message:
"Expected 400-level status but could not parse value 'foo'",
},
],
}),
])
})
@@ -234,10 +268,12 @@ describe("toBeLevel4xx", () => {
execTestScript(`pw.expect(${i}).not.toBeLevel4xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "fail",
message: `Expected '${i}' to not be 400-level status`,
}],
expectResults: [
{
status: "fail",
message: `Expected '${i}' to not be 400-level status`,
},
],
}),
])
}
@@ -249,10 +285,12 @@ describe("toBeLevel4xx", () => {
execTestScript(`pw.expect(${i}).not.toBeLevel4xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "pass",
message: `Expected '${i}' to not be 400-level status`,
}],
expectResults: [
{
status: "pass",
message: `Expected '${i}' to not be 400-level status`,
},
],
}),
])
}
@@ -263,11 +301,14 @@ describe("toBeLevel4xx", () => {
execTestScript(`pw.expect("foo").not.toBeLevel4xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 400-level status but could not parse value 'foo'",
}],
})
expectResults: [
{
status: "error",
message:
"Expected 400-level status but could not parse value 'foo'",
},
],
}),
])
})
})
@@ -279,10 +320,12 @@ describe("toBeLevel5xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel5xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "pass",
message: `Expected '${i}' to be 500-level status`,
}],
expectResults: [
{
status: "pass",
message: `Expected '${i}' to be 500-level status`,
},
],
}),
])
}
@@ -294,10 +337,12 @@ describe("toBeLevel5xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel5xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "fail",
message: `Expected '${i}' to be 500-level status`,
}],
expectResults: [
{
status: "fail",
message: `Expected '${i}' to be 500-level status`,
},
],
}),
])
}
@@ -308,11 +353,14 @@ describe("toBeLevel5xx", () => {
execTestScript(`pw.expect("foo").toBeLevel5xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 500-level status but could not parse value 'foo'",
}],
})
expectResults: [
{
status: "error",
message:
"Expected 500-level status but could not parse value 'foo'",
},
],
}),
])
})
@@ -322,10 +370,12 @@ describe("toBeLevel5xx", () => {
execTestScript(`pw.expect(${i}).not.toBeLevel5xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "fail",
message: `Expected '${i}' to not be 500-level status`,
}],
expectResults: [
{
status: "fail",
message: `Expected '${i}' to not be 500-level status`,
},
],
}),
])
}
@@ -337,10 +387,12 @@ describe("toBeLevel5xx", () => {
execTestScript(`pw.expect(${i}).not.toBeLevel5xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "pass",
message: `Expected '${i}' to not be 500-level status`,
}],
expectResults: [
{
status: "pass",
message: `Expected '${i}' to not be 500-level status`,
},
],
}),
])
}
@@ -351,11 +403,14 @@ describe("toBeLevel5xx", () => {
execTestScript(`pw.expect("foo").not.toBeLevel5xx()`, fakeResponse)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 500-level status but could not parse value 'foo'",
}],
})
expectResults: [
{
status: "error",
message:
"Expected 500-level status but could not parse value 'foo'",
},
],
}),
])
})
})
})

View File

@@ -3,7 +3,7 @@ import { execTestScript, TestResponse } from "../../../test-runner"
const fakeResponse: TestResponse = {
status: 200,
body: "hoi",
headers: []
headers: [],
}
describe("toBeType", () => {
@@ -16,16 +16,23 @@ describe("toBeType", () => {
pw.expect(true).toBeType("boolean")
pw.expect({}).toBeType("object")
pw.expect(undefined).toBeType("undefined")
`, fakeResponse
`,
fakeResponse
)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [
{ status: "pass", message: `Expected '2' to be type 'number'` },
{ status: "pass", message: `Expected '2' to be type 'number'` },
{ status: "pass", message: `Expected '2' to be type 'string'` },
{ status: "pass", message: `Expected 'true' to be type 'boolean'` },
{ status: "pass", message: `Expected '[object Object]' to be type 'object'` },
{ status: "pass", message: `Expected 'undefined' to be type 'undefined'` },
{
status: "pass",
message: `Expected '[object Object]' to be type 'object'`,
},
{
status: "pass",
message: `Expected 'undefined' to be type 'undefined'`,
},
],
}),
])
@@ -46,11 +53,17 @@ describe("toBeType", () => {
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [
{ status: "fail", message: `Expected '2' to be type 'string'`},
{ status: "fail", message: `Expected '2' to be type 'number'`},
{ status: "fail", message: `Expected 'true' to be type 'string'`},
{ status: "fail", message: `Expected '[object Object]' to be type 'number'`},
{ status: "fail", message: `Expected 'undefined' to be type 'number'`},
{ status: "fail", message: `Expected '2' to be type 'string'` },
{ status: "fail", message: `Expected '2' to be type 'number'` },
{ status: "fail", message: `Expected 'true' to be type 'string'` },
{
status: "fail",
message: `Expected '[object Object]' to be type 'number'`,
},
{
status: "fail",
message: `Expected 'undefined' to be type 'number'`,
},
],
}),
])
@@ -65,16 +78,26 @@ describe("toBeType", () => {
pw.expect(true).not.toBeType("boolean")
pw.expect({}).not.toBeType("object")
pw.expect(undefined).not.toBeType("undefined")
`, fakeResponse
`,
fakeResponse
)()
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [
{ status: "fail", message: `Expected '2' to not be type 'number'` },
{ status: "fail", message: `Expected '2' to not be type 'string'` },
{ status: "fail", message: `Expected 'true' to not be type 'boolean'` },
{ status: "fail", message: `Expected '[object Object]' to not be type 'object'` },
{ status: "fail", message: `Expected 'undefined' to not be type 'undefined'` },
{
status: "fail",
message: `Expected 'true' to not be type 'boolean'`,
},
{
status: "fail",
message: `Expected '[object Object]' to not be type 'object'`,
},
{
status: "fail",
message: `Expected 'undefined' to not be type 'undefined'`,
},
],
}),
])
@@ -97,9 +120,18 @@ describe("toBeType", () => {
expectResults: [
{ status: "pass", message: `Expected '2' to not be type 'string'` },
{ status: "pass", message: `Expected '2' to not be type 'number'` },
{ status: "pass", message: `Expected 'true' to not be type 'string'` },
{ status: "pass", message: `Expected '[object Object]' to not be type 'number'` },
{ status: "pass", message: `Expected 'undefined' to not be type 'number'` },
{
status: "pass",
message: `Expected 'true' to not be type 'string'`,
},
{
status: "pass",
message: `Expected '[object Object]' to not be type 'number'`,
},
{
status: "pass",
message: `Expected 'undefined' to not be type 'number'`,
},
],
}),
])
@@ -120,13 +152,28 @@ describe("toBeType", () => {
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [
{ status: "error", message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"` },
{ status: "error", message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"` },
{ status: "error", message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"` },
{ status: "error", message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"` },
{ status: "error", message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"` },
]
})
{
status: "error",
message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"`,
},
{
status: "error",
message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"`,
},
{
status: "error",
message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"`,
},
{
status: "error",
message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"`,
},
{
status: "error",
message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"`,
},
],
}),
])
})
@@ -145,13 +192,28 @@ describe("toBeType", () => {
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [
{ status: "error", message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"` },
{ status: "error", message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"` },
{ status: "error", message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"` },
{ status: "error", message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"` },
{ status: "error", message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"` },
]
})
{
status: "error",
message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"`,
},
{
status: "error",
message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"`,
},
{
status: "error",
message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"`,
},
{
status: "error",
message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"`,
},
{
status: "error",
message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"`,
},
],
}),
])
})
})

View File

@@ -3,7 +3,7 @@ import { execTestScript, TestResponse } from "../../../test-runner"
const fakeResponse: TestResponse = {
status: 200,
body: "hoi",
headers: []
headers: [],
}
describe("toHaveLength", () => {
@@ -20,7 +20,7 @@ describe("toHaveLength", () => {
expect.objectContaining({
expectResults: [
{ status: "pass", message: "Expected the array to be of length '4'" },
{ status: "pass", message: "Expected the array to be of length '0'" },
{ status: "pass", message: "Expected the array to be of length '0'" },
],
}),
])
@@ -57,8 +57,14 @@ describe("toHaveLength", () => {
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [
{ status: "fail", message: "Expected the array to not be of length '4'" },
{ status: "fail", message: "Expected the array to not be of length '0'" },
{
status: "fail",
message: "Expected the array to not be of length '4'",
},
{
status: "fail",
message: "Expected the array to not be of length '0'",
},
],
}),
])
@@ -76,8 +82,14 @@ describe("toHaveLength", () => {
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [
{ status: "pass", message: "Expected the array to not be of length '4'" },
{ status: "pass", message: "Expected the array to not be of length '0'" },
{
status: "pass",
message: "Expected the array to not be of length '4'",
},
{
status: "pass",
message: "Expected the array to not be of length '0'",
},
],
}),
])
@@ -95,10 +107,18 @@ describe("toHaveLength", () => {
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [
{ status: "error", message: "Expected toHaveLength to be called for an array or string" },
{ status: "error", message: "Expected toHaveLength to be called for an array or string" },
]
})
{
status: "error",
message:
"Expected toHaveLength to be called for an array or string",
},
{
status: "error",
message:
"Expected toHaveLength to be called for an array or string",
},
],
}),
])
})
@@ -114,10 +134,18 @@ describe("toHaveLength", () => {
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [
{ status: "error", message: "Expected toHaveLength to be called for an array or string" },
{ status: "error", message: "Expected toHaveLength to be called for an array or string" },
]
})
{
status: "error",
message:
"Expected toHaveLength to be called for an array or string",
},
{
status: "error",
message:
"Expected toHaveLength to be called for an array or string",
},
],
}),
])
})
@@ -132,9 +160,12 @@ describe("toHaveLength", () => {
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [
{ status: "error", message: "Argument for toHaveLength should be a number" },
{
status: "error",
message: "Argument for toHaveLength should be a number",
},
],
})
}),
])
})
@@ -149,9 +180,12 @@ describe("toHaveLength", () => {
).resolves.toEqualRight([
expect.objectContaining({
expectResults: [
{ status: "error", message: "Argument for toHaveLength should be a number" },
{
status: "error",
message: "Argument for toHaveLength should be a number",
},
],
})
}),
])
})
})

View File

@@ -3,7 +3,7 @@ import { execTestScript, TestResponse } from "../../test-runner"
const fakeResponse: TestResponse = {
status: 200,
body: "hoi",
headers: []
headers: [],
}
describe("execTestScript function behavior", () => {
@@ -21,7 +21,7 @@ describe("execTestScript function behavior", () => {
`,
fakeResponse
)()
).resolves.toBeRight();
).resolves.toBeRight()
})
test("resolves for tests with failed expectations", () => {
@@ -35,7 +35,8 @@ describe("execTestScript function behavior", () => {
pw.expect(size * 4).toBe(4000);
pw.expect(size / 4).not.toBe(250);
});
`, fakeResponse
`,
fakeResponse
)()
).resolves.toBeRight()
})
@@ -52,7 +53,8 @@ describe("execTestScript function behavior", () => {
pw.expect(size * 4).toBe(4000);
pw.expect(size / 4).not.toBe(250);
});
`, fakeResponse
`,
fakeResponse
)()
).resolves.toBeLeft()
})

View File

@@ -15,16 +15,15 @@ afterAll(() => {
})
describe("marshalObjectToVM", () => {
test("successfully marshals simple object into the vm", () => {
const testObj = {
a: 1
a: 1,
}
const objVMHandle: QuickJS.QuickJSHandle | null = pipe(
marshalObjectToVM(vm, testObj),
match(
(e) => null,
() => null,
(result) => result
)
)
@@ -38,7 +37,7 @@ describe("marshalObjectToVM", () => {
test("fails marshalling cyclic object into vm", () => {
const testObj = {
a: 1,
b: null as any
b: null as any,
}
testObj.b = testObj
@@ -46,12 +45,11 @@ describe("marshalObjectToVM", () => {
const objVMHandle: QuickJS.QuickJSHandle | null = pipe(
marshalObjectToVM(vm, testObj),
match(
(e) => null,
() => null,
(result) => result
)
)
expect(objVMHandle).toBeNull()
})
})
})

View File

@@ -1,15 +1,13 @@
import { runTestScript } from "./index"
import { TestResponse } from "./test-runner"
const dummyResponse: TestResponse = {
status: 200,
body: "hoi",
headers: []
};
headers: [],
}
// eslint-disable-next-line prettier/prettier
(async () => {
;(async () => {
console.dir(
await runTestScript(
`
@@ -46,7 +44,7 @@ const dummyResponse: TestResponse = {
pw.expect(arr).not.toHaveLength(4);
});
`,
dummyResponse
dummyResponse
),
{
depth: 100,

View File

@@ -1 +1 @@
import '@relmify/jest-fp-ts';
import "@relmify/jest-fp-ts"

View File

@@ -1,7 +1,11 @@
import { pipe } from "fp-ts/lib/function"
import { chain, right } from "fp-ts/lib/TaskEither"
import { execPreRequestScript } from "./preRequest"
import { execTestScript, TestResponse, TestDescriptor as _TestDescriptor } from "./test-runner"
import {
execTestScript,
TestResponse,
TestDescriptor as _TestDescriptor,
} from "./test-runner"
export type TestDescriptor = _TestDescriptor
/**
@@ -9,13 +13,11 @@ export type TestDescriptor = _TestDescriptor
* @param testScript The string of the script to run
* @returns A TaskEither with an error message or a TestDescriptor with the final status
*/
export const runTestScript = (
testScript: string,
response: TestResponse
) => pipe(
execTestScript(testScript, response),
chain((results) => right(results[0])) // execTestScript returns an array of descriptors with a single element (extract that)
)
export const runTestScript = (testScript: string, response: TestResponse) =>
pipe(
execTestScript(testScript, response),
chain((results) => right(results[0])) // execTestScript returns an array of descriptors with a single element (extract that)
)
/**
* Executes a given pre-request script on the sandbox
@@ -23,4 +25,4 @@ export const runTestScript = (
* @param env The envirionment variables active
* @returns A TaskEither with an error message or an array of the final environments with the all the script values applied
*/
export const runPreRequestScript = execPreRequestScript
export const runPreRequestScript = execPreRequestScript

View File

@@ -1,23 +1,23 @@
import { pipe } from "fp-ts/lib/function";
import { chain, TaskEither, tryCatch, right, left } from "fp-ts/lib/TaskEither";
import * as qjs from "quickjs-emscripten";
import clone from "lodash/clone";
import { pipe } from "fp-ts/lib/function"
import { chain, TaskEither, tryCatch, right, left } from "fp-ts/lib/TaskEither"
import * as qjs from "quickjs-emscripten"
import clone from "lodash/clone"
type EnvEntry = {
key: string;
value: string;
};
key: string
value: string
}
export const execPreRequestScript = (
preRequestScript: string,
env: EnvEntry[]
): TaskEither<string, EnvEntry[]> => pipe(
tryCatch(
async () => await qjs.getQuickJS(),
(reason) => `QuickJS initialization failed: ${reason}`
),
chain(
(QuickJS) => {
): TaskEither<string, EnvEntry[]> =>
pipe(
tryCatch(
async () => await qjs.getQuickJS(),
(reason) => `QuickJS initialization failed: ${reason}`
),
chain((QuickJS) => {
const finalEnv = clone(env)
const vm = QuickJS.createVm()
@@ -26,30 +26,35 @@ export const execPreRequestScript = (
const envHandle = vm.newObject()
const envSetFuncHandle = vm.newFunction("set", (keyHandle, valueHandle) => {
const key = vm.dump(keyHandle)
const value = vm.dump(valueHandle)
const envSetFuncHandle = vm.newFunction(
"set",
(keyHandle, valueHandle) => {
const key = vm.dump(keyHandle)
const value = vm.dump(valueHandle)
if (typeof key !== "string") return {
error: vm.newString("Expected key to be a string")
if (typeof key !== "string")
return {
error: vm.newString("Expected key to be a string"),
}
if (typeof value !== "string")
return {
error: vm.newString("Expected value to be a string"),
}
const keyIndex = finalEnv.findIndex((env) => env.key === key)
if (keyIndex === -1) {
finalEnv.push({ key, value })
} else {
finalEnv[keyIndex] = { key, value }
}
return {
value: vm.undefined,
}
}
if (typeof value !== "string") return {
error: vm.newString("Expected value to be a string")
}
const keyIndex = finalEnv.findIndex((env) => env.key === key)
if (keyIndex === -1) {
finalEnv.push({ key, value })
} else {
finalEnv[keyIndex] = { key, value }
}
return {
value: vm.undefined
}
})
)
vm.setProp(envHandle, "set", envSetFuncHandle)
envSetFuncHandle.dispose()
@@ -72,6 +77,5 @@ export const execPreRequestScript = (
vm.dispose()
return right(finalEnv)
}
})
)
)

View File

@@ -9,9 +9,9 @@ import { marshalObjectToVM } from "./utils"
*/
export type TestResponse = {
/** Status Code of the response */
status: number,
status: number
/** List of headers returned */
headers: { key: string, value: string }[],
headers: { key: string; value: string }[]
/**
* Body of the response, this will be the JSON object if it is a JSON content type, else body string
*/
@@ -21,8 +21,7 @@ export type TestResponse = {
/**
* The result of an expectation statement
*/
type ExpectResult =
| { status: "pass" | "fail" | "error", message: string } // The expectation failed (fail) or errored (error)
type ExpectResult = { status: "pass" | "fail" | "error"; message: string } // The expectation failed (fail) or errored (error)
/**
* An object defining the result of the execution of a
@@ -68,14 +67,18 @@ function createExpectation(
if (negated) assertion = !assertion
if (assertion) {
currTestStack[currTestStack.length - 1].expectResults.push({
currTestStack[currTestStack.length - 1].expectResults.push({
status: "pass",
message: `Expected '${expectVal}' to${negated ? " not" : ""} be '${expectedVal}'`
message: `Expected '${expectVal}' to${
negated ? " not" : ""
} be '${expectedVal}'`,
})
} else {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "fail",
message: `Expected '${expectVal}' to${negated ? " not" : ""} be '${expectedVal}'`,
message: `Expected '${expectVal}' to${
negated ? " not" : ""
} be '${expectedVal}'`,
})
}
@@ -91,13 +94,16 @@ function createExpectation(
if (assertion) {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "pass",
message: `Expected '${expectVal}' to${negated ? " not" : ""} be 200-level status`,
message: `Expected '${expectVal}' to${
negated ? " not" : ""
} be 200-level status`,
})
} else {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "fail",
message:
`Expected '${expectVal}' to${negated ? " not" : ""} be 200-level status`,
message: `Expected '${expectVal}' to${
negated ? " not" : ""
} be 200-level status`,
})
}
} else {
@@ -119,13 +125,16 @@ function createExpectation(
if (assertion) {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "pass",
message: `Expected '${expectVal}' to${negated ? " not" : ""} be 300-level status`,
message: `Expected '${expectVal}' to${
negated ? " not" : ""
} be 300-level status`,
})
} else {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "fail",
message:
`Expected '${expectVal}' to${negated ? " not" : ""} be 300-level status`,
message: `Expected '${expectVal}' to${
negated ? " not" : ""
} be 300-level status`,
})
}
} else {
@@ -147,13 +156,16 @@ function createExpectation(
if (assertion) {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "pass",
message: `Expected '${expectVal}' to${negated ? " not" : ""} be 400-level status`,
message: `Expected '${expectVal}' to${
negated ? " not" : ""
} be 400-level status`,
})
} else {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "fail",
message:
`Expected '${expectVal}' to${negated ? " not" : ""} be 400-level status`,
message: `Expected '${expectVal}' to${
negated ? " not" : ""
} be 400-level status`,
})
}
} else {
@@ -175,12 +187,16 @@ function createExpectation(
if (assertion) {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "pass",
message: `Expected '${expectVal}' to${negated ? " not" : ""} be 500-level status`,
message: `Expected '${expectVal}' to${
negated ? " not" : ""
} be 500-level status`,
})
} else {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "fail",
message: `Expected '${expectVal}' to${negated ? " not" : ""} be 500-level status`
message: `Expected '${expectVal}' to${
negated ? " not" : ""
} be 500-level status`,
})
}
} else {
@@ -189,7 +205,7 @@ function createExpectation(
message: `Expected 500-level status but could not parse value '${expectVal}'`,
})
}
return { value: vm.undefined }
})
@@ -197,25 +213,40 @@ function createExpectation(
const expectedType = vm.dump(expectedValHandle)
// Check if the expectation param is a valid type name string, else error
if (["string", "boolean", "number", "object", "undefined", "bigint", "symbol", "function"].includes(expectedType)) {
if (
[
"string",
"boolean",
"number",
"object",
"undefined",
"bigint",
"symbol",
"function",
].includes(expectedType)
) {
let assertion = typeof expectVal === expectedType
if (negated) assertion = !assertion
if (assertion) {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "pass",
message: `Expected '${expectVal}' to${negated ? " not" : ""} be type '${expectedType}'`
message: `Expected '${expectVal}' to${
negated ? " not" : ""
} be type '${expectedType}'`,
})
} else {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "fail",
message: `Expected '${expectVal}' to${negated ? " not" : ""} be type '${expectedType}'`,
message: `Expected '${expectVal}' to${
negated ? " not" : ""
} be type '${expectedType}'`,
})
}
} else {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "error",
message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"`
message: `Argument for toBeType should be "string", "boolean", "number", "object", "undefined", "bigint", "symbol" or "function"`,
})
}
@@ -240,25 +271,29 @@ function createExpectation(
if (typeof expectedLength === "number" && !Number.isNaN(expectedLength)) {
let assertion = (expectVal as any[]).length === expectedLength
if (negated) assertion = !assertion
if (assertion) {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "pass",
message: `Expected the array to${negated ? " not" : ""} be of length '${expectedLength}'`,
message: `Expected the array to${
negated ? " not" : ""
} be of length '${expectedLength}'`,
})
} else {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "fail",
message: `Expected the array to${negated ? " not" : ""} be of length '${expectedLength}'`
message: `Expected the array to${
negated ? " not" : ""
} be of length '${expectedLength}'`,
})
}
} else {
currTestStack[currTestStack.length - 1].expectResults.push({
status: "error",
message: `Argument for toHaveLength should be a number`
message: `Argument for toHaveLength should be a number`,
})
}
return { value: vm.undefined }
}
)
@@ -291,77 +326,81 @@ function createExpectation(
export const execTestScript = (
testScript: string,
response: TestResponse
): TaskEither<string, TestDescriptor[]> => pipe(
tryCatch(
async () => await qjs.getQuickJS(),
(reason) => `QuickJS initialization failed: ${reason}`
),
chain(
// TODO: Make this more functional ?
(QuickJS) => {
const vm = QuickJS.createVm()
): TaskEither<string, TestDescriptor[]> =>
pipe(
tryCatch(
async () => await qjs.getQuickJS(),
(reason) => `QuickJS initialization failed: ${reason}`
),
chain(
// TODO: Make this more functional ?
(QuickJS) => {
const vm = QuickJS.createVm()
const pwHandle = vm.newObject()
const pwHandle = vm.newObject()
const testRunStack: TestDescriptor[] = [
{ descriptor: "root", expectResults: [], children: [] },
]
const testRunStack: TestDescriptor[] = [
{ descriptor: "root", expectResults: [], children: [] },
]
const testFuncHandle = vm.newFunction(
"test",
(descriptorHandle, testFuncHandle) => {
const descriptor = vm.getString(descriptorHandle)
const testFuncHandle = vm.newFunction(
"test",
(descriptorHandle, testFuncHandle) => {
const descriptor = vm.getString(descriptorHandle)
testRunStack.push({
descriptor,
expectResults: [],
children: [],
})
testRunStack.push({
descriptor,
expectResults: [],
children: [],
})
const result = vm.unwrapResult(vm.callFunction(testFuncHandle, vm.null))
result.dispose()
const result = vm.unwrapResult(
vm.callFunction(testFuncHandle, vm.null)
)
result.dispose()
const child = testRunStack.pop() as TestDescriptor
testRunStack[testRunStack.length - 1].children.push(child)
const child = testRunStack.pop() as TestDescriptor
testRunStack[testRunStack.length - 1].children.push(child)
}
)
const expectFnHandle = vm.newFunction("expect", (expectValueHandle) => {
const expectVal = vm.dump(expectValueHandle)
return {
value: createExpectation(vm, expectVal, false, testRunStack),
}
})
// Marshal response object
const responseObjHandle = marshalObjectToVM(vm, response)
if (isLeft(responseObjHandle))
return left(`Response marshalling failed: ${responseObjHandle.left}`)
vm.setProp(pwHandle, "response", responseObjHandle.right)
responseObjHandle.right.dispose()
vm.setProp(pwHandle, "expect", expectFnHandle)
expectFnHandle.dispose()
vm.setProp(pwHandle, "test", testFuncHandle)
testFuncHandle.dispose()
vm.setProp(vm.global, "pw", pwHandle)
pwHandle.dispose()
const evalRes = vm.evalCode(testScript)
if (evalRes.error) {
const errorData = vm.dump(evalRes.error)
evalRes.error.dispose()
return left(`Script evaluation failed: ${errorData}`)
}
)
const expectFnHandle = vm.newFunction("expect", (expectValueHandle) => {
const expectVal = vm.dump(expectValueHandle)
vm.dispose()
return {
value: createExpectation(vm, expectVal, false, testRunStack),
}
})
// Marshal response object
const responseObjHandle = marshalObjectToVM(vm, response)
if (isLeft(responseObjHandle)) return left(`Response marshalling failed: ${responseObjHandle.left}`)
vm.setProp(pwHandle, "response", responseObjHandle.right)
responseObjHandle.right.dispose()
vm.setProp(pwHandle, "expect", expectFnHandle)
expectFnHandle.dispose()
vm.setProp(pwHandle, "test", testFuncHandle)
testFuncHandle.dispose()
vm.setProp(vm.global, "pw", pwHandle)
pwHandle.dispose()
const evalRes = vm.evalCode(testScript)
if (evalRes.error) {
const errorData = vm.dump(evalRes.error)
evalRes.error.dispose()
return left(`Script evaluation failed: ${errorData}`)
return right(testRunStack)
}
vm.dispose()
return right(testRunStack)
}
)
)
)

View File

@@ -1,7 +1,10 @@
import { Either, left, right } from "fp-ts/lib/Either";
import * as QuickJS from "quickjs-emscripten";
import { Either, left, right } from "fp-ts/lib/Either"
import * as QuickJS from "quickjs-emscripten"
export function marshalObjectToVM(vm: QuickJS.QuickJSVm, obj: object): Either<string, QuickJS.QuickJSHandle> {
export function marshalObjectToVM(
vm: QuickJS.QuickJSVm,
obj: object
): Either<string, QuickJS.QuickJSHandle> {
let jsonString
try {
@@ -15,7 +18,11 @@ export function marshalObjectToVM(vm: QuickJS.QuickJSVm, obj: object): Either<st
const jsonHandle = vm.getProp(vm.global, "JSON")
const parseFuncHandle = vm.getProp(jsonHandle, "parse")
const parseResultHandle = vm.callFunction(parseFuncHandle, vm.undefined, vmStringHandle)
const parseResultHandle = vm.callFunction(
parseFuncHandle,
vm.undefined,
vmStringHandle
)
if (parseResultHandle.error) {
parseResultHandle.error.dispose()
@@ -27,6 +34,6 @@ export function marshalObjectToVM(vm: QuickJS.QuickJSVm, obj: object): Either<st
vmStringHandle.dispose()
parseFuncHandle.dispose()
jsonHandle.dispose()
return right(resultHandle)
}
}