Skip to content

Commit da225fe

Browse files
cpojerosdnk
authored andcommitted
Adjust React error messages to obfuscate imports
Summary: Similar to the previous diff in this stack, I'm adjusting the React files we use to make sure require and import statements don't get extracted by Jest. Right now Jest extracts them, and when it looks up dependencies in reverse it just ignores the ones that don't exist. Corresponding React PR (to make sure this change doesn't get reverted during the next sync): facebook/react#18222 Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D20282829 fbshipit-source-id: 5ff6a64d31672dd29243d020e8174797a44d9267
1 parent 276dce0 commit da225fe

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Libraries/Renderer/implementations/ReactFabric-dev.fb.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,7 +2787,7 @@ function initializeLazyComponentType(lazyComponent) {
27872787
error(
27882788
"lazy: Expected the result of a dynamic import() call. " +
27892789
"Instead received: %s\n\nYour code should look like: \n " +
2790-
"const MyComponent = lazy(() => import('./MyComponent'))",
2790+
"const MyComponent = lazy(() => imp" + "ort('./MyComponent'))",
27912791
moduleObject
27922792
);
27932793
}
@@ -21918,11 +21918,13 @@ function warnIfNotScopedWithMatchingAct(fiber) {
2191821918
"It looks like you're using the wrong act() around your test interactions.\n" +
2191921919
"Be sure to use the matching version of act() corresponding to your renderer:\n\n" +
2192021920
"// for react-dom:\n" +
21921-
"import {act} from 'react-dom/test-utils';\n" +
21921+
"import {act} fr" +
21922+
"om 'react-dom/test-utils';\n" +
2192221923
"// ...\n" +
2192321924
"act(() => ...);\n\n" +
2192421925
"// for react-test-renderer:\n" +
21925-
"import TestRenderer from 'react-test-renderer';\n" +
21926+
"import TestRenderer fr" +
21927+
"om react-test-renderer';\n" +
2192621928
"const {act} = TestRenderer;\n" +
2192721929
"// ...\n" +
2192821930
"act(() => ...);" +
@@ -22006,7 +22008,7 @@ function warnIfUnmockedScheduler(fiber) {
2200622008
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
2200722009
"to guarantee consistent behaviour across tests and browsers. " +
2200822010
"For example, with jest: \n" +
22009-
"jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" +
22011+
"jest.mock('scheduler', () => require" + "('scheduler/unstable_mock'));\n\n" +
2201022012
"For more info, visit https://fb.me/react-mock-scheduler"
2201122013
);
2201222014
} else if (warnAboutUnmockedScheduler === true) {
@@ -22016,7 +22018,7 @@ function warnIfUnmockedScheduler(fiber) {
2201622018
'Starting from React v17, the "scheduler" module will need to be mocked ' +
2201722019
"to guarantee consistent behaviour across tests and browsers. " +
2201822020
"For example, with jest: \n" +
22019-
"jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" +
22021+
"jest.mock('scheduler', () => require" + "('scheduler/unstable_mock'));\n\n" +
2202022022
"For more info, visit https://fb.me/react-mock-scheduler"
2202122023
);
2202222024
}

Libraries/Renderer/implementations/ReactNativeRenderer-dev.fb.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,7 +3090,7 @@ function initializeLazyComponentType(lazyComponent) {
30903090
error(
30913091
"lazy: Expected the result of a dynamic import() call. " +
30923092
"Instead received: %s\n\nYour code should look like: \n " +
3093-
"const MyComponent = lazy(() => import('./MyComponent'))",
3093+
"const MyComponent = lazy(() => imp" + "ort('./MyComponent'))",
30943094
moduleObject
30953095
);
30963096
}
@@ -22217,11 +22217,13 @@ function warnIfNotScopedWithMatchingAct(fiber) {
2221722217
"It looks like you're using the wrong act() around your test interactions.\n" +
2221822218
"Be sure to use the matching version of act() corresponding to your renderer:\n\n" +
2221922219
"// for react-dom:\n" +
22220-
"import {act} from 'react-dom/test-utils';\n" +
22220+
"import {act} fr" +
22221+
"om 'react-dom/test-utils';\n" +
2222122222
"// ...\n" +
2222222223
"act(() => ...);\n\n" +
2222322224
"// for react-test-renderer:\n" +
22224-
"import TestRenderer from 'react-test-renderer';\n" +
22225+
"import TestRenderer fr" +
22226+
"om 'react-test-renderer';\n" +
2222522227
"const {act} = TestRenderer;\n" +
2222622228
"// ...\n" +
2222722229
"act(() => ...);" +
@@ -22305,7 +22307,7 @@ function warnIfUnmockedScheduler(fiber) {
2230522307
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
2230622308
"to guarantee consistent behaviour across tests and browsers. " +
2230722309
"For example, with jest: \n" +
22308-
"jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" +
22310+
"jest.mock('scheduler', () => require" + "('scheduler/unstable_mock'));\n\n" +
2230922311
"For more info, visit https://fb.me/react-mock-scheduler"
2231022312
);
2231122313
} else if (warnAboutUnmockedScheduler === true) {
@@ -22315,7 +22317,7 @@ function warnIfUnmockedScheduler(fiber) {
2231522317
'Starting from React v17, the "scheduler" module will need to be mocked ' +
2231622318
"to guarantee consistent behaviour across tests and browsers. " +
2231722319
"For example, with jest: \n" +
22318-
"jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" +
22320+
"jest.mock('scheduler', () => require" + "('scheduler/unstable_mock'));\n\n" +
2231922321
"For more info, visit https://fb.me/react-mock-scheduler"
2232022322
);
2232122323
}

0 commit comments

Comments
 (0)