teambit / envs

Component development environments for the Bit community
https://bit.dev/bit/envs
Other
63 stars 9 forks source link

Tests fail when run with other components, pass when run independently #82

Open rapowell9 opened 4 years ago

rapowell9 commented 4 years ago

Describe the bug

I have a few small react components, some of them with test cases. When the I use the bit test and individually pass each id in, they all pass. However, if I try to tag or test them all at once, some of the tests will fail. The failing tests throw a react-test-renderer error, see below, suggesting a problem with the imports. The conflict seems to be caused by the fact that the test file uses a default import to import the component, while another component imports the component with an import { _component_ } from statement, again, see below.

Steps to Reproduce

  1. Download TestingError.zip, extract the files and open the TEST directory TestingError.zip

  2. In the TEST directory, run bit init and bit import -t bit.envs/testers/jest.

  3. The compiler has a rawConfig setting in the package.json. If you import the compiler(v3.1.39) with bit import -c bit.envs/compilers/react-typescript, this configuration will be overwritten and the build will fail, so be sure to restore the configuration after importing. Alternatively, running bit test appears to automatically import the compiler(v3.1.31) without overriding the configuration, but the build will initially fail. However, running it again will work as described below.

  4. There are 3 components: box, label, and bar. Run bit test box, the tests will all pass.

  5. Run either bit test or bit tag, and the tests for box will fail

Expected Behavior

The tests should have the same results whether they are run independently or as a group.

Screenshots, exceptions and logs

Test fails with this error: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Import from test file: import Box from "../src/components/box"

Import from other component: import {Box, IBoxProps} from './box'

Component exports: export interface IBoxProps {...} export class Box extends React.Component<IBoxProps, {}> {...} export default Box

Specifications

EDIT: Realized my package.json had a different compiler version than I listed. Updated to reflect that, but the issue occurs with both versions

GiladShoham commented 4 years ago

Thanks @rapowell9 for reporting this. We just start re-write the jest tester from scratch since it's pretty buggy right now. We will release a new version soon which will be much more stable. We will take this bug into account as well. @JoshK2 FYI. @davidfirst please take a look, I'm not sure it's jest bug, it might be bit's bug.