Skip to content

Commit

Permalink
Upgrade jest from 26 to 29
Browse files Browse the repository at this point in the history
Reviewed By: monicatang

Differential Revision: D56591808

fbshipit-source-id: 2b77c4b8893cdb83dda160d00d4aa6a5b4d2c79e
  • Loading branch information
necolas authored and facebook-github-bot committed Apr 30, 2024
1 parent 08e4794 commit 89fe7bc
Show file tree
Hide file tree
Showing 17 changed files with 1,043 additions and 1,286 deletions.
9 changes: 5 additions & 4 deletions .github/CONTRIBUTING.md
Expand Up @@ -33,10 +33,11 @@ For JavaScript changes:

For Rust changes:

1. Ensure all rust code is formatted by running `cargo fmt` from within `./compiler`.
2. If you've added or removed any fixture tests, ensure all generated tests are up to date by running `./scripts/update-fixtures.sh` from the repository root.
3. Ensure all code typechecks by running `cargo check` from within `./compiler`.
4. Ensure all tests pass by running `cargo test` from within `./compiler`.
1. [Install Rust and Cargo](https://www.rust-lang.org/tools/install)
2. Ensure all rust code is formatted by running `cargo fmt` from within `./compiler`.
3. If you've added or removed any fixture tests, ensure all generated tests are up to date by running `./scripts/update-fixtures.sh` from the repository root.
4. Ensure all code typechecks by running `cargo check` from within `./compiler`.
5. Ensure all tests pass by running `cargo test` from within `./compiler`.

### Contributor License Agreement (CLA)

Expand Down
19 changes: 14 additions & 5 deletions package.json
Expand Up @@ -36,7 +36,7 @@
"@babel/runtime": "^7.0.0",
"@babel/traverse": "^7.14.0",
"@babel/types": "^7.0.0",
"@jest/create-cache-key-function": "^26.6.2",
"@jest/create-cache-key-function": "^29.7.0",
"babel-eslint": "^10.1.0",
"babel-plugin-macros": "^2.0.0",
"babel-plugin-syntax-hermes-parser": "0.20.1",
Expand Down Expand Up @@ -69,7 +69,7 @@
"gulp-util": "3.0.8",
"hermes-eslint": "0.20.1",
"invariant": "^2.2.4",
"jest": "^26.6.3",
"jest": "^29.7.0",
"nullthrows": "^1.1.1",
"prettier": "2.8.8",
"prettier-plugin-hermes-parser": "0.20.1",
Expand Down Expand Up @@ -98,7 +98,9 @@
"parser": "hermes"
},
"jest": {
"testRegex": "/__tests__/.*-test\\.js$",
"testMatch": [
"<rootDir>/packages/**/__tests__/**/*-test.js"
],
"modulePathIgnorePatterns": [
"<rootDir>/lib/",
"<rootDir>/node_modules/(?!(fbjs/lib/|react/lib/))",
Expand All @@ -112,14 +114,21 @@
"setupFiles": [
"<rootDir>/scripts/jest/environment.js"
],
"timers": "fake",
"fakeTimers": {
"enableGlobally": true,
"legacyFakeTimers": true
},
"transform": {
".*": "<rootDir>/scripts/jest/preprocessor.js"
},
"transformIgnorePatterns": [
"<rootDir>/node_modules/"
],
"testEnvironment": "node"
"testEnvironment": "node",
"snapshotFormat": {
"escapeString": true,
"printBasicPrototype": true
}
},
"devDependencies": {}
}
Expand Up @@ -11,7 +11,7 @@
'use strict';

const transformerWithOptions = require('./transformerWithOptions');
const {generateTestsFromFixtures} = require('relay-test-utils-internal');
const {generateTestsFromFixtures} = require('relay-test-utils-internal/node');

