{"action":"created","issue":{"url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/5824","repository_url":"https://api.github.com/repos/gatsbyjs/gatsby","labels_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/5824/labels{/name}","comments_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/5824/comments","events_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/5824/events","html_url":"https://github.com/gatsbyjs/gatsby/issues/5824","id":330915902,"node_id":"MDU6SXNzdWUzMzA5MTU5MDI=","number":5824,"title":"[Gatsby v2] Jest unit testing and configuration for Gatsby","user":{"login":"thescientist13","id":895923,"node_id":"MDQ6VXNlcjg5NTkyMw==","avatar_url":"https://avatars0.githubusercontent.com/u/895923?v=4","gravatar_id":"","url":"https://api.github.com/users/thescientist13","html_url":"https://github.com/thescientist13","followers_url":"https://api.github.com/users/thescientist13/followers","following_url":"https://api.github.com/users/thescientist13/following{/other_user}","gists_url":"https://api.github.com/users/thescientist13/gists{/gist_id}","starred_url":"https://api.github.com/users/thescientist13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thescientist13/subscriptions","organizations_url":"https://api.github.com/users/thescientist13/orgs","repos_url":"https://api.github.com/users/thescientist13/repos","events_url":"https://api.github.com/users/thescientist13/events{/privacy}","received_events_url":"https://api.github.com/users/thescientist13/received_events","type":"User","site_admin":false},"labels":[{"id":214544672,"node_id":"MDU6TGFiZWwyMTQ1NDQ2NzI=","url":"https://api.github.com/repos/gatsbyjs/gatsby/labels/%F0%9F%8F%B7%20type:%20bug","name":"🏷 type: bug","color":"d93f0b","default":false},{"id":214544675,"node_id":"MDU6TGFiZWwyMTQ1NDQ2NzU=","url":"https://api.github.com/repos/gatsbyjs/gatsby/labels/%F0%9F%93%8D%20status:%20help%20wanted","name":"📍 status: help wanted","color":"0e8a16","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-09T20:10:32Z","updated_at":"2018-06-12T22:20:14Z","closed_at":null,"author_association":"NONE","body":"## Description\r\nI was working my way through [the upgrade process to v2](https://v2--gatsbyjs.netlify.com/docs/migrating-from-v1-to-v2/#update-gatsby-version) for my [website](https://github.com/thegreenhouseio/www.thegreenhouse.io/tree/technical/issue-82-gatsby-v2-upgrade) and wanted to report a couple things while running my unit tests with Jest and Gatsby v2 (coming from v1).\r\n\r\n###   Cannot find module './pages.json' from 'gatsby-browser-entry.js'\r\nI am seeing this in some specs when running unit tests\r\n```shell\r\n FAIL  src/components/header/header.spec.jsx\r\n  ● Test suite failed to run\r\n\r\n    Cannot find module './pages.json' from 'gatsby-browser-entry.js'\r\n\r\n      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)\r\n      at Object.<anonymous> (node_modules/gatsby/cache-dir/gatsby-browser-entry.js:20:37)\r\n\r\n```\r\n\r\n\r\n```javascript\r\n# component\r\nimport React from 'react';\r\nimport { Link } from 'gatsby';\r\nimport './header.css';\r\n\r\nconst Header = () => {\r\n  return (\r\n    <div className=\"header\"> \r\n      <Link to=\"/\">\r\n        <header></header>\r\n        <h2 className=\"caption\">A DREAMER BY DESIGN</h2>\r\n      </Link>\r\n    </div>\r\n  );\r\n};\r\n\r\nexport default Header;\r\n\r\n# spec\r\nimport * as React from 'react';\r\nimport { mount, configure } from 'enzyme';\r\nimport Adapter from 'enzyme-adapter-react-16';\r\nimport Header from './header';\r\n\r\nconfigure({ adapter: new Adapter() });\r\n\r\ndescribe('Header Component', () => {\r\n  let header;\r\n\r\n  beforeEach(() => {\r\n    header = mount(<Header/>);\r\n  });\r\n\r\n  it('should not be null', () => {\r\n    expect(header).not.toBeNull();\r\n    expect(header.find('.header').length).toEqual(1);\r\n  });\r\n\r\n});\r\n```\r\n\r\nNote sure if it is related to [this issue](https://github.com/gatsbyjs/gatsby/issues/2932#issuecomment-376306319)?\r\n\r\n### .babelrc\r\nNot so much an issue with Gatsby per se, but maybe worth an update somewhere in the docs, which I am happy to do as it is a change in expected behavior.  (relative to v1)\r\n\r\nI had a [_.babelrc_ file in the root of my project](https://github.com/thegreenhouseio/www.thegreenhouse.io/blob/master/.babelrc) which was read by Jest to process JSX and ES2015+ syntax.\r\n```shell\r\n{\r\n  \"presets\": [\"react\", \"env\"]\r\n}\r\n```\r\n\r\nAfter the upgrade, Gatsby which now depends on **Babel** 7, will now reflect **Babel**'s  configuration resolution behavior, which will now defer to the consuming project's top level _.babelrc_ instead, which generated this error\r\n```\r\nsuccess onPostBootstrap — 0.001 s\r\n\r\ninfo bootstrap finished - 3.68 s\r\n\r\n\r\nerror Generating JavaScript bundles failed\r\n\r\n\r\n  Error: Cannot find module 'env'\r\n\r\n  - v8-compile-cache.js:162 require.resolve\r\n    [www.thegreenhouse.io]/[v8-compile-cache]/v8-compile-cache.js:162:23\r\n\r\n  - babel-config.js:17 abstractConfig.presets.forEach.p\r\n    [www.thegreenhouse.io]/[gatsby]/dist/utils/babel-config.js:17:61\r\n\r\n  - Array.forEach\r\n\r\n  - babel-config.js:17 buildConfig\r\n    [www.thegreenhouse.io]/[gatsby]/dist/utils/babel-config.js:17:26\r\n\r\n  - babel-config.js:52\r\n    [www.thegreenhouse.io]/[gatsby]/dist/utils/babel-config.js:52:19\r\n\r\n  - Generator.next\r\n\r\n  - next_tick.js:131 _combinedTickCallback\r\n    internal/process/next_tick.js:131:7\r\n\r\n  - next_tick.js:180 process._tickCallback\r\n    internal/process/next_tick.js:180:9\r\n\r\n\r\nerror An unexpected error occurred: \"Command failed.\r\nExit code: 1\r\nCommand: sh\r\nArguments: -c yarn lint && rimraf ./public && gatsby build\r\n```\r\n\r\nSolution was to delete my _.babelrc_ file and \"move\" the configuration over to **Jest**, per the recommendation [here](https://github.com/facebook/jest/issues/1468#issuecomment-361260279) to avoid the conflict. \r\n\r\n### Steps to reproduce\r\n1. Followed the v2 Upgrade guide\r\n1. Updated relevant specs to use **enzyme-adapter-react-16**\r\n1. Moved **Babel** configuration to **Jest** (see description above ^)\r\n\r\n### Expected result\r\n1. Unit tests would continue to pass\r\n\r\n### Actual result\r\n1. Some tests fail with this error\r\n```shell\r\nsuccess onPostBootstrap — 0.001 s\r\n\r\ninfo bootstrap finished - 3.68 s\r\n\r\n\r\nerror Generating JavaScript bundles failed\r\n\r\n\r\n  Error: Cannot find module 'env'\r\n\r\n  - v8-compile-cache.js:162 require.resolve\r\n    [www.thegreenhouse.io]/[v8-compile-cache]/v8-compile-cache.js:162:23\r\n\r\n  - babel-config.js:17 abstractConfig.presets.forEach.p\r\n    [www.thegreenhouse.io]/[gatsby]/dist/utils/babel-config.js:17:61\r\n\r\n  - Array.forEach\r\n\r\n  - babel-config.js:17 buildConfig\r\n    [www.thegreenhouse.io]/[gatsby]/dist/utils/babel-config.js:17:26\r\n\r\n  - babel-config.js:52\r\n    [www.thegreenhouse.io]/[gatsby]/dist/utils/babel-config.js:52:19\r\n\r\n  - Generator.next\r\n\r\n  - next_tick.js:131 _combinedTickCallback\r\n    internal/process/next_tick.js:131:7\r\n\r\n  - next_tick.js:180 process._tickCallback\r\n    internal/process/next_tick.js:180:9\r\n\r\n\r\nerror An unexpected error occurred: \"Command failed.\r\nExit code: 1\r\nCommand: sh\r\nArguments: -c yarn lint && rimraf ./public && gatsby build\r\n```\r\n\r\n### Environment\r\n```shell\r\n$ ./node_modules/.bin/gatsby info --clipboard\r\n\r\n  System:\r\n    OS: macOS High Sierra 10.13.5\r\n    CPU: x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz\r\n    Shell: 3.2.57 - /bin/bash\r\n  Binaries:\r\n    Node: 8.9.4 - /usr/local/bin/node\r\n    Yarn: 1.5.1 - ~/.yarn/bin/yarn\r\n    npm: 5.6.0 - /usr/local/bin/npm\r\n  Browsers:\r\n    Chrome: 67.0.3396.79\r\n    Firefox: 60.0.1\r\n    Safari: 11.1.1\r\n  npmPackages:\r\n    gatsby: next => 2.0.0-alpha.51\r\n    gatsby-cli: ^1.1.58 => 1.1.58\r\n    gatsby-plugin-google-analytics: next => 1.0.20-10\r\n    gatsby-plugin-react-helmet: next => 2.0.12-7\r\n    gatsby-plugin-sitemap: next => 1.2.14-10\r\n    gatsby-plugin-typography: next => 2.0.1-11\r\n```\r\n\r\n### File contents (if changed)\r\n\r\n`gatsby-config.js`\r\n```javascript\r\nmodule.exports = {\r\n  siteMetadata: {\r\n    title: 'The Greenhouse I/O',\r\n    siteUrl: 'https://www.thegreenhouse.io',\r\n    description: 'Personal / portfolio website for The Greenhouse.'\r\n  },\r\n  plugins: [\r\n    'gatsby-plugin-typography', \r\n    'gatsby-plugin-sitemap',\r\n    'gatsby-plugin-react-helmet',\r\n    {\r\n      resolve: 'gatsby-plugin-google-analytics',\r\n      options: {\r\n        trackingId: 'xxx',\r\n        head: true\r\n      }\r\n    }\r\n  ]\r\n};\r\n```\r\n\r\n`package.json`: N/A <!-- Please use a code block or just leave it as is if wasn't changed -->\r\n`gatsby-node.js`: N/A <!-- Please use a code block or just leave it as is if wasn't changed -->\r\n`gatsby-browser.js`: N/A <!-- Please use a code block or just leave it as is if wasn't changed -->\r\n`gatsby-ssr.js`: N/A <!-- Please use a code block or just leave it as is if wasn't changed -->\r\n\r\n\r\nThanks for everything and let me know if you need more info!  The upgrade was straightforward for me and everything else is working as expected.  👍 "},"comment":{"url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/comments/396753061","html_url":"https://github.com/gatsbyjs/gatsby/issues/5824#issuecomment-396753061","issue_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/5824","id":396753061,"node_id":"MDEyOklzc3VlQ29tbWVudDM5Njc1MzA2MQ==","user":{"login":"m-allanson","id":381801,"node_id":"MDQ6VXNlcjM4MTgwMQ==","avatar_url":"https://avatars1.githubusercontent.com/u/381801?v=4","gravatar_id":"","url":"https://api.github.com/users/m-allanson","html_url":"https://github.com/m-allanson","followers_url":"https://api.github.com/users/m-allanson/followers","following_url":"https://api.github.com/users/m-allanson/following{/other_user}","gists_url":"https://api.github.com/users/m-allanson/gists{/gist_id}","starred_url":"https://api.github.com/users/m-allanson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m-allanson/subscriptions","organizations_url":"https://api.github.com/users/m-allanson/orgs","repos_url":"https://api.github.com/users/m-allanson/repos","events_url":"https://api.github.com/users/m-allanson/events{/privacy}","received_events_url":"https://api.github.com/users/m-allanson/received_events","type":"User","site_admin":false},"created_at":"2018-06-12T22:20:14Z","updated_at":"2018-06-12T22:20:14Z","author_association":"CONTRIBUTOR","body":"Thanks for the detailed write up!\r\n\r\n### Cannot find module './pages.json' from 'gatsby-browser-entry.js'\r\n\r\nThis seems like a bug that should be fixed. In v2 the Link component is exported from Gatsby itself. This is done in [`gatsby-browser-entry.js`](https://github.com/gatsbyjs/gatsby/blob/v2/packages/gatsby/src/cache-dir/gatsby-browser-entry.js#L3-L4) which also expects the `pages.json` file you see in your error messages. However this file is not available at `node_modules/gatsby/cache-dir/pages.json` as it's created in your project root at `.cache/pages.json` at build time.\r\n\r\nA 'quick fix' for this would be to always have an empty `pages.json` file available. But maybe there's a cleaner way to export the Link component. @pieh do you have any thoughts on this?\r\n\r\n### .babelrc\r\n\r\nAdding a note about this in the v2 migration guide would be very useful I think. I'd be be very happy to see a PR if you're interested? Maybe it could also link to the [custom babelrc docs](https://v2--gatsbyjs.netlify.com/docs/babel/#how-to-use-a-custom-babelrc-file)?\r\n\r\nI'm glad to hear everything else went smoothly :)"}}
{"actor":{"display_login":"m-allanson"}}