Skip to content

Commit

Permalink
fix(gatsby): Use correct settings for yaml-loader (#37454)
Browse files Browse the repository at this point in the history
* fix

* add e2e test

(cherry picked from commit 3ef4f44)
  • Loading branch information
LekoArts authored and tyhopp committed Jan 13, 2023
1 parent 7021834 commit 3a72547
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
describe(`webpack-loader: yaml`, () => {
beforeEach(() => {
cy.visit(`/webpack-loader/yaml/`).waitForRouteChange()
})

it(`outputs the YAML file as JSON`, () => {
cy.getTestElement(`webpack-loader-yaml`)
.invoke(`text`)
.should(`eq`, `[{"name":"Paul"},{"name":"Leto II"},{"name":"Ghanima"},{"name":"Alia"}]`)
})
})
16 changes: 16 additions & 0 deletions e2e-tests/development-runtime/src/pages/webpack-loader/yaml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as React from "react"
import Layout from "../../components/layout"

import inputYaml from "../../test-files/input.yaml"

const YamlPage = () => (
<Layout>
<pre>
<code data-testid="webpack-loader-yaml">
{JSON.stringify(inputYaml, null, 0)}
</code>
</pre>
</Layout>
)

export default YamlPage
4 changes: 4 additions & 0 deletions e2e-tests/development-runtime/src/test-files/input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- name: Paul
- name: Leto II
- name: Ghanima
- name: Alia
5 changes: 4 additions & 1 deletion packages/gatsby/src/utils/webpack-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,11 @@ export const createWebpackUtils = (
},
yaml: (options = {}) => {
return {
options,
loader: require.resolve(`yaml-loader`),
options: {
asJSON: true,
...options,
},
}
},

Expand Down

0 comments on commit 3a72547

Please sign in to comment.