Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade jest from 26 to 29 #4686

Closed
wants to merge 1 commit into from
Closed

Upgrade jest from 26 to 29 #4686

wants to merge 1 commit into from

Conversation

necolas
Copy link
Contributor

@necolas necolas commented Apr 24, 2024

This PR upgrades jest from 26 to 29 and makes related changes. The unit tests pass; the console.error warnings seem to be pre-existing. Included some of them below.

GraphQL fragments wrapped in a thunk

"this is legacy behavior and to be removed in the future"

    console.error
      Warning: RelayGraphQLTag: node `GraphQLTagTest1Query` unexpectedly wrapped in a function.

      67 |   if (typeof node === 'function') {
      68 |     node = (node(): ReaderFragment | ConcreteRequest);
    > 69 |     warning(
         |             ^
      70 |       false,
      71 |       'RelayGraphQLTag: node `%s` unexpectedly wrapped in a function.',
      72 |       node.kind === 'Fragment' ? node.name : node.operation.name,

      at printWarning (node_modules/fbjs/lib/warning.js:30:13)
      at Object.<anonymous>.warning (node_modules/fbjs/lib/warning.js:51:18)
      at getNode (packages/relay-runtime/query/GraphQLTag.js:69:32)
      at Object.getRequest (packages/relay-runtime/query/GraphQLTag.js:156:17)
      at Object.<anonymous> (packages/relay-runtime/query/__tests__/GraphQLTag-test.js:71:37)

Errors in the test-only warnings module.

There were other problematic patterns in this code that I fixed (nesting afterEach within tests; doesn't play well with jest.resetModules).

    console.error
      Unexpected Warning: expected warning #1

      60 |     } else {
      61 |       // log to console in case the error gets swallowed somewhere
    > 62 |       originalConsoleError(`Unexpected ${typenameCap}: ` + message);
         |       ^
      63 |       throw new Error(`${typenameCap}: ` + message);
      64 |     }
      65 |   }

      at handleMessage (packages/relay-test-utils-internal/consoleErrorsAndWarnings.js:62:7)
      at packages/relay-test-utils-internal/warnings.js:29:11
      at packages/relay-test-utils-internal/__tests__/warnings-test.js:84:36
      at Object.expectMessageMany (packages/relay-test-utils-internal/consoleErrorsAndWarnings.js:116:18)
      at Object.expectToWarnMany (packages/relay-test-utils-internal/warnings.js:70:25)
      at packages/relay-test-utils-internal/__tests__/warnings-test.js:83:30
      at Object.<anonymous> (node_modules/expect/build/toThrowMatchers.js:74:11)
      at Object.throwingMatcher [as toThrowError] (node_modules/expect/build/index.js:320:21)
      at Object.<anonymous> (packages/relay-test-utils-internal/__tests__/warnings-test.js:87:8)

Other

   Warning: RelayResponseNormalizer: Payload did not contain a value for field `text: text`. Check that you are parsing with the same query that was used to fetch the payload.

      513 |           // to be present
      514 |           if (__DEV__) {
    > 515 |             warning(
          |                     ^
      516 |               false,
      517 |               'RelayResponseNormalizer: Payload did not contain a value ' +
      518 |                 'for field `%s: %s`. Check that you are parsing with the same ' +

Comment on lines +117 to +120
"fakeTimers": {
"enableGlobally": true,
"legacyFakeTimers": true
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retain legacy timer expectations.

Comment on lines +128 to +131
"snapshotFormat": {
"escapeString": true,
"printBasicPrototype": true
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retain legacy snapshot format.

Comment on lines +31 to +35
const {disallowWarnings, expectWarningWillFire} = (jest.requireActual(
'relay-test-utils-internal',
): $FlowFixMe);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid module getting reset when jest.resetModules is called somewhere in this test, otherwise expectWarningWillFire errors.

@@ -2491,7 +2490,6 @@ describe('useBlockingPaginationFragment', () => {
// the component twice: `expectFragmentResults` will fail in the next
// test
jest.resetModules();
disallowWarnings();
Copy link
Contributor Author

@necolas necolas Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot nest this function within a test, because it contains an internal call to afterEach. I'm assuming this was done because of the resetModules, but preventing the module from being reset avoids the issue without triggering the new error about nesting jest hooks

Comment on lines -117 to -118
disallowWarnings();
disallowConsoleErrors();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot nest afterEach within beforeEach

Comment on lines +655 to +657
setTimeout(() => {
resolve(markdownRendererNormalizationFragment);
});
}, 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only use of setImmediate in the tests. No test failures from this change - possibly there are console messages related to it but they were truncated in the test output.

@@ -10,6 +10,7 @@

'use strict';

global.IS_REACT_ACT_ENVIRONMENT = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed after upgrading jest

@@ -38,7 +38,7 @@ module.exports = {
filename: filename,
retainLines: true,
});
return babel.transform(src, options).code;
return babel.transform(src, options);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API changed between 26 and 29

const {
FIXTURE_TAG,
generateTestsFromFixtures,
} = require('./generateTestsFromFixtures');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module uses Node.js APIs. Better to isolate the utils that require a Node environment from those that don't. These helpers are only used in the Babel plugin tests.

@necolas
Copy link
Contributor Author

necolas commented Apr 24, 2024

Are the Rust CI failures unrelated? Locally all the Rust tests pass, but rustup wouldn't let me downgrade to 1.36 on M1 Mac, so it modified Cargo.lock and changed the formatting of every crate file.

@facebook-github-bot
Copy link
Contributor

@necolas has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@necolas
Copy link
Contributor Author

necolas commented May 3, 2024

Closed by 89fe7bc

@necolas necolas closed this May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants