Skip to content

Commit

Permalink
Break up require/import statements in strings (#18222)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer committed Mar 5, 2020
1 parent 024a764 commit 4027f2a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 12 additions & 4 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2937,11 +2937,15 @@ export function warnIfNotScopedWithMatchingAct(fiber: Fiber): void {
"It looks like you're using the wrong act() around your test interactions.\n" +
'Be sure to use the matching version of act() corresponding to your renderer:\n\n' +
'// for react-dom:\n' +
"import {act} from 'react-dom/test-utils';\n" +
// Break up imports to avoid accidentally parsing them as dependencies.
'import {act} fr' +
"om 'react-dom/test-utils';\n" +
'// ...\n' +
'act(() => ...);\n\n' +
'// for react-test-renderer:\n' +
"import TestRenderer from 'react-test-renderer';\n" +
// Break up imports to avoid accidentally parsing them as dependencies.
'import TestRenderer fr' +
"om react-test-renderer';\n" +
'const {act} = TestRenderer;\n' +
'// ...\n' +
'act(() => ...);' +
Expand Down Expand Up @@ -3027,7 +3031,9 @@ export function warnIfUnmockedScheduler(fiber: Fiber) {
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
'to guarantee consistent behaviour across tests and browsers. ' +
'For example, with jest: \n' +
"jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" +
// Break up requires to avoid accidentally parsing them as dependencies.
"jest.mock('scheduler', () => require" +
"('scheduler/unstable_mock'));\n\n" +
'For more info, visit https://fb.me/react-mock-scheduler',
);
} else if (warnAboutUnmockedScheduler === true) {
Expand All @@ -3036,7 +3042,9 @@ export function warnIfUnmockedScheduler(fiber: Fiber) {
'Starting from React v17, the "scheduler" module will need to be mocked ' +
'to guarantee consistent behaviour across tests and browsers. ' +
'For example, with jest: \n' +
"jest.mock('scheduler', () => require('scheduler/unstable_mock'));\n\n" +
// Break up requires to avoid accidentally parsing them as dependencies.
"jest.mock('scheduler', () => require" +
"('scheduler/unstable_mock'));\n\n" +
'For more info, visit https://fb.me/react-mock-scheduler',
);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/shared/ReactLazyComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export function initializeLazyComponentType(
console.error(
'lazy: Expected the result of a dynamic import() call. ' +
'Instead received: %s\n\nYour code should look like: \n ' +
"const MyComponent = lazy(() => import('./MyComponent'))",
// Break up imports to avoid accidentally parsing them as dependencies.
'const MyComponent = lazy(() => imp' +
"ort('./MyComponent'))",
moduleObject,
);
}
Expand Down

0 comments on commit 4027f2a

Please sign in to comment.