Skip to content

Commit 4ea3fa1

Browse files
sidharthachatterjeeGatsbyJS Bot
authored andcommitted
feat(gatsby): enable babel in deps (#15284)
* Add modules that use gatsby to query compiler * Run babel on modules that use Gatsby * Update snapshot * Set higher timeout in test * Apply suggestions from code review Co-Authored-By: Ward Peeters <ward@coding-tech.com> * Missing ) * Suggestions from Ward * Add tests for include and exclude functions * Add one more test for exclude function * moar tests * add some sanity e2e tests * Fix production runtime tests * fix(e2e-production-runtime): adjust siteMetadata to shape gatsby-seo needs
1 parent 8bcd843 commit 4ea3fa1

File tree

16 files changed

+255
-47
lines changed

16 files changed

+255
-47
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe(`queries in packages`, () => {
2+
beforeEach(() => {
3+
cy.visit(`/queries-in-packages`).waitForRouteChange()
4+
})
5+
6+
it(`Should extract and run query from gatsby component`, () => {
7+
// we are using `gatsby-seo` package which sets
8+
// window's title to title passed as prop followed by siteMetadata.title
9+
cy.title().should(
10+
`eq`,
11+
`Testing queries in packages | Gatsby Default Starter`
12+
)
13+
})
14+
})

e2e-tests/development-runtime/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"gatsby-plugin-offline": "^2.1.0",
1111
"gatsby-plugin-react-helmet": "^3.0.6",
1212
"gatsby-plugin-sharp": "^2.0.37",
13+
"gatsby-seo": "^0.1.0",
1314
"gatsby-source-filesystem": "^2.0.33",
1415
"gatsby-transformer-remark": "^2.3.12",
1516
"gatsby-transformer-sharp": "^2.1.19",
@@ -25,11 +26,11 @@
2526
"license": "MIT",
2627
"scripts": {
2728
"build": "gatsby build",
28-
"develop": "cross-env ENABLE_GATSBY_REFRESH_ENDPOINT=true gatsby develop",
29+
"develop": "cross-env CYPRESS_SUPPORT=y ENABLE_GATSBY_REFRESH_ENDPOINT=true gatsby develop",
2930
"serve": "gatsby serve",
3031
"start": "npm run develop",
3132
"format": "prettier --write \"src/**/*.js\"",
32-
"test": "CYPRESS_SUPPORT=y npm run start-server-and-test || (npm run reset && exit 1)",
33+
"test": "npm run start-server-and-test || (npm run reset && exit 1)",
3334
"posttest": "npm run reset",
3435
"reset": "node scripts/reset.js",
3536
"reset:preview": "node plugins/gatsby-source-fake-data/reset.js && npm run update:preview",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from "react"
2+
import SEO from "gatsby-seo"
3+
4+
import Layout from "../components/layout"
5+
6+
export default () => (
7+
<Layout>
8+
<SEO
9+
title="Testing queries in packages"
10+
keywords={[`gatsby`, `application`, `react`, `queries in component`]}
11+
/>
12+
</Layout>
13+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe(`queries in packages`, () => {
2+
beforeEach(() => {
3+
cy.visit(`/queries-in-packages`).waitForRouteChange()
4+
})
5+
6+
it(`Should extract and run query from gatsby component`, () => {
7+
// we are using `gatsby-seo` package which sets
8+
// window's title to title passed as prop followed by siteMetadata.title
9+
cy.title().should(
10+
`eq`,
11+
`Testing queries in packages | Gatsby Default Starter`
12+
)
13+
})
14+
})

e2e-tests/production-runtime/gatsby-config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
module.exports = {
22
siteMetadata: {
33
title: `Gatsby Default Starter`,
4-
author: {
5-
name: `Kyle Mathews`,
6-
bio: `lives and works in San Francisco building useful things`,
7-
},
4+
author: `Kyle Mathews`,
5+
description: `This is site for production runtime e2e tests`,
86
},
97
plugins: [
108
`gatsby-plugin-react-helmet`,

e2e-tests/production-runtime/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"gatsby-plugin-manifest": "^2.0.17",
1010
"gatsby-plugin-offline": "^2.0.23",
1111
"gatsby-plugin-react-helmet": "^3.0.6",
12+
"gatsby-seo": "^0.1.0",
1213
"glob": "^7.1.3",
1314
"react": "^16.8.0",
1415
"react-dom": "^16.8.0",

e2e-tests/production-runtime/src/components/bio.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ function Bio() {
77
query={bioQuery}
88
render={data => (
99
<div>
10-
<p data-testid="bio">
11-
A site by {data.site.siteMetadata.author.name} who
12-
{` `}
13-
{data.site.siteMetadata.author.bio}
14-
</p>
10+
<p data-testid="bio">A site by {data.site.siteMetadata.author}</p>
1511
</div>
1612
)}
1713
/>
@@ -22,10 +18,7 @@ export const bioQuery = graphql`
2218
{
2319
site {
2420
siteMetadata {
25-
author {
26-
bio
27-
name
28-
}
21+
author
2922
}
3023
}
3124
}

e2e-tests/production-runtime/src/components/static-query/exported-variable-query.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function ExportedVariable(props) {
55
return (
66
<StaticQuery
77
query={nameQuery}
8-
render={data => <p {...props}>{data.site.siteMetadata.author.name}</p>}
8+
render={data => <p {...props}>{data.site.siteMetadata.author}</p>}
99
/>
1010
)
1111
}
@@ -14,9 +14,7 @@ export const nameQuery = graphql`
1414
{
1515
site {
1616
siteMetadata {
17-
author {
18-
name
19-
}
17+
author
2018
}
2119
}
2220
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import SEO from 'gatsby-seo'
3+
4+
import Layout from '../components/layout'
5+
6+
export default () => (
7+
<Layout>
8+
<SEO
9+
title="Testing queries in packages"
10+
keywords={[`gatsby`, `application`, `react`, `queries in component`]}
11+
/>
12+
</Layout>
13+
)

packages/gatsby/src/query/query-compiler.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import RelayParser from "@gatsbyjs/relay-compiler/lib/RelayParser"
1010
import ASTConvert from "@gatsbyjs/relay-compiler/lib/ASTConvert"
1111
import GraphQLCompilerContext from "@gatsbyjs/relay-compiler/lib/GraphQLCompilerContext"
1212
import filterContextForNode from "@gatsbyjs/relay-compiler/lib/filterContextForNode"
13+
import getGatsbyDependents from "../utils/gatsby-dependents"
1314
const _ = require(`lodash`)
1415

1516
import { store } from "../redux"
@@ -102,11 +103,14 @@ class Runner {
102103
async parseEverything() {
103104
const filesRegex = path.join(`/**`, `*.+(t|j)s?(x)`)
104105

106+
const modulesThatUseGatsby = await getGatsbyDependents()
107+
105108
let files = [
106109
path.join(this.base, `src`),
107110
path.join(this.base, `.cache`, `fragments`),
108111
]
109112
.concat(this.additional.map(additional => path.join(additional, `src`)))
113+
.concat(modulesThatUseGatsby.map(module => module.path))
110114
.reduce(
111115
(merged, folderPath) =>
112116
merged.concat(

0 commit comments

Comments
 (0)