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

Instantiating an instance of Link in unit tests triggers an error in withPrefix #24789

Closed
planetcohen opened this issue Jun 4, 2020 · 2 comments · Fixed by #25608
Closed
Assignees
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@planetcohen
Copy link

Description

Running unit tests in my project (jest and react testing library) triggers a failure in the Link component in the withPrefix function.

The specific issue is the following line (which was recently changed):

export function withPrefix(path, prefix = __BASE_PATH__) {

If __BASE_PATH__ is not defined, this triggers an error. The previous version of this file guarded against this case by checking that typeof __BASE_PATH__ is defined.

I will be submitting a PR shortly with a fix.

Steps to reproduce

Run a unit test using Jest with RTL for any component that uses the Gatsby Link component.

Expected result

No reference error.

Actual result

The specific error is:

ReferenceError: __BASE_PATH__ is not defined

Environment

  System:
    OS: macOS 10.15.4
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 10.21.0 - /var/folders/82/v_28mld95zqd97n81x_c2kb00000gn/T/yarn--1591305860413-0.03955211442214068/node
    Yarn: 1.22.4 - /var/folders/82/v_28mld95zqd97n81x_c2kb00000gn/T/yarn--1591305860413-0.03955211442214068/yarn
    npm: 6.14.4 - /usr/local/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 83.0.4103.97
    Edge: 83.0.478.44
    Firefox: 77.0
    Safari: 13.1
  npmPackages:
    gatsby: ^2.23.0 => 2.23.0
    gatsby-background-image: ^1.0.1 => 1.1.1
    gatsby-cli: ^2.12.43 => 2.12.43
    gatsby-image: ^2.4.6 => 2.4.6
    gatsby-plugin-google-analytics: ^2.3.3 => 2.3.3
    gatsby-plugin-google-tagmanager: ^2.3.4 => 2.3.4
    gatsby-plugin-lodash: ^3.3.3 => 3.3.3
    gatsby-plugin-module-resolver: ^1.0.3 => 1.0.3
    gatsby-plugin-prefetch-google-fonts: ^1.4.3 => 1.4.3
    gatsby-plugin-react-helmet: ^3.3.3 => 3.3.3
    gatsby-plugin-react-svg: ^3.0.0 => 3.0.0
    gatsby-plugin-remove-generator: ^1.0.5 => 1.0.5
    gatsby-plugin-remove-trailing-slashes: ^2.3.4 => 2.3.4
    gatsby-plugin-root-import: ^2.0.5 => 2.0.5
    gatsby-plugin-sass: ^2.3.3 => 2.3.3
    gatsby-plugin-schema-snapshot: ^1.0.0 => 1.0.0
    gatsby-plugin-sharp: ^2.6.10 => 2.6.10
    gatsby-plugin-sitemap: ./plugins/gatsby-plugin-sitemap/ => 2.2.4
    gatsby-plugin-styled-components: ^3.3.3 => 3.3.3
    gatsby-plugin-typescript: ^2.4.4 => 2.4.4
    gatsby-plugin-webpack-bundle-analyser-v2: ^1.1.10 => 1.1.10
    gatsby-source-contentful: 2.3.14 => 2.3.14
    gatsby-source-filesystem: ^2.3.10 => 2.3.10
    gatsby-transformer-json: ^2.4.4 => 2.4.4
    gatsby-transformer-sharp: ^2.5.4 => 2.5.4
    gatsby-transformer-sqip: ^2.3.10 => 2.3.10
@planetcohen planetcohen added the type: bug An issue or pull request relating to a bug in Gatsby label Jun 4, 2020
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jun 4, 2020
@planetcohen
Copy link
Author

Here is the PR with the fix: #24790

@freiksenet freiksenet added status: inkteam assigned and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jun 5, 2020
@czabaj
Copy link

czabaj commented Jun 9, 2020

As workaround, you can configure jest.config.js

globals: {
  __PATH_PREFIX__: ``,
  __BASE_PATH__: ``, // add this line
},

see Unit testing docs for more info.

davifantasia added a commit to commercetools/commercetools-docs-kit that referenced this issue Jun 15, 2020
davifantasia added a commit to commercetools/commercetools-docs-kit that referenced this issue Jun 15, 2020
* fix(deps): update all dependencies

* chore: downgrade gatsby link because of this issue - gatsbyjs/gatsby#24789

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Adewale Oluyinka <davifantasia@hotmail.com>
davifantasia added a commit to commercetools/commercetools-docs-kit that referenced this issue Jun 25, 2020
davifantasia added a commit to commercetools/commercetools-docs-kit that referenced this issue Jun 25, 2020
* chore(deps): update all dependencies

* fix: tests breaks, see issue here - gatsbyjs/gatsby#24789

* fix: downgrade stylelint

* fix: revert back to using latest gatsby link

* fix: updated yarn lock

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Adewale Oluyinka <davifantasia@hotmail.com>
cbillowes added a commit to cbillowes/curious-programmer-nitrogen that referenced this issue Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants