viewstools / yarn-workspaces-cra-crna

How to use yarn workspaces with Create React App and Create React Native App (Expo) to share common code across
151 stars 23 forks source link

Yarn test does not work in native #9

Open Smtih opened 6 years ago

Smtih commented 6 years ago

So I've been using this as the basis for a project using cra and crna.

Using the workspace_example provided running yarn test on the native project doesn't work (pretty obvious as it sitl points to ./node_modules/jest/.bin/jest.js which is now in the parent directory.

pointing to the jest file in the parent directory doesn't fix the issue as jest-expo preset is still using the native directory as it's root to find other modules.

Next level of fixing is to change the rootDir in jest. in the end I had to add the following lines to the package.json jest config.

  "jest": {
    "preset": "jest-expo",
    "rootDir": "..",
    "roots": [
      "<rootDir>/native",
      "<rootDir>/node_modules"
    ]
  },

the roots are needed such that it doesn't try and run tests in all folders from the workspace but can still find node modules, however it then can't interpret es6 things anymore. This is where I'm stuck.

dariocravero commented 6 years ago

Does #8 sort it out for you?

kimak commented 6 years ago

@dariocravero https://github.com/viewstools/yarn-workspaces-cra-crna/pull/8 doesn't make it work

I made a PR to fix web & native tests: https://github.com/viewstools/yarn-workspaces-cra-crna/pull/15 The main "tricks" was to move the native/.babelrc to the root folder (need documentation for that) + update the jest version on native side