Skip to content

Commit

Permalink
feat: handle run errors [sc-00]
Browse files Browse the repository at this point in the history
  • Loading branch information
tnolet committed Jul 12, 2024
1 parent 34abc2d commit bffa9ed
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`JsonBuilder renders JSON markdown output with assets & links: json-with-assets-links 1`] = `
"{
"testSessionId": "0c4c64b3-79c5-44a6-ae07-b580ce73f328",
"numChecks": 2,
"runLocation": "eu-west-1",
"checks": [
{
"result": "Pass",
"name": "my-test.spec.ts",
"checkType": "BROWSER",
"durationMilliseconds": 6522,
"filename": "src/__checks__/folder/browser.check.ts",
"link": "https://app.checklyhq.com/test-sessions/0c4c64b3-79c5-44a6-ae07-b580ce73f328/results/702961fd-7e2c-45f0-97be-1aa9eabd4d82"
},
{
"result": "Pass",
"name": "Test API check",
"checkType": "API",
"durationMilliseconds": 1234,
"filename": "src/some-other-folder/api.check.ts",
"link": "https://app.checklyhq.com/test-sessions/0c4c64b3-79c5-44a6-ae07-b580ce73f328/results/1c0be612-a5ec-432e-ac1c-837d2f70c010"
}
]
}"
`;

exports[`JsonBuilder renders basic JSON output with no assets & links: json-basic 1`] = `
"{
"numChecks": 2,
Expand All @@ -37,15 +11,17 @@ exports[`JsonBuilder renders basic JSON output with no assets & links: json-basi
"checkType": "BROWSER",
"durationMilliseconds": 6522,
"filename": "src/__checks__/folder/browser.check.ts",
"link": null
"link": null,
"runError": null
},
{
"result": "Pass",
"name": "Test API check",
"checkType": "API",
"durationMilliseconds": 1234,
"filename": "src/some-other-folder/api.check.ts",
"link": null
"link": null,
"runError": null
}
]
}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,5 @@ export const apiCheckResult = {
requestError: null,
},
scheduleError: '',
runError: '',
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,5 @@ export const browserCheckResult = {
},
],
scheduleError: '',
runError: '',
}
6 changes: 5 additions & 1 deletion packages/cli/src/reporters/__tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { checkFilesMap } from '../abstract-list'
import { browserCheckResult } from './fixtures/browser-check-result'
import { apiCheckResult } from './fixtures/api-check-result'

export function generateMapAndTestResultIds ({ includeTestResultIds = true }) {
export function generateMapAndTestResultIds ({ includeTestResultIds = true, includeRunErrors = false }) {
if (includeRunErrors) {
browserCheckResult.runError = 'Run error'
apiCheckResult.runError = 'Run error'
}
const checkFilesMapFixture: checkFilesMap = new Map([
['folder/browser.check.ts', new Map([
[browserCheckResult.checkRunId, {
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/reporters/__tests__/json-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ describe('JsonBuilder', () => {
}).render()
expect(json).toMatchSnapshot('json-basic')
})
test('renders basic JSON output with run errors', () => {
const checkFilesMap = generateMapAndTestResultIds({ includeTestResultIds: false, includeRunErrors: true })
const json = new JsonBuilder({
testSessionId: undefined,
numChecks: checkFilesMap.size,
runLocation,
checkFilesMap,
}).render()
expect(json).toMatchSnapshot('json-basic')

Check failure on line 25 in packages/cli/src/reporters/__tests__/json-builder.spec.ts

View workflow job for this annotation

GitHub Actions / test - ubuntu-latest

JsonBuilder › renders basic JSON output with run errors

expect(received).toMatchSnapshot(hint) Snapshot name: `JsonBuilder renders basic JSON output with run errors: json-basic 1` New snapshot was not written. The update flag must be explicitly passed to write a new snapshot. This is likely because this test is run in a continuous integration (CI) environment in which snapshots are not written by default. Received: "{ "numChecks": 2, "runLocation": "eu-west-1", "checks": [ { "result": "Pass", "name": "my-test.spec.ts", "checkType": "BROWSER", "durationMilliseconds": 6522, "filename": "src/__checks__/folder/browser.check.ts", "link": null, "runError": "Run error" }, { "result": "Pass", "name": "Test API check", "checkType": "API", "durationMilliseconds": 1234, "filename": "src/some-other-folder/api.check.ts", "link": null, "runError": "Run error" } ] }" at Object.<anonymous> (src/reporters/__tests__/json-builder.spec.ts:25:18)
})
test('renders JSON markdown output with assets & links', () => {
const checkFilesMap = generateMapAndTestResultIds({ includeTestResultIds: true })
const json = new JsonBuilder({
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/reporters/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class JsonBuilder {
durationMilliseconds: result.responseTime ?? null,
filename: null,
link: null,
runError: result.runError || null,
}

if (this.hasFilenames) {
Expand Down

0 comments on commit bffa9ed

Please sign in to comment.