Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
Add better error and failure case handling on test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBastin committed Jul 9, 2021
1 parent 2eed7c5 commit c131322
Show file tree
Hide file tree
Showing 5 changed files with 499 additions and 52 deletions.
18 changes: 13 additions & 5 deletions src/__tests__/testing/expect/toBe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("toBe", () => {
)
).resolves.toEqual([
expect.objectContaining({
expectResults: [true],
expectResults: [{ status: "pass" }],
}),
])
})
Expand All @@ -25,7 +25,7 @@ describe("toBe", () => {
)
).resolves.toEqual([
expect.objectContaining({
expectResults: [false],
expectResults: [{ status: "fail", message: "Expected '2' to be '4'" }],
}),
])
})
Expand All @@ -41,7 +41,10 @@ describe("toBe", () => {
)
).resolves.toEqual([
expect.objectContaining({
expectResults: [false],
expectResults: [{
status: "fail",
message: "Expected '2' to not be '2'",
}],
}),
])
})
Expand All @@ -55,7 +58,9 @@ describe("toBe", () => {
)
).resolves.toEqual([
expect.objectContaining({
expectResults: [true],
expectResults: [{
status: "pass",
}],
}),
])
})
Expand All @@ -71,7 +76,10 @@ test("strict checks types", () => {
)
).resolves.toEqual([
expect.objectContaining({
expectResults: [false],
expectResults: [{
status: "fail",
message: "Expected '2' to be '2'",
}],
}),
])
})
177 changes: 161 additions & 16 deletions src/__tests__/testing/expect/toBeLevelxxx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ describe("toBeLevel2xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel2xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [true],
expectResults: [{
status: "pass",
}],
}),
])
}
Expand All @@ -19,19 +21,38 @@ describe("toBeLevel2xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel2xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [false],
expectResults: [{
status: "fail",
message: `Expected '${i}' to be 200-level status`,
}],
}),
])
}
})

test("give error if the expect value was not a number with no negation", async () => {
await expect(
execTestScript(`pw.expect("foo").toBeLevel2xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 200-level status but could not parse value 'foo'",
}],
})
])
})

test("assertion fails for 200 series with negation", async () => {
for (let i = 200; i < 300; i++) {
await expect(
execTestScript(`pw.expect(${i}).not.toBeLevel2xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [false],
expectResults: [{
status: "fail",
message: `Expected '${i}' to not be 200-level status`,
}],
}),
])
}
Expand All @@ -43,11 +64,26 @@ describe("toBeLevel2xx", () => {
execTestScript(`pw.expect(${i}).not.toBeLevel2xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [true],
expectResults: [{
status: "pass",
}],
}),
])
}
})

test("give error if the expect value was not a number with negation", async () => {
await expect(
execTestScript(`pw.expect("foo").not.toBeLevel2xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 200-level status but could not parse value 'foo'",
}],
})
])
})
})

describe("toBeLevel3xx", () => {
Expand All @@ -57,7 +93,9 @@ describe("toBeLevel3xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel3xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [true],
expectResults: [{
status: "pass",
}],
}),
])
}
Expand All @@ -69,19 +107,38 @@ describe("toBeLevel3xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel3xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [false],
expectResults: [{
status: "fail",
message: `Expected '${i}' to be 300-level status`,
}],
}),
])
}
})

test("give error if the expect value is not a number without negation", () => {
return expect(
execTestScript(`pw.expect("foo").toBeLevel3xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 300-level status but could not parse value 'foo'",
}],
})
])
})

test("assertion fails for 400 series with negation", async () => {
for (let i = 300; i < 400; i++) {
await expect(
execTestScript(`pw.expect(${i}).not.toBeLevel3xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [false],
expectResults: [{
status: "fail",
message: `Expected '${i}' to not be 300-level status`,
}],
}),
])
}
Expand All @@ -93,11 +150,27 @@ describe("toBeLevel3xx", () => {
execTestScript(`pw.expect(${i}).not.toBeLevel3xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [true],
expectResults: [{
status: "pass",
}],
}),
])
}
})

test("give error if the expect value is not a number with negation", () => {
return expect(
execTestScript(`pw.expect("foo").not.toBeLevel3xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 300-level status but could not parse value 'foo'",
}]
})
])
})

})

describe("toBeLevel4xx", () => {
Expand All @@ -107,7 +180,9 @@ describe("toBeLevel4xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel4xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [true],
expectResults: [{
status: "pass",
}],
}),
])
}
Expand All @@ -119,19 +194,38 @@ describe("toBeLevel4xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel4xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [false],
expectResults: [{
status: "fail",
message: `Expected '${i}' to be 400-level status`,
}],
}),
])
}
})

test("give error if the expected value is not a number without negation", () => {
return expect(
execTestScript(`pw.expect("foo").toBeLevel4xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 400-level status but could not parse value 'foo'",
}],
})
])
})

test("assertion fails for 400 series with negation", async () => {
for (let i = 400; i < 500; i++) {
await expect(
execTestScript(`pw.expect(${i}).not.toBeLevel4xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [false],
expectResults: [{
status: "fail",
message: `Expected '${i}' to not be 400-level status`,
}],
}),
])
}
Expand All @@ -143,11 +237,26 @@ describe("toBeLevel4xx", () => {
execTestScript(`pw.expect(${i}).not.toBeLevel4xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [true],
expectResults: [{
status: "pass",
}],
}),
])
}
})

test("give error if the expected value is not a number with negation", () => {
return expect(
execTestScript(`pw.expect("foo").not.toBeLevel4xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 400-level status but could not parse value 'foo'",
}],
})
])
})
})

describe("toBeLevel5xx", () => {
Expand All @@ -157,7 +266,9 @@ describe("toBeLevel5xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel5xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [true],
expectResults: [{
status: "pass",
}],
}),
])
}
Expand All @@ -169,19 +280,38 @@ describe("toBeLevel5xx", () => {
execTestScript(`pw.expect(${i}).toBeLevel5xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [false],
expectResults: [{
status: "fail",
message: `Expected '${i}' to be 500-level status`,
}],
}),
])
}
})

test("give error if the expect value is not a number with no negation", () => {
return expect(
execTestScript(`pw.expect("foo").toBeLevel5xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 500-level status but could not parse value 'foo'",
}],
})
])
})

test("assertion fails for 500 series with negation", async () => {
for (let i = 500; i < 600; i++) {
await expect(
execTestScript(`pw.expect(${i}).not.toBeLevel5xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [false],
expectResults: [{
status: "fail",
message: `Expected '${i}' to not be 500-level status`,
}],
}),
])
}
Expand All @@ -193,9 +323,24 @@ describe("toBeLevel5xx", () => {
execTestScript(`pw.expect(${i}).not.toBeLevel5xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [true],
expectResults: [{
status: "pass",
}],
}),
])
}
})

test("give error if the expect value is not a number with negation", () => {
return expect(
execTestScript(`pw.expect("foo").not.toBeLevel5xx()`)
).resolves.toEqual([
expect.objectContaining({
expectResults: [{
status: "error",
message: "Expected 500-level status but could not parse value 'foo'",
}],
})
])
})
})
Loading

0 comments on commit c131322

Please sign in to comment.