question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ra-core causes @testing-library/react to be bundled in prod

See original GitHub issue

What you were expecting:

Production bundle of an app containing react-admin to not contain @testing-library/react and its dependencies.

What happened instead:

@testing-library/react was included in a production bundle. As a side-effect, IE11 broke due to pretty-format (a dependency of @testing-library/react) containing code that relies on Symbol, which is not available in IE11.

Steps to reproduce:

Unfortunately none at the moment as I cannot share the project and this doesn’t happen in a create-react-app project (which perhaps has a more sophisticated code elimination). Might be able to create a minimal test case later.

Related code:

I fixed this build by locally patching util/index.js at this point to not import and re-export renderWithRedux (which in turn depends on @testing-library/react).

Files needing renderWithRedux seem to be needed during dev only:

~/.../node_modules/ra-core$ ag 'import { renderWithRedux }'
src/i18n/useSetLocale.spec.js
9:import { renderWithRedux } from '../util';

src/i18n/useTranslate.spec.tsx
8:import { renderWithRedux } from '../util';

src/form/useChoices.spec.tsx
5:import { renderWithRedux } from '../util';

src/form/ValidationError.spec.tsx
8:import { renderWithRedux } from '../util';

src/controller/input/ReferenceArrayInputController.spec.tsx
5:import { renderWithRedux } from '../../util';

They could be fixed by having them import from ../util/renderWithRedux directly. Happy to provide a PR if that sounds sensible.

Also, @testing-library/react is reported in ra-core’s package.json dependencies instead of devDependencies.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
bardcommented, Apr 1, 2020

The smallest option would be:

modified   packages/ra-ui-materialui/src/input/CheckboxGroupInput.spec.tsx
@@ -3,267 +3,268 @@ import expect from 'expect';
 import CheckboxGroupInput from './CheckboxGroupInput';
 import { render, cleanup, fireEvent } from '@testing-library/react';
 import { Form } from 'react-final-form';
-import { renderWithRedux, TestTranslationProvider } from 'ra-core';
+import { TestTranslationProvider } from 'ra-core';
+import renderWithRedux from 'ra-core/src/util/renderWithRedux';

Though for consistency and clarity I guess I would do:

modified   packages/ra-ui-materialui/src/input/CheckboxGroupInput.spec.tsx
@@ -3,267 +3,267 @@ import expect from 'expect';
 import CheckboxGroupInput from './CheckboxGroupInput';
 import { render, cleanup, fireEvent } from '@testing-library/react';
 import { Form } from 'react-final-form';
-import { renderWithRedux, TestTranslationProvider } from 'ra-core';
+import { renderWithRedux, TestTranslationProvider } from 'ra-core/src/devUtils';
0reactions
fzaninottocommented, Feb 2, 2021

Fixed by #5846

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest error when testing React Component library bundled ...
So I'm pretty confident my problem is that since my React Component library isn't including React in the bundle any test with JSX...
Read more >
React Testing Library and the “not wrapped in act” Errors
I recently upgraded React and React testing library. ... In test, the code to render and update React components need to be included...
Read more >
How To Test Your React Apps With The React Testing Library
Fails caused by automated testing may lead to more bugs in production. In this article, we're going to show how React developers can...
Read more >
Setup - Testing Library
If you're running your tests in the browser bundled with webpack (or similar) then React Testing Library should work out of the box...
Read more >
React app testing: Jest and React Testing Library
Testing React Apps Jest React Testing Library ... we can run it and see what outputs. create-react-app makes it easy for us to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found