-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add types to api-runner-error-parser
- Loading branch information
1 parent
2c08909
commit 4d109ab
Showing
2 changed files
with
79 additions
and
21 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
packages/gatsby/src/utils/__tests__/api-runner-error-parser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import errorParser from "../api-runner-error-parser" | ||
|
||
describe(`error matching`, () => { | ||
test(`it matches "is not defined" errors`, () => { | ||
const match = errorParser({ err: new Error(`foo is not defined`) }) | ||
|
||
expect(match).toEqual({ | ||
id: `11330`, | ||
context: { sourceMessage: `foo is not defined`, arg: `foo` }, | ||
}) | ||
}) | ||
|
||
test(`it has a default when no match are found`, () => { | ||
const match = errorParser({ err: new Error(`unknown error`) }) | ||
|
||
expect(match).toEqual({ | ||
id: `11321`, | ||
context: { sourceMessage: `unknown error` }, | ||
error: new Error(`unknown error`), | ||
}) | ||
}) | ||
}) | ||
|
||
describe(`unkown error parser`, () => { | ||
test(`it handles Errors`, () => { | ||
const match = errorParser({ err: new Error(`error`) }) | ||
|
||
expect(match.context.sourceMessage).toEqual(`error`) | ||
expect(match.error).toBeTruthy() | ||
}) | ||
|
||
test(`it handles Strings`, () => { | ||
const match = errorParser({ err: `error` }) | ||
|
||
expect(match.context.sourceMessage).toEqual(`error`) | ||
expect(match.error).toBeUndefined() | ||
}) | ||
|
||
test(`it handles arrays of Error`, () => { | ||
const match = errorParser({ err: [new Error(`error`)] }) | ||
|
||
expect(match.context.sourceMessage).toEqual(`error`) | ||
expect(match.error).toBeTruthy() | ||
}) | ||
|
||
test(`it handles anything else by returning an empty string`, () => { | ||
const match = errorParser({ err: new Map() }) | ||
|
||
expect(match.context.sourceMessage).toEqual(``) | ||
expect(match.error).toBeUndefined() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters