Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"SyntaxError: Unexpected string" when implementing unit testing guide on stock blog starter #9614

Closed
ebello opened this issue Oct 31, 2018 · 3 comments · Fixed by #9629
Closed
Labels
type: question or discussion Issue discussing or asking a question about Gatsby

Comments

@ebello
Copy link

ebello commented Oct 31, 2018

Description

I am receiving an error when running yarn test after installing the gatsby-starter-blog and going through the Unit testing guide. The error I receive is:

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import "core-js/modules/es6.date.to-json";
                                                                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    SyntaxError: Unexpected string

Steps to reproduce

I have a demo repo here: gatsby-starter-blog-jest-error

  1. Clone gatsby-starter-blog-jest-error
  2. yarn
  3. yarn test

Expected result

I should receive the SyntaxError: Invalid or unexpected token for import 'typeface-montserrat' as referenced in the guide.

Actual result

I receive an error relating to babel not being able to transform the test file. It seems to be a regression from this commit: 2788f93. If I revert the babelOptions back to the following, I get the expected result above.

const babelOptions = {
  presets: ["@babel/react", "@babel/env"],
  plugins: [
    "@babel/plugin-proposal-optional-chaining",
    "@babel/plugin-proposal-class-properties",
  ],
};

Environment

  System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i7-6567U CPU @ 3.30GHz
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 10.13.0 - /usr/local/opt/node@10/bin/node
    Yarn: 1.12.1 - /usr/local/bin/yarn
    npm: 6.4.1 - /usr/local/opt/node@10/bin/npm
  Browsers:
    Chrome: 70.0.3538.77
    Firefox: 57.0
    Safari: 12.0
  npmPackages:
    gatsby: ^2.0.19 => 2.0.35 
    gatsby-plugin-feed: ^2.0.8 => 2.0.9 
    gatsby-plugin-google-analytics: ^2.0.5 => 2.0.7 
    gatsby-plugin-manifest: ^2.0.5 => 2.0.7 
    gatsby-plugin-offline: ^2.0.5 => 2.0.10 
    gatsby-plugin-react-helmet: ^3.0.0 => 3.0.1 
    gatsby-plugin-sharp: ^2.0.6 => 2.0.10 
    gatsby-plugin-typography: ^2.2.0 => 2.2.1 
    gatsby-remark-copy-linked-files: ^2.0.5 => 2.0.6 
    gatsby-remark-images: ^2.0.4 => 2.0.5 
    gatsby-remark-prismjs: ^3.0.0 => 3.0.3 
    gatsby-remark-responsive-iframe: ^2.0.5 => 2.0.6 
    gatsby-remark-smartypants: ^2.0.5 => 2.0.6 
    gatsby-source-filesystem: ^2.0.2 => 2.0.6 
    gatsby-transformer-remark: ^2.1.6 => 2.1.11 
    gatsby-transformer-sharp: ^2.1.3 => 2.1.7 
  npmGlobalPackages:
    gatsby-cli: 2.4.4
@kakadiadarpan
Copy link
Contributor

It seems to be a regression from this commit: 2788f93.

This commit implements babel-preset-gatsby, which does the same thing as below:

const babelOptions = {
  presets: ["@babel/react", "@babel/env"],
  plugins: [
    "@babel/plugin-proposal-optional-chaining",
    "@babel/plugin-proposal-class-properties",
  ],
};

I'm able to reproduce this issue, but I'm not sure why this is causing the problem.

@pieh any ideas regarding this?

@kakadiadarpan kakadiadarpan added the type: question or discussion Issue discussing or asking a question about Gatsby label Nov 1, 2018
@DSchau
Copy link
Contributor

DSchau commented Nov 1, 2018

@ebello @kakadiadarpan I'll check this out right now!

DSchau added a commit to DSchau/gatsby that referenced this issue Nov 1, 2018
This PR does a few things, namely:

- Fixes a few things with the test stage, e.g. uses commonjs modules for
test running, uses the current node version for @babel/preset-env, etc.
- Fixes up docs slightly for the unit testing guide
- Fixes gatsbyjs#9614
@ebello
Copy link
Author

ebello commented Nov 1, 2018

Excellent, thank you @DSchau!

@pieh pieh closed this as completed in #9629 Nov 5, 2018
pieh pushed a commit that referenced this issue Nov 5, 2018
This PR does a few things, namely:

- Fixes a few things with the test stage, e.g. uses commonjs modules for
test running, uses the current node version for @babel/preset-env, etc.
- Fixes up docs slightly for the unit testing guide
- Fixes #9614

<!--
  Q. Which branch should I use for my pull request?
  A. Use `master` branch (probably).

  Q. Which branch if my change is a bug fix for Gatsby v1?
  A. In this case, you should use the `v1` branch

  Q. Which branch if I'm still not sure?
  A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :)

  Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2.

  Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/
-->
gpetrioli pushed a commit to gpetrioli/gatsby that referenced this issue Jan 22, 2019
…#9629)

This PR does a few things, namely:

- Fixes a few things with the test stage, e.g. uses commonjs modules for
test running, uses the current node version for @babel/preset-env, etc.
- Fixes up docs slightly for the unit testing guide
- Fixes gatsbyjs#9614

<!--
  Q. Which branch should I use for my pull request?
  A. Use `master` branch (probably).

  Q. Which branch if my change is a bug fix for Gatsby v1?
  A. In this case, you should use the `v1` branch

  Q. Which branch if I'm still not sure?
  A. Use `master` branch. Ask in the PR if you're not sure and a Gatsby maintainer will be happy to help :)

  Note: We will only accept bug fixes for Gatsby v1. New features should be added to Gatsby v2.

  Learn more about contributing: https://www.gatsbyjs.org/docs/how-to-contribute/
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question or discussion Issue discussing or asking a question about Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants