Skip to content

Commit

Permalink
Use Jest version 27.0.1
Browse files Browse the repository at this point in the history
See release notes: https://jestjs.io/blog/2021/05/25/jest-27

There is currently one issue with global `afterEach` callbacks order which I workarounded by using `afterAll` (see: jestjs/jest#11456). I will wait for the resolution of that issue and update our code accordingly.
  • Loading branch information
mrtnzlml authored and kodiakhq[bot] committed May 26, 2021
1 parent adc8bdf commit 154daeb
Show file tree
Hide file tree
Showing 33 changed files with 804 additions and 529 deletions.
3 changes: 2 additions & 1 deletion .jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const commonProjectConfig = {
transform: {
'^.+\\.js$': 'babel-jest',
},
timers: 'fake',
timers: 'legacy', // TODO: migrate to the Jest default values!
};

function tryToLoadWorkspaceConfig(configPath /*: string */) /*: Object */ {
Expand All @@ -45,6 +45,7 @@ module.exports = {
reporters: ['default'],
rootDir: __dirname,
verbose: false,
testEnvironment: 'node',
setupFilesAfterEnv: commonProjectConfig.setupFilesAfterEnv, // specified here so it triggers all tests to run if changed.
projects: Workspaces.getWorkspacesSync().map((packageJSONLocation) => {
const packageJSON = require(packageJSONLocation);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"@babel/cli": "^7.14.3",
"@babel/core": "^7.14.3",
"@babel/eslint-parser": "^7.14.3",
"babel-jest": "^26.6.3",
"babel-jest": "^27.0.1",
"babel-loader": "^8.2.2",
"eslint": "^7.27.0",
"flow-bin": "^0.151.0",
"glob": "^7.1.7",
"jest": "^26.6.3",
"jest": "^27.0.1",
"jest-runner-eslint": "^0.10.0"
},
"jest": {
Expand Down
7 changes: 5 additions & 2 deletions scripts/jest/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const isSpy = (spy: MaybeSpy): boolean %checks => {
};

// TODO: .toWarnDev() ?
// Inspired by React itself: https://github.com/facebook/react/blob/7841d0695ae4bde9848cf8953baf34d312d0cced/scripts/jest/setupTests.js
['error', 'warn', 'log', 'info', 'groupCollapsed'].forEach((methodName) => {
const unexpectedConsoleCallStacks = [];
const newMethod = function (format, ...args) {
Expand All @@ -60,11 +61,13 @@ const isSpy = (spy: MaybeSpy): boolean %checks => {
// $FlowExpectedError[cannot-write]: these properties are not normally writable but it's expected in this case
console[methodName] = newMethod;

global.beforeEach(() => {
// TODO: which back to beforeEach, see https://github.com/facebook/jest/issues/11456
global.beforeAll(() => {
unexpectedConsoleCallStacks.length = 0;
});

global.afterEach(() => {
// TODO: which back to afterEach, see https://github.com/facebook/jest/issues/11456
global.afterAll(() => {
if (console[methodName] !== newMethod && !isSpy(console[methodName])) {
throw new Error(
`Test did not tear down console.${methodName} mock properly. Did you call spy.mockRestore() or jest.restoreAllMocks()?`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import * as React from 'react';
import fbt from 'fbt';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import * as React from 'react';
import fbt from 'fbt';
Expand Down
5 changes: 4 additions & 1 deletion src/abacus-backoffice/src/forms/__tests__/FormNumber.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import * as React from 'react';
import fbt from 'fbt';
Expand Down
5 changes: 4 additions & 1 deletion src/abacus-backoffice/src/forms/__tests__/FormText.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import * as React from 'react';
import fbt from 'fbt';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import * as React from 'react';
import fbt from 'fbt';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import { renderHook, act } from '@testing-library/react-hooks';
import { RecoilRoot } from 'recoil';
Expand Down
2 changes: 1 addition & 1 deletion src/eslint-fixtures-tester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@babel/eslint-parser": "^7.14.3",
"@babel/runtime": "^7.14.0",
"eslint": "^7.27.0",
"jest-docblock": "^26.0.0"
"jest-docblock": "^27.0.1"
},
"peerDependencies": {
"eslint": "^7.27.0"
Expand Down
4 changes: 2 additions & 2 deletions src/example-relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"@adeira/babel-preset-adeira": "^3.0.0",
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.7",
"babel-jest": "^26.6.3",
"babel-jest": "^27.0.1",
"flow-bin": "^0.151.0",
"graphql": "^15.5.0",
"jest": "^26.6.3",
"jest": "^27.0.1",
"react-test-renderer": "^17.0.2",
"relay-test-utils": "^11.0.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/example-relay/scripts/jest/custom-transformer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

const path = require('path');
const babelJest = require('babel-jest');
const babelJest = require('babel-jest').default; // https://github.com/facebook/jest/issues/11444

module.exports = (babelJest.createTransformer(
require(path.join(__dirname, '..', '..', '.babelrc.js')),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import { createMockEnvironment, MockPayloadGenerator } from 'relay-test-utils';
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
Expand Down
3 changes: 2 additions & 1 deletion src/fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"cross-fetch": "^3.1.4"
},
"devDependencies": {
"@sinonjs/fake-timers": "^7.1.0"
"@sinonjs/fake-timers": "^7.1.0",
"form-data": "^4.0.0"
}
}
2 changes: 2 additions & 0 deletions src/fetch/src/__tests__/fetchWithRetries.FormData.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @flow

import FormData from 'form-data';

import fetch from '../fetch';
import fetchWithRetries from '../fetchWithRetries';
import flushPromises from './_flushPromises';
Expand Down
4 changes: 2 additions & 2 deletions src/js/src/__tests__/isBrowser.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
* @flow strict
* @jest-environment jsdom
*/
// @flow strict

import isBrowser from '../isBrowser';

Expand Down
5 changes: 4 additions & 1 deletion src/relay/src/__tests__/helpers.getRequestBody.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import { getRequestBody } from '../helpers';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import * as React from 'react';
import { render, fireEvent } from '@testing-library/react';
Expand Down
5 changes: 4 additions & 1 deletion src/sx-design/src/Heading/__tests__/Heading.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import * as React from 'react';
import { render } from '@testing-library/react';
Expand Down
5 changes: 4 additions & 1 deletion src/sx-design/src/Image/__tests__/Image.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import React from 'react';
import { render } from '@testing-library/react';
Expand Down
9 changes: 6 additions & 3 deletions src/sx-design/src/Kbd/__tests__/Kbd.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import * as deviceDetect from 'react-device-detect';
import * as React from 'react';
import { invariant } from '@adeira/js';
import { render } from '@testing-library/react';
Expand All @@ -19,8 +21,9 @@ test.each`
let Kbd;
jest.isolateModules(() => {
// https://github.com/duskload/react-device-detect/blob/161b62d7f46a5b810b7a5677985e340f93468e32/README.md#testing
// eslint-disable-next-line no-import-assign
const deviceDetect = require('react-device-detect');
deviceDetect.isMacOs = isMacOs;

Kbd = require('../Kbd').default;
});

Expand Down
5 changes: 4 additions & 1 deletion src/sx-design/src/Link/__tests__/Link.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import { render } from '@testing-library/react';
import React from 'react';
Expand Down
5 changes: 4 additions & 1 deletion src/sx-design/src/Money/__tests__/Money.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import * as React from 'react';
import { render } from '@testing-library/react';
Expand Down
5 changes: 4 additions & 1 deletion src/sx-design/src/Note/__tests__/Note.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import { render } from '@testing-library/react';
import React from 'react';
Expand Down
5 changes: 4 additions & 1 deletion src/sx-design/src/ProductCard/__tests__/ProductCard.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import { render } from '@testing-library/react';
import React from 'react';
Expand Down
5 changes: 4 additions & 1 deletion src/sx-jest-snapshot-serializer/__tests__/serializer.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

import sx from '@adeira/sx';
import TestRenderer from 'react-test-renderer';
Expand Down
5 changes: 3 additions & 2 deletions src/sx-jest-snapshot-serializer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { __internal as __sxInternal } from '@adeira/sx';
import prettier from 'prettier';
import prettyFormat from 'pretty-format';
import { format as prettyFormat, plugins } from 'pretty-format';

/* global window */

Expand All @@ -20,9 +20,10 @@ expect.addSnapshotSerializer({
{ parser: 'css' },
);

const { DOMElement, ReactTestComponent } = plugins;
const printedHTML = prettier.format(
prettyFormat(val, {
plugins: [prettyFormat.plugins.DOMElement, prettyFormat.plugins.ReactTestComponent],
plugins: [DOMElement, ReactTestComponent],
printFunctionName: false,
}),
{ parser: 'html' },
Expand Down
2 changes: 1 addition & 1 deletion src/sx-jest-snapshot-serializer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@adeira/sx": "^0.25.0",
"@babel/runtime": "^7.14.0",
"prettier": "^2.3.0",
"pretty-format": "^26.6.2"
"pretty-format": "^27.0.1"
},
"devDependencies": {
"@testing-library/react": "^11.2.7",
Expand Down
5 changes: 4 additions & 1 deletion src/sx/src/__tests__/SxDomTests.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

/* global document */

Expand Down
5 changes: 4 additions & 1 deletion src/sx/src/__tests__/autoprefixRuntimeStyles.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

/* global document */

Expand Down
5 changes: 4 additions & 1 deletion src/sx/src/__tests__/composability.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

/* global document */

Expand Down
5 changes: 4 additions & 1 deletion src/sx/src/__tests__/injectRuntimeStyles.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @flow
/**
* @flow
* @jest-environment jsdom
*/

/* global document */

Expand Down
Loading

0 comments on commit 154daeb

Please sign in to comment.