generateTestsFromFixtures(
`${__dirname}/fixtures`,
Expand Down
Expand Up @@ -11,7 +11,7 @@
'use strict';

const transformerWithOptions = require('./transformerWithOptions');
const {generateTestsFromFixtures} = require('relay-test-utils-internal');
const {generateTestsFromFixtures} = require('relay-test-utils-internal/node');

generateTestsFromFixtures(
`${__dirname}/fixtures`,
Expand Down
Expand Up @@ -11,6 +11,6 @@
'use strict';

const transformerWithOptions = require('./transformerWithOptions');
const {generateTestsFromFixtures} = require('relay-test-utils-internal');
const {generateTestsFromFixtures} = require('relay-test-utils-internal/node');

generateTestsFromFixtures(`${__dirname}/fixtures`, transformerWithOptions({}));
Expand Up @@ -28,12 +28,12 @@ const {
graphql,
} = require('relay-runtime');
const {createMockEnvironment} = require('relay-test-utils');
const {
disallowWarnings,
expectWarningWillFire,
} = require('relay-test-utils-internal');
const Scheduler = require('scheduler');

const {disallowWarnings, expectWarningWillFire} = (jest.requireActual(
'relay-test-utils-internal',
): $FlowFixMe);

const {useMemo, useState} = React;

disallowWarnings();
Expand Down Expand Up @@ -2491,7 +2491,6 @@ describe('useBlockingPaginationFragment', () => {
// the component twice: `expectFragmentResults` will fail in the next
// test
jest.resetModules();
disallowWarnings();
});

it('preserves pagination request if re-rendered with same fragment ref', () => {
Expand Down
Expand Up @@ -47,7 +47,7 @@ const {
disallowWarnings,
expectToWarn,
expectWarningWillFire,
} = require('relay-test-utils-internal');
} = (jest.requireActual('relay-test-utils-internal'): $FlowFixMe);

const defaultFetchPolicy = 'network-only';

Expand Down Expand Up @@ -112,10 +112,11 @@ let logs: Array<LogEvent>;
let errorBoundaryDidCatchFn;
let useFragmentImpl: typeof useFragment;

disallowWarnings();
disallowConsoleErrors();

beforeEach(() => {
jest.resetModules();
disallowWarnings();
disallowConsoleErrors();

useFragmentImpl = useFragment;

Expand Down
Expand Up @@ -652,9 +652,9 @@ describe.each(['RelayModernEnvironment', 'MultiActorEnvironment'])(
it('optimistically creates @match fields and loads resources', () => {
operationLoader.load.mockImplementationOnce(() => {
return new Promise(resolve => {
setImmediate(() => {
setTimeout(() => {
resolve(markdownRendererNormalizationFragment);
});
}, 0);
});
});
environment
Expand Down
Expand Up @@ -68,6 +68,7 @@ function createConsoleInterceptionSystem(
if (installed) {
throw new Error(`${installerName} should be called only once.`);
}

installed = true;
setUpMock(handleMessage);

Expand Down
18 changes: 18 additions & 0 deletions packages/relay-test-utils-internal/fixtureTag.js
@@ -0,0 +1,18 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @oncall relay
*/

'use strict';

const FIXTURE_TAG = Symbol.for('FIXTURE_TAG');

/**
* The public interface to Relay Test Utils.
*/
module.exports = FIXTURE_TAG;
Expand Up @@ -10,6 +10,7 @@

'use strict';

const FIXTURE_TAG = require('./fixtureTag');
const getOutputForFixture = require('./getOutputForFixture');
const fs = require('fs');
const path = require('path');
Expand All @@ -20,9 +21,8 @@ const path = require('path');
* Extend Jest with a custom snapshot serializer to provide additional context
* and reduce the amount of escaping that occurs.
*/
const FIXTURE_TAG = Symbol.for('FIXTURE_TAG');
expect.addSnapshotSerializer({
print(value) {
serialize(value) {
return Object.keys(value)
.map(key => `~~~~~~~~~~ ${key.toUpperCase()} ~~~~~~~~~~\n${value[key]}`)
.join('\n');
Expand Down
6 changes: 0 additions & 6 deletions packages/relay-test-utils-internal/index.js
Expand Up @@ -24,10 +24,6 @@ const {
expectConsoleWarningWillFire,
} = require('./consoleWarning');
const describeWithFeatureFlags = require('./describeWithFeatureFlags');
const {
FIXTURE_TAG,
generateTestsFromFixtures,
} = require('./generateTestsFromFixtures');
const Matchers = require('./Matchers');
const printAST = require('./printAST');
const simpleClone = require('./simpleClone');
Expand Down Expand Up @@ -75,8 +71,6 @@ module.exports = {
expectToWarn,
expectToWarnMany,
expectWarningWillFire,
FIXTURE_TAG,
generateTestsFromFixtures,
matchers: Matchers,
printAST,
simpleClone,
Expand Down
25 changes: 25 additions & 0 deletions packages/relay-test-utils-internal/node.js
@@ -0,0 +1,25 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
* @oncall relay
*/

'use strict';

const {
FIXTURE_TAG,
generateTestsFromFixtures,
} = require('./generateTestsFromFixtures');

/**
* The public interface to Relay Test Utils.
*/
module.exports = {
FIXTURE_TAG,
generateTestsFromFixtures,
};
Expand Up @@ -16,7 +16,7 @@ import type {Query, Variables} from 'relay-runtime';

const RelayMockPayloadGenerator = require('../RelayMockPayloadGenerator');
const {createOperationDescriptor, graphql} = require('relay-runtime');
const {FIXTURE_TAG} = require('relay-test-utils-internal');
const {FIXTURE_TAG} = require('relay-test-utils-internal/node');

function testGeneratedData<TVariables: Variables, TData, TRawResponse>(
query: Query<TVariables, TData, TRawResponse>,
Expand Down
1 change: 1 addition & 0 deletions scripts/jest/environment.js
Expand Up @@ -10,6 +10,7 @@

'use strict';

global.IS_REACT_ACT_ENVIRONMENT = true;
global.__DEV__ = true;

require('@babel/runtime/regenerator');
2 changes: 1 addition & 1 deletion scripts/jest/preprocessor.js
Expand Up @@ -38,7 +38,7 @@ module.exports = {
filename: filename,
retainLines: true,
});
return babel.transform(src, options).code;
return babel.transform(src, options);
},

getCacheKey: createCacheKeyFunction([
Expand Down

0 comments on commit 89fe7bc

Please sign in to comment.