react-workspaces / react-workspaces-playground

⚛️ 🐈 Zero Config Create-React-App Monorepos with Yarn Workspaces, Lerna and React Storybook.
https://react-workspaces.github.io/react-workspaces-playground/
764 stars 128 forks source link

yarn test not working #4

Closed pastor3llo closed 5 years ago

pastor3llo commented 5 years ago

I tried the stuff in this repo but i found that yarn test is not working ` Test suite failed to run

Cannot find module '@project/comp-one' from 'App.js'

  2 | import logo from './logo.svg';
  3 | import './App.css';
> 4 | import CompOne from '@project/comp-one';
    | ^
  5 | 
  6 | class App extends Component {
  7 |     render() {

  at Resolver.resolveModule (../../node_modules/jest-resolve/build/index.js:221:17)
  at Object.<anonymous> (src/App.js:4:1)

Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 2.451s`

F1LT3R commented 5 years ago

How are you running the tests?

pastor3llo commented 5 years ago

i just took the repo as is and i did: $ yarn $ cd ~/repos/cra-workspaces-poc/apps create-react-app --scripts-version @f1lt3r/react-scripts@2.1.1-workspaces-04 app-foo $ cd ~/repos/cra-workspaces-poc/apps/app-foo yarn start was ok, but on $ yarn test

and i got: ` FAIL src/App.test.js ● Test suite failed to run

Cannot find module '@project/comp-one' from 'App.js'

  2 | import logo from './logo.svg';
  3 | import './App.css';
> 4 | import CompOne from '@project/comp-one';
    | ^
  5 | 
  6 | class App extends Component {
  7 |     render() {

  at Resolver.resolveModule (../../node_modules/jest-resolve/build/index.js:221:17)
  at Object.<anonymous> (src/App.js:4:1)

Test Suites: 1 failed, 1 total Tests: 0 total Snapshots: 0 total Time: 1.427s Ran all test suites.

Watch Usage › Press f to run only failed tests. › Press o to only run tests related to changed files. › Press q to quit watch mode. › Press t to filter by a test name regex pattern. › Press p to filter by a filename regex pattern. › Press Enter to trigger a test run.`

Remimstr commented 5 years ago

I have experienced the same behaviour both with my own monorepo and a clone of this one.

Remimstr commented 5 years ago

@F1LT3R this is a really big hurdle to me using this approach on my codebase. Is there anything I can do to help fix it?

F1LT3R commented 5 years ago

Should be working now @Remimstr @pastor3llo you want to checkout and test?

Remimstr commented 5 years ago

Unfortunately no, it's still not working. I did exactly the steps as you outlined for a new repo:

git clone git@github.com:react-workspaces/cra-workspaces-playground.git
cd cra-workspaces-playground
yarn
cd packages/apps/app-one
yarn test

and it still gives the same "Cannot find module '@project/comp-one' from 'App.js' error.

In case it's relevant, I'm using node v11.5.0 yarn v1.15.2 and npm v6.4.1

alistair-hmh commented 5 years ago

Working here...

Screen Shot 2019-04-27 at 9 09 18 AM

You might need to pull this repo and try that way.

I think following the steps there are parts missing that would make testing work for you.

alistair-hmh commented 5 years ago

@Remimstr try adding "main": "src/index.js" to each package.json.

Remimstr commented 5 years ago

That suggestion fixed it for me. Thank you for the help!