Jest fails when using node 20
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- javascript, node.js
- 領域
- testing-qa
調査の方向性
まず jest.config.js と config/jest-before.js を確認し、次に update/node-20 ブランチで yarn jest を実行して、layout-grid の migrations.js と invalidations.js のテストで発生する失敗を再現します。試行されたパッチで十分だと決めつけず、報告された Jest、@wordpress/scripts、uuid のエラーと、react-resize-aware が見つからないエラーを追跡します。Node 20 で Jest スイートが通り、リポジトリでアップグレードを完了できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
We tried to upgrade node to version 20 in https://github.com/Automattic/block-experiments/pull/340, however, the effort got blocked due to failures in Jest (https://github.com/Automattic/block-experiments/pull/340#issuecomment-1887293084).
⚠️ In order to upgrade node to version 20 in this repository, we'd need to address this issue.
Steps to reproduce it:
- Checkout branch
update/node-20(https://github.com/Automattic/block-experiments/pull/340) - Run
yarn jest - Observe the error:
FAIL blocks/layout-grid/src/__tests__/migrations.js
● Test suite failed to run
The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/configuration#testenvironment-string.
Consider using the "jsdom" test environment.
ReferenceError: window is not defined
at Object.<anonymous> (node_modules/@wordpress/jest-preset-default/scripts/setup-globals.js:2:14)
Seems that apart from upgrading the package @wordpress/scripts, we'd need to update the Jest configuration and upgrade other packages. So far, I tried the following updates but none seemed to work:
1 - Use jsdom as the test environment
- Apply the following patch:
diff --git forkSrcPrefix/jest.config.js forkDstPrefix/jest.config.js
index 76cd5ec2e813f9b6d68a4ac6655d034eb7657b7f..c07fb045d95b75c6b6b17fa640cca8f45f720e0b 100644
--- forkSrcPrefix/jest.config.js
+++ forkDstPrefix/jest.config.js
@@ -12,6 +12,7 @@ module.exports = {
),
'./config/jest-before.js',
],
+ testEnvironment: 'jsdom',
testMatch: [
'**/__tests__/**/*.[jt]s',
'**/test/*.[jt]s',
- Run
yarn jest
Error:
FAIL blocks/layout-grid/src/__tests__/migrations.js
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/Users/<local-path>/block-experiments/node_modules/uuid/dist/esm-browser/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { default as v1 } from './v1.js';
^^^^^^
SyntaxError: Unexpected token 'export'
2 | * WordPress dependencies
3 | */
> 4 | import { parse, serialize, rawHandler } from '@wordpress/blocks';
| ^
5 | import { registerCoreBlocks } from '@wordpress/block-library';
6 |
7 | /**
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
at Object.<anonymous> (node_modules/@wordpress/blocks/build/api/@wordpress/blocks/src/api/factory.js:4:1)
at Object.<anonymous> (node_modules/@wordpress/blocks/build/api/@wordpress/blocks/src/api/utils.js:20:1)
at Object.<anonymous> (node_modules/@wordpress/blocks/build/store/@wordpress/blocks/src/store/reducer.js:15:1)
at Object.<anonymous> (node_modules/@wordpress/blocks/build/store/@wordpress/blocks/src/store/index.js:9:1)
at Object.<anonymous> (node_modules/@wordpress/blocks/build/@wordpress/blocks/src/index.js:11:1)
at Object.require (blocks/layout-grid/src/__tests__/migrations.js:4:1)
2 - Issue with package uuid
- Apply the following patch:
diff --git forkSrcPrefix/jest.config.js forkDstPrefix/jest.config.js
index 76cd5ec2e813f9b6d68a4ac6655d034eb7657b7f..2d5af5d1128c82ff454f67719e4fd03cdf334099 100644
--- forkSrcPrefix/jest.config.js
+++ forkDstPrefix/jest.config.js
@@ -12,6 +12,7 @@ module.exports = {
),
'./config/jest-before.js',
],
+ testEnvironment: 'jsdom',
testMatch: [
'**/__tests__/**/*.[jt]s',
'**/test/*.[jt]s',
@@ -24,5 +25,10 @@ module.exports = {
'^.+\\.[jt]sx?$': 'babel-jest',
'^.+\\.(css|scss)$': 'jest-transform-css',
'\\.(jpg|jpeg|png|gif|webp|svg)$': 'jest-transform-file',
- }
+ },
+ moduleNameMapper: {
+ // Workaround for Jest not having ESM support yet
+ // Reference: https://t.ly/9ap_
+ '^uuid$': require.resolve( 'uuid' ),
+ },
};
Error:
FAIL blocks/layout-grid/src/__tests__/migrations.js
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.
By default "node_modules" folder is ignored by transformers.
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
• If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/Users/fluiddot/workspace/gutenberg-mobile/block-experiments/node_modules/@wordpress/block-library/node_modules/is-plain-obj/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export default function isPlainObject(value) {
^^^^^^
SyntaxError: Unexpected token 'export'
3 | */
4 | import { parse, serialize, rawHandler } from '@wordpress/blocks';
> 5 | import { registerCoreBlocks } from '@wordpress/block-library';
| ^
6 |
7 | /**
8 | * Internal dependencies
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
at Object.<anonymous> (node_modules/@wordpress/block-library/node_modules/@wordpress/data/build/plugins/persistence/@wordpress/data/src/plugins/persistence/index.js:4:1)
at Object.<anonymous> (node_modules/@wordpress/block-library/node_modules/@wordpress/data/build/plugins/@wordpress/data/src/plugins/index.js:1:1)
at Object.<anonymous> (node_modules/@wordpress/block-library/node_modules/@wordpress/data/build/@wordpress/data/src/index.js:10:1)
at Object.<anonymous> (node_modules/@wordpress/block-library/node_modules/@wordpress/blocks/build/store/@wordpress/blocks/src/store/index.js:4:1)
at Object.<anonymous> (node_modules/@wordpress/block-library/node_modules/@wordpress/blocks/build/@wordpress/blocks/src/index.js:11:1)
at Object.<anonymous> (node_modules/@wordpress/block-library/build/@wordpress/block-library/src/index.js:4:1)
at Object.require (blocks/layout-grid/src/__tests__/migrations.js:5:1)
FAIL blocks/layout-grid/src/__tests__/invalidations.js
● Test suite failed to run
Cannot find module 'react-resize-aware' from 'node_modules/@wordpress/block-editor/node_modules/@wordpress/compose/build/hooks/use-resize-observer/index.js'
Require stack:
node_modules/@wordpress/block-editor/node_modules/@wordpress/compose/build/hooks/use-resize-observer/index.js
node_modules/@wordpress/block-editor/node_modules/@wordpress/compose/build/index.js
node_modules/@wordpress/block-editor/build/hooks/align.js
node_modules/@wordpress/block-editor/build/hooks/index.js
node_modules/@wordpress/block-editor/build/index.js
blocks/layout-grid/src/grid/edit.js
blocks/layout-grid/src/index.js
blocks/layout-grid/src/__tests__/invalidations.js
9 | */
10 |
> 11 | import {
| ^
12 | InnerBlocks,
13 | InspectorControls,
14 | BlockControls,
at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)
at Object.<anonymous> (node_modules/@wordpress/block-editor/node_modules/@wordpress/compose/build/hooks/use-resize-observer/@wordpress/compose/src/hooks/use-resize-observer/index.js:4:1)
at Object.<anonymous> (node_modules/@wordpress/block-editor/node_modules/@wordpress/compose/build/@wordpress/compose/src/index.js:32:1)
at Object.<anonymous> (node_modules/@wordpress/block-editor/build/hooks/@wordpress/block-editor/src/hooks/align.js:10:1)
at Object.<anonymous> (node_modules/@wordpress/block-editor/build/hooks/@wordpress/block-editor/src/hooks/index.js:5:1)
at Object.<anonymous> (node_modules/@wordpress/block-editor/build/@wordpress/block-editor/src/index.js:4:1)
at Object.require (blocks/layout-grid/src/grid/edit.js:11:1)
at Object.require (blocks/layout-grid/src/index.js:12:1)
at Object.require (blocks/layout-grid/src/__tests__/invalidations.js:9:1)
- 主要言語
- JavaScript
- スター
- 132
- フォーク
- 18
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Automattic/block-experiments のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
Automattic/block-experiments#343 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
Automattic/block-experiments#339 · コメント 4 件 ·
-
Grainy Gradientsオープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
Automattic/block-experiments#336 · コメント 1 件 ·
-
Bug
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
Automattic/block-experiments#331 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
Automattic/block-experiments#327 · コメント 1 件 ·
Automattic/block-experiments の issue をすべて見る
似ている issue
-
[Bug]: fileUploadMatrix.test.ts URL case does a real DNS lookup and fails offline対応中かも @r2jaff が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ComposioHQ/composio#5054 ·
メンテナーはふだん 1 日以内に返信
-
W3cオープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
web-platform-tests/wpt#64017 ·
メンテナーはふだん 1 日以内に返信
-
routine:ci-review
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
harlan-zw/unlighthouse#456 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
beginner enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
philaconvalley/website#217 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] xiaohongshu search_input_not_available on accounts with new AI-search layout (gray rollout)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信