From aeb17a21e66e4311d7b401ece9df82a445167187 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 24 Mar 2022 14:51:58 +0100 Subject: [PATCH] cli: update Jest 27 changeset + make node env default Signed-off-by: Patrik Oldsberg --- .changeset/twelve-buses-nail.md | 6 ++++-- .github/styles/vocab.txt | 1 + packages/cli/config/jest.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.changeset/twelve-buses-nail.md b/.changeset/twelve-buses-nail.md index 24dd6bbb0b..ddeb7f1413 100644 --- a/.changeset/twelve-buses-nail.md +++ b/.changeset/twelve-buses-nail.md @@ -2,6 +2,8 @@ '@backstage/cli': minor --- -Bump the version range of `jest` from `^26.0.1` to `^27.4.7`. You can find the complete list of breaking changes [here](https://github.com/facebook/jest/releases/tag/v27.0.0). +**BREAKING**: Bump the version range of `jest` from `^26.0.1` to `^27.5.1`. You can find the complete list of breaking changes [here](https://github.com/facebook/jest/releases/tag/v27.0.0). -One of the main breaking changes in Jest 27 is that the default test environment is now `node` rather than `jsdom`. However, this is counteracted in the default Jest configuration provided by the Backstage CLI, as it still defaults the environment to `jsdom`. The future addition of the Backstage package `"role"` field will override this default, setting the test environment to the appropriate value for the role. +We strongly recommend to have completed the [package role migration](https://backstage.io/docs/tutorials/package-role-migration) before upgrading to this version, as the package roles are used to automatically determine the testing environment for each package. If you instead want to set an explicit test environment for each package, you can do so for example in the `"jest"` section in `package.json`. The default test environment for all packages is now `node`, which is also the new Jest default. + +Note that one of the breaking changes of Jest 27 is that the `jsdom` environment no longer includes `setImmediate` and `clearImmediate`, which means you might need to update some of your frontend packages. Another notable change is that `jest.useFakeTimers` now defaults to the `'modern'` implementation, which also mocks microtasks. diff --git a/.github/styles/vocab.txt b/.github/styles/vocab.txt index 3910caccc6..c9382b1fd0 100644 --- a/.github/styles/vocab.txt +++ b/.github/styles/vocab.txt @@ -170,6 +170,7 @@ memoized microservice microservices microsite +microtasks middleware minikube Minikube diff --git a/packages/cli/config/jest.js b/packages/cli/config/jest.js index 6618790a72..6b9201559b 100644 --- a/packages/cli/config/jest.js +++ b/packages/cli/config/jest.js @@ -44,13 +44,13 @@ function getRoleConfig(role) { case 'common-library': case 'frontend-plugin': case 'frontend-plugin-module': - default: return { testEnvironment: 'jsdom' }; case 'cli': case 'backend': case 'node-library': case 'backend-plugin': case 'backend-plugin-module': + default: return { testEnvironment: 'node' }; } }