Тестовый компонент React не работает в CircleCi и успешно работает локально - PullRequest
0 голосов
/ 06 мая 2020
• 1000 *

"FAIL src / App.test.jsx ● Не удалось запустить набор тестов

Cannot find module './containers/signup_signin/signupsignin' from 'App.jsx'

However, Jest was able to find:
  './App.jsx'
  './App.test.jsx'"

Вот моя конфигурация circleci:

config .yml

version: 2.1
jobs:
  build:
    docker:
      - image: circleci/node:9.9.0 # the primary container, where your job's commands are run
    steps:
      - checkout # check out the code in the project directory
      - run: echo "npm installing" # run the `echo` command
      - run: npm install
  test:
    docker:
      - image: circleci/node:9.9.0 # the primary container, where your job's commands are run
    steps:
      - checkout # check out the code in the project directory
      - run: echo "run testing" # run the `echo` command
      - run: npm install
      - run: npm test
workflows:
  version: 2.1
  build_test_lint:
    jobs:
      - build
      - test

App.test.jsx

import React from 'react';
import { shallow } from 'enzyme';
import App from './App';

describe('test App component', () => {
  const wrapper = <App />;
  it('expect to render App component', () => {
    expect(shallow(wrapper)).toHaveLength(1);
  });
});

App.jsx

import React from 'react';
import { Switch, Route, Redirect } from 'react-router-dom';
import Container from '@material-ui/core/Container';
import Header from './layouts/header';
import SignUpSignIn from './containers/signup_signin/signupsignin';

function App() {
  // const { currentUser } = useSelector((state) => state.user);
  const currentUser = false;
  return (
    <div className="App-container">
      <Header />
      <Switch>
        <Container maxWidth="md">
          <Route
            exact
            path="/signup"
            render={() =>
              currentUser ? <Redirect to="/" /> : <SignUpSignIn />
            }
          />
        </Container>
      </Switch>
    </div>
  );
}

export default App;
...