FredKSchott / snowpack

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️
https://www.snowpack.dev
MIT License
19.48k stars 921 forks source link

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

Open pusewicz opened 3 years ago

pusewicz commented 3 years ago

Bug Report Quick Checklist

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 commented 3 years ago

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

manavm1990 commented 3 years ago

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

bkilrain commented 3 years ago

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 commented 3 years ago

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

chphillipvose commented 3 years ago

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 https://github.com/facebook/jest/issues/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]],
})
trusktr commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.