In the next article, we will focus on how to get Jest working. In this part, I will explain step by step how to setup Lerna, Yarn Workspaces and Typescript in a mono repo. The release of the packages will be done with Github Actions. So it will have its own package.json where we'll explicitly declare its dependencies. We will be using TypeScript, Yarn workspaces, Lerna, and Jest. We should think about this workspaces as a standard npm library that can work in isolation. yarn cd rnproject yarn test When running jest, specifying the root dir as the workspace root ( -rootDir. When using Yarn workspaces, we also need to ensure that Jest is able to resolve local dependencies. The idea here is to isolate the JavaScript code that runs the app in an app workspace. Lets' start from the shared React Native JavaScript code. └── / └── packages/ # React Native JavaScript code shared across the apps ├── app/ │ ├── src/ │ └── package.json # Android/iOS app configuration files and native code └── mobile/ ├── android/ ├── ios/ ├── app.json ├── ├── index.js ├── └── package.json The shared React Native JavaScript code: packages/app Yarn Workspaces is a feature that allows users to install dependencies from multiple package.json files in subfolders of a single root package.json file, all in one go. eslintrc.js in workspaces where you need to ignore certain folders or files. └── / └── packages/ # React Native JavaScript code shared across the apps ├── app/ │ ├── src/ │ └── package.json # Android/iOS app configuration files and native code └── mobile/ ├── android/ ├── ios/ ├── app.json ├── ├── index.js ├── └── package.json. workspaces that require tests have a file and 'test': 'jest' in 'scripts' of package.json you extend. If (match & Path.dirname(match) >= process. Run the build script on all descendant packages : yarn workspaces foreach -A run build. if match and it's not outside the workspace: yarn workspaces foreach -A npm publish -tolerate-republish. OK so the idea here is similar, run the right Yarn workspace for the file we’re trying to debug: // launch.json So I think that part just works out of the box. Running this will make Yarn run yarn test in each of its workspaces, running jest all tests for services. If you’re using Yarn Workspaces (or Lerna), all I had to do is change the run configuration like so: "jest.pathToJest": "yarn workspaces run test" There are two key aspects to vscode-jest:įor running all tests, I was able to run all my services tests, each with each own jest configuration, without having to add define each as workspace. Register one or more remote workspaces for use in the current project : yarn link /ts-loader /jest. This pattern is often called monorepo when used in conjunction with a repository. It’s obviously not vscode-jest’s fault, but I think there might be a rather simple way to support running jest in the right monorepo service without having to configure VS Code for Workspaces. Workspaces are the name of individual packages that are part of the same project and that Yarn will install and link together to simplify cross-references. Yarn workspaces, 317 third-party authentication services, 246 Three.js, 192 tokens. I am not finding much in the docs to support that installing binaries in workspace root is pointless which makes me wonder if something is corrupt. Jest publishing, 323 shadowing, 312 gatsby-starter-blog-theme, 328-329. yarn workspaces focus -all -production & rm -rf '(yarn cache clean)' From here you should be past the major obstacles and you will probably just need to clean up some tests. yarn plugin import yarnpkg/plugin-workspace-tools // Clean the cache out of all your workspaces. It’s a pretty tedious process for a project with 15+ services, and counting… I've upgrade Yarn and now no workspace script such as yarn test will run without installing say jest in each workspace, or calling it with run -T jest. yarn set version stable // Update workspace tools. The problem is, the way VS Code Workspaces currently works is, one has to define each of the services in one’s monorepo as a VS Code workspace. It’s great that vscode-jest now supports VS Code’s Workspaces.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |