Skip to content

Commit b229e7b

Browse files
gatsbybotLekoArts
andauthored
fix(gatsby): Use correct settings for yaml-loader (#37454) (#37460)
* fix * add e2e test (cherry picked from commit 3ef4f44) Co-authored-by: Lennart <lekoarts@gmail.com>
1 parent 7021834 commit b229e7b

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
describe(`webpack-loader: yaml`, () => {
2+
beforeEach(() => {
3+
cy.visit(`/webpack-loader/yaml/`).waitForRouteChange()
4+
})
5+
6+
it(`outputs the YAML file as JSON`, () => {
7+
cy.getTestElement(`webpack-loader-yaml`)
8+
.invoke(`text`)
9+
.should(`eq`, `[{"name":"Paul"},{"name":"Leto II"},{"name":"Ghanima"},{"name":"Alia"}]`)
10+
})
11+
})
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from "react"
2+
import Layout from "../../components/layout"
3+
4+
import inputYaml from "../../test-files/input.yaml"
5+
6+
const YamlPage = () => (
7+
<Layout>
8+
<pre>
9+
<code data-testid="webpack-loader-yaml">
10+
{JSON.stringify(inputYaml, null, 0)}
11+
</code>
12+
</pre>
13+
</Layout>
14+
)
15+
16+
export default YamlPage
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- name: Paul
2+
- name: Leto II
3+
- name: Ghanima
4+
- name: Alia

packages/gatsby/src/utils/webpack-utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,11 @@ export const createWebpackUtils = (
228228
},
229229
yaml: (options = {}) => {
230230
return {
231-
options,
232231
loader: require.resolve(`yaml-loader`),
232+
options: {
233+
asJSON: true,
234+
...options,
235+
},
233236
}
234237
},
235238

0 commit comments

Comments
 (0)