@wordpress/jest-preset-default 7.1.1 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 8.0.0 (2022-01-27)
6
+
7
+ ### Breaking Changes
8
+
9
+ - The peer `jest` dependency has been updated from requiring `>=26` to requiring `>=27` (see [Breaking Changes](https://jestjs.io/blog/2021/05/25/jest-27), [#33287](https://github.com/WordPress/gutenberg/pull/33287)).
10
+
11
+ ### Bug Fixes
12
+
13
+ - Allow ESLint to be imported from within Jest (e.g. when using `ruleTester`) ([#36283](https://github.com/WordPress/gutenberg/pull/36283)).
14
+ - Improve support for test files with `.jsx` and `.tsx` extensions ([#36260](https://github.com/WordPress/gutenberg/pull/36260)).
15
+
16
+ ## 7.1.2 (2021-10-22)
17
+
18
+ ### Bug Fix
19
+
20
+ - Provide more complete mocks of browser timing functions. ([#35368](https://github.com/WordPress/gutenberg/pull/35368))
21
+
5
22
  ## 7.1.1 (2021-09-09)
6
23
 
7
24
  ### Bug Fix
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## Gutenberg
2
2
 
3
- Copyright 2016-2021 by the contributors
3
+ Copyright 2016-2022 by the contributors
4
4
 
5
5
  **License for Contributions (on and after April 15, 2021)**
6
6
 
package/README.md CHANGED
@@ -31,7 +31,7 @@ npm install @wordpress/jest-preset-default --save-dev
31
31
  - `setupFiles` - runs code before each test which sets up global variables required in the testing environment.
32
32
  - `setupFilesAfterEnv` - runs code which adds improved support for `Console` object and `React` components to the testing framework before each test.
33
33
  - `snapshotSerializers` - makes it possible to use snapshot tests on `Enzyme` wrappers.
34
- - `testMatch`- includes `/test/` subfolder in addition to the glob patterns Jest uses to detect test files. It detects only test files containing `.js` (or `.ts`) suffix. It doesn't match files with `.spec.js` suffix.
34
+ - `testMatch`- includes `/test/` subfolder in addition to the glob patterns Jest uses to detect test files. It detects only test files containing `.js`, `.jsx`, `.ts` and `.tsx` suffix. It doesn't match files with `.spec.js` suffix.
35
35
  - `timers` - use of [fake timers](https://jestjs.io/docs/en/timer-mocks.html) for functions such as `setTimeout` is enabled.
36
36
  - `transform` - keeps the default [babel-jest](https://github.com/facebook/jest/tree/HEAD/packages/babel-jest) transformer.
37
37
  - `verbose` - each individual test won't be reported during the run.
package/jest-preset.js CHANGED
@@ -3,6 +3,8 @@ module.exports = {
3
3
  '\\.(scss|css)$': require.resolve(
4
4
  '@wordpress/jest-preset-default/scripts/style-mock.js'
5
5
  ),
6
+ // See https://github.com/facebook/jest/issues/11100#issuecomment-967161978
7
+ '@eslint/eslintrc': '@eslint/eslintrc/dist/eslintrc-universal.cjs',
6
8
  },
7
9
  modulePaths: [ '<rootDir>' ],
8
10
  setupFiles: [
@@ -16,14 +18,15 @@ module.exports = {
16
18
  ),
17
19
  ],
18
20
  snapshotSerializers: [ require.resolve( 'enzyme-to-json/serializer.js' ) ],
21
+ testEnvironment: 'jsdom',
19
22
  testMatch: [
20
- '**/__tests__/**/*.[jt]s',
21
- '**/test/*.[jt]s',
22
- '**/?(*.)test.[jt]s',
23
+ '**/__tests__/**/*.[jt]s?(x)',
24
+ '**/test/*.[jt]s?(x)',
25
+ '**/?(*.)test.[jt]s?(x)',
23
26
  ],
24
27
  testPathIgnorePatterns: [ '/node_modules/', '<rootDir>/vendor/' ],
25
28
  timers: 'fake',
26
29
  transform: {
27
- '^.+\\.[jt]sx?$': require.resolve( 'babel-jest' ),
30
+ '\\.[jt]sx?$': require.resolve( 'babel-jest' ),
28
31
  },
29
32
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/jest-preset-default",
3
- "version": "7.1.1",
3
+ "version": "8.0.0",
4
4
  "description": "Default Jest preset for WordPress development.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -32,16 +32,19 @@
32
32
  "main": "index.js",
33
33
  "dependencies": {
34
34
  "@wojtekmaj/enzyme-adapter-react-17": "^0.6.1",
35
- "@wordpress/jest-console": "^4.1.0",
36
- "babel-jest": "^26.6.3",
35
+ "@wordpress/jest-console": "^5.0.0",
36
+ "babel-jest": "^27.4.5",
37
37
  "enzyme": "^3.11.0",
38
38
  "enzyme-to-json": "^3.4.4"
39
39
  },
40
40
  "peerDependencies": {
41
- "jest": ">=26"
41
+ "@babel/core": ">=7",
42
+ "jest": ">=27",
43
+ "react": "^17.0.0",
44
+ "react-dom": "^17.0.0"
42
45
  },
43
46
  "publishConfig": {
44
47
  "access": "public"
45
48
  },
46
- "gitHead": "98c42a7187f788fe3e023f04df7f5dcbdae4e4e7"
49
+ "gitHead": "d95ccb9366e249133cdb1d7b25c382446b9ee502"
47
50
  }
@@ -5,8 +5,42 @@ global.window.tinyMCEPreInit = {
5
5
  // <script> tag where it was loaded from, which of course fails here.
6
6
  baseURL: 'about:blank',
7
7
  };
8
- global.window.requestAnimationFrame = setTimeout;
9
- global.window.cancelAnimationFrame = clearTimeout;
8
+
9
+ global.window.setImmediate = function ( callback ) {
10
+ return setTimeout( callback, 0 );
11
+ };
12
+
13
+ global.window.requestAnimationFrame = function requestAnimationFrame(
14
+ callback
15
+ ) {
16
+ // eslint-disable-next-line no-restricted-syntax
17
+ const randomDelay = Math.round( ( Math.random() * 1_000 ) / 60 );
18
+
19
+ return setTimeout( () => callback( Date.now() ), randomDelay );
20
+ };
21
+
22
+ global.window.cancelAnimationFrame = function cancelAnimationFrame( handle ) {
23
+ return clearTimeout( handle );
24
+ };
25
+
26
+ // Ignoring `options` argument since we unconditionally schedule this ASAP
27
+ global.window.requestIdleCallback = function requestIdleCallback( callback ) {
28
+ const start = Date.now();
29
+
30
+ return setTimeout(
31
+ () =>
32
+ callback( {
33
+ didTimeout: false,
34
+ timeRemaining: () => Math.max( 0, 50 - ( Date.now() - start ) ),
35
+ } ),
36
+ 0
37
+ );
38
+ };
39
+
40
+ global.window.cancelIdleCallback = function cancelIdleCallback( handle ) {
41
+ return clearTimeout( handle );
42
+ };
43
+
10
44
  global.window.matchMedia = () => ( {
11
45
  matches: false,
12
46
  addListener: () => {},