From 4f54980a59da1c1b7deb0626778e5a9b33b383b2 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Mon, 1 Jul 2019 23:12:43 +0530 Subject: [PATCH 01/13] Add modules that use gatsby to query compiler --- packages/gatsby/src/query/query-compiler.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/gatsby/src/query/query-compiler.js b/packages/gatsby/src/query/query-compiler.js index 64294c556c69d..d8d8a2d1a9da3 100644 --- a/packages/gatsby/src/query/query-compiler.js +++ b/packages/gatsby/src/query/query-compiler.js @@ -10,6 +10,7 @@ import RelayParser from "@gatsbyjs/relay-compiler/lib/RelayParser" import ASTConvert from "@gatsbyjs/relay-compiler/lib/ASTConvert" import GraphQLCompilerContext from "@gatsbyjs/relay-compiler/lib/GraphQLCompilerContext" import filterContextForNode from "@gatsbyjs/relay-compiler/lib/filterContextForNode" +import getGatsbyDependents from "../utils/gatsby-dependents" const _ = require(`lodash`) import { store } from "../redux" @@ -102,11 +103,14 @@ class Runner { async parseEverything() { const filesRegex = path.join(`/**`, `*.+(t|j)s?(x)`) + const modulesThatUseGatsby = await getGatsbyDependents() + let files = [ path.join(this.base, `src`), path.join(this.base, `.cache`, `fragments`), ] .concat(this.additional.map(additional => path.join(additional, `src`))) + .concat(modulesThatUseGatsby.map(module => module.path)) .reduce( (merged, folderPath) => merged.concat( From b24b071e0770843417873357f76ae88cddec904b Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Tue, 2 Jul 2019 00:07:09 +0530 Subject: [PATCH 02/13] Run babel on modules that use Gatsby --- .../gatsby/src/utils/gatsby-dependents.js | 5 +- packages/gatsby/src/utils/webpack-utils.js | 49 ++++++++++++++++--- packages/gatsby/src/utils/webpack.config.js | 12 ++++- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/packages/gatsby/src/utils/gatsby-dependents.js b/packages/gatsby/src/utils/gatsby-dependents.js index 7d326c7a035a4..bb80898ba3db7 100644 --- a/packages/gatsby/src/utils/gatsby-dependents.js +++ b/packages/gatsby/src/utils/gatsby-dependents.js @@ -1,8 +1,9 @@ import { store } from "../redux" +import { memoize } from "lodash" import rpt from "read-package-tree" // Returns [Object] with name and path -module.exports = async () => { +module.exports = memoize(async () => { const { program } = store.getState() const allNodeModules = await rpt(program.directory) return allNodeModules.children.filter( @@ -10,4 +11,4 @@ module.exports = async () => { (node.package.dependencies && node.package.dependencies[`gatsby`]) || (node.package.peerDependencies && node.package.peerDependencies[`gatsby`]) ) -} +}) diff --git a/packages/gatsby/src/utils/webpack-utils.js b/packages/gatsby/src/utils/webpack-utils.js index d47963ecc85be..c0efa1c7f581d 100644 --- a/packages/gatsby/src/utils/webpack-utils.js +++ b/packages/gatsby/src/utils/webpack-utils.js @@ -290,13 +290,25 @@ module.exports = async ({ const rules = {} /** - * JavaScript loader via babel, excludes node_modules + * JavaScript loader via babel, includes userland code + * and packages that depend on `gatsby` */ { - let js = (options = {}) => { + let js = ( + { modulesThatUseGatsby, ...options } = { modulesThatUseGatsby: [] } + ) => { return { test: /\.(js|mjs|jsx)$/, - exclude: vendorRegex, + include: modulePath => { + if (vendorRegex.test(modulePath)) { + // Does this module that use gatsby? + return modulesThatUseGatsby.some(module => + modulePath.includes(module.path) + ) + } + + return true + }, type: `javascript/auto`, use: [loaders.js(options)], } @@ -306,10 +318,14 @@ module.exports = async ({ } /** - * Node_modules JavaScript loader via babel (exclude core-js & babel-runtime to speedup babel transpilation) + * Node_modules JavaScript loader via babel + * Excludes core-js & babel-runtime to speedup babel transpilation + * Excludes modules that use Gatsby since the `rules.js` already transpiles those */ { - let dependencies = (options = {}) => { + let dependencies = ( + { modulesThatUseGatsby, ...options } = { modulesThatUseGatsby: [] } + ) => { const jsOptions = { babelrc: false, configFile: false, @@ -326,7 +342,28 @@ module.exports = async ({ return { test: /\.(js|mjs)$/, - exclude: /@babel(?:\/|\\{1,2})runtime|core-js/, + exclude: modulePath => { + if (vendorRegex.test(modulePath)) { + // If dep uses Gatsby, exclude + if ( + modulesThatUseGatsby.some(module => + modulePath.includes(module.path) + ) + ) { + return true + } + // If dep is babel-runtime or core-js, exclude + else if (/@babel(?:\/|\\{1,2})runtime|core-js/.test(modulePath)) { + return true + } + + // If dep is in node_modules and none of the above, include + return false + } + + // If dep is user land code, exclude + return true + }, type: `javascript/auto`, use: [loaders.js(jsOptions)], } diff --git a/packages/gatsby/src/utils/webpack.config.js b/packages/gatsby/src/utils/webpack.config.js index ee84a1a512148..8eab36445e397 100644 --- a/packages/gatsby/src/utils/webpack.config.js +++ b/packages/gatsby/src/utils/webpack.config.js @@ -11,6 +11,7 @@ const getPublicPath = require(`./get-public-path`) const debug = require(`debug`)(`gatsby:webpack-config`) const report = require(`gatsby-cli/lib/reporter`) const { withBasePath, withTrailingSlash } = require(`./path`) +const getGatsbyDependents = require(`./gatsby-dependents`) const apiRunnerNode = require(`./api-runner-node`) const createUtils = require(`./webpack-utils`) @@ -23,6 +24,7 @@ const hasLocalEslint = require(`./local-eslint-config-finder`) // 4) build-html: build all HTML files module.exports = async (program, directory, suppliedStage) => { + const modulesThatUseGatsby = await getGatsbyDependents() const directoryPath = withBasePath(directory) process.env.GATSBY_BUILD_STAGE = suppliedStage @@ -249,7 +251,9 @@ module.exports = async (program, directory, suppliedStage) => { // Common config for every env. // prettier-ignore let configRules = [ - rules.js(), + rules.js({ + modulesThatUseGatsby: modulesThatUseGatsby + }), rules.yaml(), rules.fonts(), rules.images(), @@ -260,7 +264,11 @@ module.exports = async (program, directory, suppliedStage) => { // Speedup 🏎️💨 the build! We only include transpilation of node_modules on javascript production builds // TODO create gatsby plugin to enable this behaviour on develop (only when people are requesting this feature) if (stage === `build-javascript`) { - configRules.push(rules.dependencies()) + configRules.push( + rules.dependencies({ + modulesThatUseGatsby: modulesThatUseGatsby, + }) + ) } if (store.getState().themes.themes) { From a34d55e2fd4c389aa9508a5b66c9f651eed20387 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Tue, 2 Jul 2019 01:19:18 +0530 Subject: [PATCH 03/13] Update snapshot --- .../src/utils/__tests__/__snapshots__/webpack-utils.js.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/utils/__tests__/__snapshots__/webpack-utils.js.snap b/packages/gatsby/src/utils/__tests__/__snapshots__/webpack-utils.js.snap index eb3793f597a77..967fb09ebd072 100644 --- a/packages/gatsby/src/utils/__tests__/__snapshots__/webpack-utils.js.snap +++ b/packages/gatsby/src/utils/__tests__/__snapshots__/webpack-utils.js.snap @@ -2,7 +2,7 @@ exports[`webpack utils js returns default values without any options 1`] = ` Object { - "exclude": /\\(node_modules\\|bower_components\\)/, + "include": [Function], "test": /\\\\\\.\\(js\\|mjs\\|jsx\\)\\$/, "type": "javascript/auto", "use": Array [ @@ -16,7 +16,7 @@ Object { exports[`webpack utils js returns default values without any options 2`] = ` Object { - "exclude": /@babel\\(\\?:\\\\/\\|\\\\\\\\\\{1,2\\}\\)runtime\\|core-js/, + "exclude": [Function], "test": /\\\\\\.\\(js\\|mjs\\)\\$/, "type": "javascript/auto", "use": Array [ From 73a4c138cd2965ef36331dad25f26f1340ca1aaf Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Tue, 2 Jul 2019 02:52:26 +0530 Subject: [PATCH 04/13] Set higher timeout in test --- packages/gatsby/src/utils/__tests__/webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/src/utils/__tests__/webpack.config.js b/packages/gatsby/src/utils/__tests__/webpack.config.js index 2789094dde1b1..544a792599b81 100644 --- a/packages/gatsby/src/utils/__tests__/webpack.config.js +++ b/packages/gatsby/src/utils/__tests__/webpack.config.js @@ -55,7 +55,7 @@ describe(`basic functionality`, () => { ) ) ) - }) + }, 30000) }) describe(`environment variables`, () => { From b51fec288cdb94c62a454e37dfb80653c2e705e5 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Tue, 2 Jul 2019 18:11:33 +0530 Subject: [PATCH 05/13] Apply suggestions from code review Co-Authored-By: Ward Peeters --- packages/gatsby/src/utils/webpack.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/utils/webpack.config.js b/packages/gatsby/src/utils/webpack.config.js index 8eab36445e397..ad3fc0d1ca5dc 100644 --- a/packages/gatsby/src/utils/webpack.config.js +++ b/packages/gatsby/src/utils/webpack.config.js @@ -252,7 +252,7 @@ module.exports = async (program, directory, suppliedStage) => { // prettier-ignore let configRules = [ rules.js({ - modulesThatUseGatsby: modulesThatUseGatsby + modulesThatUseGatsby, }), rules.yaml(), rules.fonts(), @@ -266,7 +266,7 @@ module.exports = async (program, directory, suppliedStage) => { if (stage === `build-javascript`) { configRules.push( rules.dependencies({ - modulesThatUseGatsby: modulesThatUseGatsby, + modulesThatUseGatsby, }) ) } From 7130ffe4463aff41c929e2307ca59719964d14a4 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Tue, 2 Jul 2019 21:09:35 +0530 Subject: [PATCH 06/13] Missing ) --- packages/gatsby/src/utils/gatsby-dependents.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/src/utils/gatsby-dependents.js b/packages/gatsby/src/utils/gatsby-dependents.js index 46848d832b898..8325f196c7d59 100644 --- a/packages/gatsby/src/utils/gatsby-dependents.js +++ b/packages/gatsby/src/utils/gatsby-dependents.js @@ -11,4 +11,4 @@ module.exports = memoize(async () => { /gatsby/.test(moduleName) ) return allNodeModules.children -} +}) From 630456bb92ceb5a464851f32d98121b5ab3485cc Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Tue, 2 Jul 2019 22:01:04 +0530 Subject: [PATCH 07/13] Suggestions from Ward --- packages/gatsby/src/utils/webpack-utils.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/gatsby/src/utils/webpack-utils.js b/packages/gatsby/src/utils/webpack-utils.js index c0efa1c7f581d..3f37c6b439980 100644 --- a/packages/gatsby/src/utils/webpack-utils.js +++ b/packages/gatsby/src/utils/webpack-utils.js @@ -300,14 +300,16 @@ module.exports = async ({ return { test: /\.(js|mjs|jsx)$/, include: modulePath => { - if (vendorRegex.test(modulePath)) { - // Does this module that use gatsby? - return modulesThatUseGatsby.some(module => - modulePath.includes(module.path) - ) + // when it's not coming from node_modules we treat it as a source file. + if (!vendorRegex.test(modulePath)) { + return true } - return true + // If the module uses Gatsby as a dependency + // we want to treat it as src so we can extract queries + return modulesThatUseGatsby.some(module => + modulePath.includes(module.path) + ) }, type: `javascript/auto`, use: [loaders.js(options)], @@ -353,7 +355,7 @@ module.exports = async ({ return true } // If dep is babel-runtime or core-js, exclude - else if (/@babel(?:\/|\\{1,2})runtime|core-js/.test(modulePath)) { + if (/@babel(?:\/|\\{1,2})runtime|core-js/.test(modulePath)) { return true } From aa51604bd4771e34c0d4518d59a0a48efa53db21 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Tue, 2 Jul 2019 22:35:19 +0530 Subject: [PATCH 08/13] Add tests for include and exclude functions --- .../__snapshots__/webpack-utils.js.snap | 30 +++--- .../src/utils/__tests__/webpack-utils.js | 92 ++++++++++++++++++- 2 files changed, 106 insertions(+), 16 deletions(-) diff --git a/packages/gatsby/src/utils/__tests__/__snapshots__/webpack-utils.js.snap b/packages/gatsby/src/utils/__tests__/__snapshots__/webpack-utils.js.snap index 967fb09ebd072..ea89eecf03346 100644 --- a/packages/gatsby/src/utils/__tests__/__snapshots__/webpack-utils.js.snap +++ b/packages/gatsby/src/utils/__tests__/__snapshots__/webpack-utils.js.snap @@ -1,20 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`webpack utils js returns default values without any options 1`] = ` -Object { - "include": [Function], - "test": /\\\\\\.\\(js\\|mjs\\|jsx\\)\\$/, - "type": "javascript/auto", - "use": Array [ - Object { - "loader": "/packages/gatsby/src/utils/babel-loader.js", - "options": Object {}, - }, - ], -} -`; - -exports[`webpack utils js returns default values without any options 2`] = ` +exports[`webpack utils dependencies returns default values without any options 1`] = ` Object { "exclude": [Function], "test": /\\\\\\.\\(js\\|mjs\\)\\$/, @@ -40,3 +26,17 @@ Object { ], } `; + +exports[`webpack utils js returns default values without any options 1`] = ` +Object { + "include": [Function], + "test": /\\\\\\.\\(js\\|mjs\\|jsx\\)\\$/, + "type": "javascript/auto", + "use": Array [ + Object { + "loader": "/packages/gatsby/src/utils/babel-loader.js", + "options": Object {}, + }, + ], +} +`; diff --git a/packages/gatsby/src/utils/__tests__/webpack-utils.js b/packages/gatsby/src/utils/__tests__/webpack-utils.js index 14951ba0f1969..ae6e325e9936a 100644 --- a/packages/gatsby/src/utils/__tests__/webpack-utils.js +++ b/packages/gatsby/src/utils/__tests__/webpack-utils.js @@ -21,15 +21,105 @@ describe(`webpack utils`, () => { expect(rule).toMatchSnapshot() }) + describe(`include function`, () => { + let js + beforeAll(() => { + js = config.rules.js({ + modulesThatUseGatsby: [ + { + name: `gatsby-seo`, + path: `/Users/sidharthachatterjee/Code/gatsby-seo-test/node_modules/gatsby-seo`, + }, + ], + }) + }) + it(`includes source files from user code`, () => { + expect( + js.include( + `/Users/sidharthachatterjee/Code/gatsby-seo-test/src/pages/index.js` + ) + ).toEqual(true) + }) + it(`includes dependencies that use gatsby`, () => { + expect( + js.include( + `/Users/sidharthachatterjee/Code/gatsby-seo-test/node_modules/gatsby-seo/index.js` + ) + ).toEqual(true) + }) + it(`does not include other dependencies`, () => { + expect( + js.include( + `/Users/sidharthachatterjee/Code/gatsby-seo-test/node_modules/react/index.js` + ) + ).toEqual(false) + }) + it(`includes gatsby-browser.js`, () => { + expect( + js.include( + `/Users/sidharthachatterjee/Code/gatsby-seo-test/gatsby-browser.js` + ) + ).toEqual(true) + }) + }) + }) + describe(`dependencies`, () => { it(`adds dependency rule`, () => { expect(config.rules.dependencies).toEqual(expect.any(Function)) }) - it(`returns default values without any options`, () => { const rule = config.rules.dependencies() expect(rule).toMatchSnapshot() }) + describe(`exclude function`, () => { + let dependencies + beforeAll(() => { + dependencies = config.rules.dependencies({ + modulesThatUseGatsby: [ + { + name: `gatsby-seo`, + path: `/Users/sidharthachatterjee/Code/gatsby-seo-test/node_modules/gatsby-seo`, + }, + ], + }) + }) + it(`excludes source files from user code`, () => { + expect( + dependencies.exclude( + `/Users/sidharthachatterjee/Code/gatsby-seo-test/src/pages/index.js` + ) + ).toEqual(true) + }) + it(`excludes dependencies that use gatsby`, () => { + expect( + dependencies.exclude( + `/Users/sidharthachatterjee/Code/gatsby-seo-test/node_modules/gatsby-seo/index.js` + ) + ).toEqual(true) + }) + it(`excludes babel-runtime`, () => { + expect( + dependencies.exclude( + `/Users/misiek/test/pr15285/node_modules/@babel/runtime/helpers/interopRequireDefault.js` + ) + ).toEqual(true) + }) + it(`excludes core-js`, () => { + expect( + dependencies.exclude( + `/Users/misiek/test/pr15285/node_modules/core-js/modules/es6.array.iterator.js` + ) + ).toEqual(true) + }) + it(`includes dependencies that don't use gatsby`, () => { + expect( + dependencies.exclude( + `/Users/sidharthachatterjee/Code/gatsby-seo-test/node_modules/react/index.js` + ) + ).toEqual(false) + }) + }) }) }) From d861635024a2f314c56550fc045e69a558df60e0 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Tue, 2 Jul 2019 22:38:23 +0530 Subject: [PATCH 09/13] Add one more test for exclude function --- packages/gatsby/src/utils/__tests__/webpack-utils.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/gatsby/src/utils/__tests__/webpack-utils.js b/packages/gatsby/src/utils/__tests__/webpack-utils.js index ae6e325e9936a..5a62e21084fe3 100644 --- a/packages/gatsby/src/utils/__tests__/webpack-utils.js +++ b/packages/gatsby/src/utils/__tests__/webpack-utils.js @@ -120,6 +120,13 @@ describe(`webpack utils`, () => { ) ).toEqual(false) }) + it(`excludes gatsby-browser.js`, () => { + expect( + dependencies.exclude( + `/Users/sidharthachatterjee/Code/gatsby-seo-test/gatsby-browser.js` + ) + ).toEqual(true) + }) }) }) }) From b51f9ac69c156e1f7fc994de7d482ec5f702bbec Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Tue, 2 Jul 2019 22:41:18 +0530 Subject: [PATCH 10/13] moar tests --- .../gatsby/src/utils/__tests__/webpack-utils.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/gatsby/src/utils/__tests__/webpack-utils.js b/packages/gatsby/src/utils/__tests__/webpack-utils.js index 5a62e21084fe3..9fa0fc1d76091 100644 --- a/packages/gatsby/src/utils/__tests__/webpack-utils.js +++ b/packages/gatsby/src/utils/__tests__/webpack-utils.js @@ -41,6 +41,13 @@ describe(`webpack utils`, () => { ) ).toEqual(true) }) + it(`includes files from .cache`, () => { + expect( + js.include( + `/Users/sidharthachatterjee/Code/gatsby-seo-test/.cache/production-app.js` + ) + ).toEqual(true) + }) it(`includes dependencies that use gatsby`, () => { expect( js.include( @@ -92,6 +99,13 @@ describe(`webpack utils`, () => { ) ).toEqual(true) }) + it(`excludes files from .cache`, () => { + expect( + dependencies.exclude( + `/Users/sidharthachatterjee/Code/gatsby-seo-test/.cache/production-app.js` + ) + ).toEqual(true) + }) it(`excludes dependencies that use gatsby`, () => { expect( dependencies.exclude( From 584641427cf7eb5c3a35b87435ab04da33e1131a Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 2 Jul 2019 19:54:47 +0200 Subject: [PATCH 11/13] add some sanity e2e tests --- .../functionality/queries-in-packages.js | 14 ++++++++++++++ e2e-tests/development-runtime/package.json | 5 +++-- .../src/pages/queries-in-packages.js | 13 +++++++++++++ .../cypress/integration/queries-in-packages.js | 14 ++++++++++++++ e2e-tests/production-runtime/package.json | 1 + .../src/pages/queries-in-packages.js | 13 +++++++++++++ 6 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 e2e-tests/development-runtime/cypress/integration/functionality/queries-in-packages.js create mode 100644 e2e-tests/development-runtime/src/pages/queries-in-packages.js create mode 100644 e2e-tests/production-runtime/cypress/integration/queries-in-packages.js create mode 100644 e2e-tests/production-runtime/src/pages/queries-in-packages.js diff --git a/e2e-tests/development-runtime/cypress/integration/functionality/queries-in-packages.js b/e2e-tests/development-runtime/cypress/integration/functionality/queries-in-packages.js new file mode 100644 index 0000000000000..efcf5a6c588cd --- /dev/null +++ b/e2e-tests/development-runtime/cypress/integration/functionality/queries-in-packages.js @@ -0,0 +1,14 @@ +describe(`queries in packages`, () => { + beforeEach(() => { + cy.visit(`/queries-in-packages`).waitForRouteChange() + }) + + it(`Should extract and run query from gatsby component`, () => { + // we are using `gatsby-seo` package which sets + // window's title to title passed as prop followed by siteMetadata.title + cy.title().should( + `eq`, + `Testing queries in packages | Gatsby Default Starter` + ) + }) +}) diff --git a/e2e-tests/development-runtime/package.json b/e2e-tests/development-runtime/package.json index 3c2889fd16348..967c4175895b2 100644 --- a/e2e-tests/development-runtime/package.json +++ b/e2e-tests/development-runtime/package.json @@ -10,6 +10,7 @@ "gatsby-plugin-offline": "^2.1.0", "gatsby-plugin-react-helmet": "^3.0.6", "gatsby-plugin-sharp": "^2.0.37", + "gatsby-seo": "^0.1.0", "gatsby-source-filesystem": "^2.0.33", "gatsby-transformer-remark": "^2.3.12", "gatsby-transformer-sharp": "^2.1.19", @@ -25,11 +26,11 @@ "license": "MIT", "scripts": { "build": "gatsby build", - "develop": "cross-env ENABLE_GATSBY_REFRESH_ENDPOINT=true gatsby develop", + "develop": "cross-env CYPRESS_SUPPORT=y ENABLE_GATSBY_REFRESH_ENDPOINT=true gatsby develop", "serve": "gatsby serve", "start": "npm run develop", "format": "prettier --write \"src/**/*.js\"", - "test": "CYPRESS_SUPPORT=y npm run start-server-and-test || (npm run reset && exit 1)", + "test": "npm run start-server-and-test || (npm run reset && exit 1)", "posttest": "npm run reset", "reset": "node scripts/reset.js", "reset:preview": "node plugins/gatsby-source-fake-data/reset.js && npm run update:preview", diff --git a/e2e-tests/development-runtime/src/pages/queries-in-packages.js b/e2e-tests/development-runtime/src/pages/queries-in-packages.js new file mode 100644 index 0000000000000..dde20480b38fe --- /dev/null +++ b/e2e-tests/development-runtime/src/pages/queries-in-packages.js @@ -0,0 +1,13 @@ +import React from "react" +import SEO from "gatsby-seo" + +import Layout from "../components/layout" + +export default () => ( + + + +) diff --git a/e2e-tests/production-runtime/cypress/integration/queries-in-packages.js b/e2e-tests/production-runtime/cypress/integration/queries-in-packages.js new file mode 100644 index 0000000000000..efcf5a6c588cd --- /dev/null +++ b/e2e-tests/production-runtime/cypress/integration/queries-in-packages.js @@ -0,0 +1,14 @@ +describe(`queries in packages`, () => { + beforeEach(() => { + cy.visit(`/queries-in-packages`).waitForRouteChange() + }) + + it(`Should extract and run query from gatsby component`, () => { + // we are using `gatsby-seo` package which sets + // window's title to title passed as prop followed by siteMetadata.title + cy.title().should( + `eq`, + `Testing queries in packages | Gatsby Default Starter` + ) + }) +}) diff --git a/e2e-tests/production-runtime/package.json b/e2e-tests/production-runtime/package.json index 89c90bca24b6b..b05f9cd4f7ef7 100644 --- a/e2e-tests/production-runtime/package.json +++ b/e2e-tests/production-runtime/package.json @@ -9,6 +9,7 @@ "gatsby-plugin-manifest": "^2.0.17", "gatsby-plugin-offline": "^2.0.23", "gatsby-plugin-react-helmet": "^3.0.6", + "gatsby-seo": "^0.1.0", "glob": "^7.1.3", "react": "^16.8.0", "react-dom": "^16.8.0", diff --git a/e2e-tests/production-runtime/src/pages/queries-in-packages.js b/e2e-tests/production-runtime/src/pages/queries-in-packages.js new file mode 100644 index 0000000000000..bd32b0c8083b5 --- /dev/null +++ b/e2e-tests/production-runtime/src/pages/queries-in-packages.js @@ -0,0 +1,13 @@ +import React from 'react' +import SEO from 'gatsby-seo' + +import Layout from '../components/layout' + +export default () => ( + + + +) From 1f4531b94a54b87c97922e055968c2ba66d56ff0 Mon Sep 17 00:00:00 2001 From: Sidhartha Chatterjee Date: Wed, 3 Jul 2019 00:42:29 +0530 Subject: [PATCH 12/13] Fix production runtime tests --- e2e-tests/production-runtime/src/components/bio.js | 11 ++--------- .../static-query/exported-variable-query.js | 6 ++---- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/e2e-tests/production-runtime/src/components/bio.js b/e2e-tests/production-runtime/src/components/bio.js index 50604f3b3e3ee..4fa3013a866d6 100644 --- a/e2e-tests/production-runtime/src/components/bio.js +++ b/e2e-tests/production-runtime/src/components/bio.js @@ -7,11 +7,7 @@ function Bio() { query={bioQuery} render={data => (
-

- A site by {data.site.siteMetadata.author.name} who - {` `} - {data.site.siteMetadata.author.bio} -

+

A site by {data.site.siteMetadata.author}

)} /> @@ -22,10 +18,7 @@ export const bioQuery = graphql` { site { siteMetadata { - author { - bio - name - } + author } } } diff --git a/e2e-tests/production-runtime/src/components/static-query/exported-variable-query.js b/e2e-tests/production-runtime/src/components/static-query/exported-variable-query.js index 449cd05204bf3..ab8e7d94bd186 100644 --- a/e2e-tests/production-runtime/src/components/static-query/exported-variable-query.js +++ b/e2e-tests/production-runtime/src/components/static-query/exported-variable-query.js @@ -5,7 +5,7 @@ function ExportedVariable(props) { return (

{data.site.siteMetadata.author.name}

} + render={data =>

{data.site.siteMetadata.author}

} /> ) } @@ -14,9 +14,7 @@ export const nameQuery = graphql` { site { siteMetadata { - author { - name - } + author } } } From fbc57d5fec23e0b578c0db4100fa010d1b32570f Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 2 Jul 2019 21:29:46 +0200 Subject: [PATCH 13/13] fix(e2e-production-runtime): adjust siteMetadata to shape gatsby-seo needs --- e2e-tests/production-runtime/gatsby-config.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/e2e-tests/production-runtime/gatsby-config.js b/e2e-tests/production-runtime/gatsby-config.js index eebaa291e6bb4..2ebb93056e601 100644 --- a/e2e-tests/production-runtime/gatsby-config.js +++ b/e2e-tests/production-runtime/gatsby-config.js @@ -1,10 +1,8 @@ module.exports = { siteMetadata: { title: `Gatsby Default Starter`, - author: { - name: `Kyle Mathews`, - bio: `lives and works in San Francisco building useful things`, - }, + author: `Kyle Mathews`, + description: `This is site for production runtime e2e tests`, }, plugins: [ `gatsby-plugin-react-helmet`,