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

[BUG] @snowpack/app-scripts-react is not compatible with Jest 27. #3398

Open
4 tasks done
pusewicz opened this issue Jun 1, 2021 · 9 comments
Open
4 tasks done

[BUG] @snowpack/app-scripts-react is not compatible with Jest 27. #3398

pusewicz opened this issue Jun 1, 2021 · 9 comments

Comments

@pusewicz
Copy link

pusewicz commented Jun 1, 2021

Bug Report Quick Checklist

  • I am on the latest version of Snowpack & all plugins.
  • I use package manager yarn
  • I run Snowpack on OS Mac
  • I run Snowpack on Node.js v12+

Describe the bug

@snowpack/app-scripts-react is not compatible with Jest 27.

TypeError: Cannot destructure property 'config' of 'cacheKeyOptions' as it is undefined.
    at Object.getCacheKey (/Users/piotr/[...]/node_modules/@snowpack/app-scripts-react/node_modules/babel-jest/build/index.js:217:14)
    at ScriptTransformer._getCacheKey (/Users/piotr/[...]/node_modules/@jest/transform/build/ScriptTransformer.js:280:41)
    at ScriptTransformer._getFileCachePath (/Users/piotr/[...]/node_modules/@jest/transform/build/ScriptTransformer.js:351:27)
    at ScriptTransformer.transformSource (/Users/piotr/[...]/node_modules/@jest/transform/build/ScriptTransformer.js:588:32)
    at revertHook.exts (/Users/piotr/[...]/node_modules/@jest/transform/build/ScriptTransformer.js:864:18)
    at Module._compile (/Users/piotr/[...]/node_modules/pirates/lib/index.js:93:29)
    at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Object.newLoader (/Users/piotr/[...]/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)

Looks like the babel-jest dependency should be updated to 27.

Expected behavior

Tests cases should be executed.

@RobertLowe
Copy link

This is the correct fix, jest and babel-jest should follow the same major, ex 27.x.x

@manavm1990
Copy link

"babel-jest": "~27.0.2", Added that in package.json under devDependencies, of course.
Still getting similar issue as indicated by @pusewicz

@bkilrain
Copy link

Looks like Snowpack should be very interested in v27 as it claims "experimental support" for ES modules. Has anyone tried to upgrade Jest by opting out of the config that ships with Snowpack?

@Belco90
Copy link

Belco90 commented Jul 26, 2021

I had to downgrade to jest v26 meanwhile. It would be really interesting to get jest v27 support.

@chphillipvose
Copy link

So I've forked locally to figure out a fix, and the package needs a couple of changes to work. The package.json file needs babel-jest updating to v27.x as per @pusewicz 's suggestion. But it also needs the createTransformer method updating (as per this issue in the Jest repo jestjs/jest#11444) which would look something like this:

packages/app-scripts-react/jest/babelTransform.js

// @remove-file-on-eject
/**
 * Copyright (c) 2014-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
'use strict'

const babelJestMd = require('babel-jest')
const importMetaBabelPlugin = require('./importMetaBabelPlugin')

const babelJest = babelJestMd.__esModule ? babelJestMd.default : babelJestMd

module.exports = babelJest.createTransformer({
  presets: ['babel-preset-react-app', '@babel/preset-react', '@babel/preset-typescript'],
  plugins: [[importMetaBabelPlugin]],
})

drwpow pushed a commit that referenced this issue Oct 19, 2021
* Upgrade babel-jest version

This is to match with the current version of Jest. Also Jest is added
as a peer dependency to reflect this.

* Change the babel jest transform script

This is done to reflect the new API changes in babel-jest.
The second line is done so that it can stay backwards compatible with
Jest 26 if needed.

References:
#3398 (comment)
jestjs/jest#11444 (comment)

* Use jsdom as a test environment to run jest

This is done so the react testing-library can render the DOM elements
in testing.
@trusktr
Copy link

trusktr commented Dec 8, 2021

I'm on babel-jest 27.4.2 and what worked for me is pinning jest-playwright-preset to 1.6.0. The error was happening with jest-playwright 1.7 in my case.

@zachariahtimothy
Copy link

I was able to make this work by using Jest 26. The NPM version (2.0.1, published 9 months ago) that gets installed locally only works with Jest 26, however the source code is version 2.0.1 (updated 2 months ago) and supports Jest 27. Seems it was fixed and forgot to get published with a new version.

@oxodesign
Copy link

I was able to make this work by using Jest 26. The NPM version (2.0.1, published 9 months ago) that gets installed locally only works with Jest 26, however the source code is version 2.0.1 (updated 2 months ago) and supports Jest 27. Seems it was fixed and forgot to get published with a new version.

You are right, facing same issue. Hopefully someone from the team (@drwpow ?) will do a new release for "@snowpack/app-scripts-react".

@trusktr
Copy link

trusktr commented Jan 8, 2022

I had this error when I updated from Jest 26 to 27 without updating babel-jest from 26. Once I updated babel-jest to 27, solved.

MakotoUwaya pushed a commit to MakotoUwaya/webapp-template that referenced this issue Jan 21, 2022
- Remove @snowpack/app-scripts-react config
- FredKSchott/snowpack#3398
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants