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
  • Loading branch information
LekoArts authored Jan 12, 2023
1 parent 76f979c commit 3ef4f44
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 @@ -232,8 +232,11 @@ export const createWebpackUtils = (
},
yaml: (options = {}) => {
return {
options,
loader: require.resolve(`yaml-loader`),
options: {
asJSON: true,
...options,
},
}
},

Expand Down

0 comments on commit 3ef4f44

Please sign in to comment.