-
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.
fix(gatsby): use correct stageLabel instead of
undefined
(#28701)
* add basic tests for webpack-error-utils * fix(gatsby): use correct stageLabel instead of undefined
- Loading branch information
Showing
3 changed files
with
116 additions
and
10 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
packages/gatsby/src/utils/__tests__/__snapshots__/webpack-error-utils.ts.snap
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,77 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`structureWebpackErrors stage: build-html Can't resolve (98124) 1`] = ` | ||
Object { | ||
"context": Object { | ||
"packageName": "wat.js", | ||
"sourceMessage": "Can't resolve 'wat.js' in 'foo.js'", | ||
"stage": "build-html", | ||
"stageLabel": "Generating SSR bundle", | ||
}, | ||
"filePath": "foo.js", | ||
"id": "98124", | ||
"location": Object { | ||
"start": Object { | ||
"column": 10, | ||
"line": 5, | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`structureWebpackErrors stage: build-javascript Can't resolve (98124) 1`] = ` | ||
Object { | ||
"context": Object { | ||
"packageName": "wat.js", | ||
"sourceMessage": "Can't resolve 'wat.js' in 'foo.js'", | ||
"stage": "build-javascript", | ||
"stageLabel": "Generating JavaScript bundles", | ||
}, | ||
"filePath": "foo.js", | ||
"id": "98124", | ||
"location": Object { | ||
"start": Object { | ||
"column": 10, | ||
"line": 5, | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`structureWebpackErrors stage: develop Can't resolve (98124) 1`] = ` | ||
Object { | ||
"context": Object { | ||
"packageName": "wat.js", | ||
"sourceMessage": "Can't resolve 'wat.js' in 'foo.js'", | ||
"stage": "develop", | ||
"stageLabel": "Generating development JavaScript bundle", | ||
}, | ||
"filePath": "foo.js", | ||
"id": "98124", | ||
"location": Object { | ||
"start": Object { | ||
"column": 10, | ||
"line": 5, | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`structureWebpackErrors stage: develop-html Can't resolve (98124) 1`] = ` | ||
Object { | ||
"context": Object { | ||
"packageName": "wat.js", | ||
"sourceMessage": "Can't resolve 'wat.js' in 'foo.js'", | ||
"stage": "develop-html", | ||
"stageLabel": "Generating development SSR bundle", | ||
}, | ||
"filePath": "foo.js", | ||
"id": "98124", | ||
"location": Object { | ||
"start": Object { | ||
"column": 10, | ||
"line": 5, | ||
}, | ||
}, | ||
} | ||
`; |
32 changes: 32 additions & 0 deletions
32
packages/gatsby/src/utils/__tests__/webpack-error-utils.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,32 @@ | ||
import { structureWebpackErrors } from "../webpack-error-utils" | ||
import { Stage } from "../../commands/types" | ||
|
||
describe(`structureWebpackErrors`, () => { | ||
const stages: Array<Stage> = [ | ||
Stage.BuildJavascript, | ||
Stage.BuildHTML, | ||
Stage.DevelopHTML, | ||
Stage.Develop, | ||
] | ||
|
||
describe.each(stages)(`stage: %s`, (stage: Stage) => { | ||
it(`Can't resolve (98124)`, () => { | ||
const error = new Error(`Can't resolve 'wat.js' in 'foo.js'`) as any | ||
error.module = { resource: `foo.js` } | ||
error.error = { | ||
loc: { | ||
line: 5, | ||
column: 10, | ||
}, | ||
} | ||
let structuredError = structureWebpackErrors(stage, error) | ||
if (Array.isArray(structuredError)) { | ||
structuredError = structuredError[0] | ||
} | ||
|
||
expect(structuredError).toMatchSnapshot() | ||
expect(structuredError.context.stageLabel).not.toBeUndefined() | ||
expect(structuredError.context.stage).not.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