I have my project in huge monorepo on non machine that has poor I/O performance etc. git status takes ages. When I run npm test (app was create with create-react-app), there's an initial step to that is determining tests to run. I assume that jest is figuring it out based on files changed.
Is there a way to configure jest to ignore git repo features completely and simply rerun all tests at startup and later run tests only for files that were affected by currently changed file (I guess that could be possible with ES6 imports) or always rerun all tests when watched files are changed?
Related
I'm using Turborepo for my monorepo project, i have 2 react apps. How can i configure Turborepo and CircleCI (repos are on Github) so if i make changes to one project that pipeline is not going to run for second project?
I know turbo is using hash algo to check if there is any changes to a project and then rebuild it.
I have tried looking here https://turborepo.org/docs/ci/circleci but does not explain the behavior of this.
Steps would be:
Make code change to Project 1
Commit changes of monorepo to Github
Github detects a commit and triggers CircleCI to run CI/CD
So this part is what I'm not sure, if it triggers CI/CD it will trigger for the both projects right? And if so how can i prevent only for the one i have made changes?
I've been working on such a solution for days now. There are two core-concepts in turborepo to achieve this:
Filtering workspaces
Caching Buildoutputs and store the cache in the cloud (not what you're looking for)
So, you can filter your monorepo for a specific project, e.g:
pnpm turbo run build --filter='my-project...[HEAD^1]' --dry=json
-> This will look if the task build is needed to run for the project "my-project", comparing the current source with "HEAD^1". The option dry=json helps to just look if there would be a need to run "build" or not for "my-project".
You could filter a whole lot more, check the docs.
Now, what i have built on top of this:
A new job on the github workflow looks with the help of this filter command if a deployment of my graphql-server is needed and he will set the output of this decision as an artifact, to provide this information for later jobs (https://github.com/actions/upload-artifact)
My actual docker-build and deploy-to-fly-io jobs that run afterwards, will download this artifact and set a CONTINUE environment variable, depending if it should build + deploy or not.
Every job coming after that is having an if: ${{ env.CONTINUE == 'true' }} to skip them if no build/deploy is needed.
It could be much simpler if you can run your build/deploy job directly with the turbo cli, because then you can just combine your filter and the execution of the build - but that was not possible in my case.
If you need to "skip" jobs that are coming later in your workflow, it's harder thant it should, as github is not supporting "abortion" of jobs.
For all the other commands like lint, typecheck and test -> just add an appropriate filter option to them and you will achieve that they only run on your "affected" workspaces/projects in your PR.
Ressources:
https://dev.to/ngconf/deploying-nx-affected-apps-from-github-actions-54n4
How can I get the previous commit before a push or merge in GitHub Action workflow?
https://github.com/orgs/community/discussions/26313
We're using Jest to perform our React.js unit tests (on the frontend) of our Node.js app which runs in a docker container.
We have set up a Pipeline in Jenkins but I'm unsure of the best way (or best practice) to include the tests as part of the pipeline.
The steps we have are the following:
Check out the code from source control
NPM install and npm run build (front-end)
Docker build + publish
Deploy app
Bump version
Git push
Docker cleanup
I have 3 main queries:
A. I'm assuming it's best to include npm run test between Step 1 and Step 2 and if all tests pass successfully to move further?
B. But how are the snapshots handled? For example, if there's some change which occurred that generates a difference in a snapshot this will not be "checked" back into the source control.
C. I read that people use Cobertura, jest-junit, etc to have unit tests and coverage within Jenkins - what is the best?
Thanks in advance.
Good questions!
A. You can run tests after npm install. And if all tests pass you move further. Another common thing to do is to run linting or code style check.
B. A bad snapshot will fail tests. Which is why it's important to update snapshots before committing. If your jenkins is hooked up to a code review system, you may disable merges that fail builds, to make sure bad snapshots don't get on your master branch.
C. I have seen people use jest-junit, but that's only because there was a requirement to have the coverage report combined with a junit coverage report. If you don't have any particular requirements around the structure of the report, then the default report jest produces should be fine, and you don't need anything extra.
my current front-end dev setup is below:
browserify as build tool
budo as a development server
I have a couple of shared modules packaged up and published on npm for use as a dependency among many projects.
However the development feedback cycle is too long since I have to run npm link ../<repo> && npm run dev every time I need to see an updated change and it takes too long to finish linking , approx. 2-5 minutes.
Is there a way I can watch changes in my link'd module and it will rebuild files that were changes?
Budo (browserify) should follow symlinks, so once you npm link then you should be able to edit both modules concurrently (and get live reload) without having to re-run any commands. This is assuming your other module doesn't need a transpile step. If it isn't working, perhaps it's a bug or some other issue. Feel free to open an issue on budo's GH issues to discuss further.
– #mattdesl
We are using Storybook along with its StoryShots addon to visualize and test our ReactXP components.
Recently, the CI job that runs the tests on those StoryShots started failing with snapshots that don't match.
Turns out that when we update the snapshots from our Mac development environment, the snapshots include a webkitFlexDirection style whereas the snapshots generated by the CI environment (docker image based on node:9) don't have this attribute:
I have no idea where this webkitFlexDirection comes from and why it is present in the snapshots generated on my Mac but not in the snapshots generated within the test Docker image.
I have searched for webkitFlexDirection in many top-level repos (React, ReactXP, Jest, Storybook, StoryShots, ...) and found nothing.
I suppose that react-test-renderer uses some library to produce the snapshot, and that library would be the one responsible for generating (or not) the webkitFlexDirection attribute, but I can't figure it out.
Currently I have an Angular application built on top of NG6-starter. The NG6-Starter uses webpack to bundle the application. It also supports unit testing by default via Karma, but karma uses webpack as well in order to get all the sources injected to it's browser.
Now, my issue is, that I would like to add my application to a classic CI/CD pipeline: Some static analysis, then package build, then unit tests, then etc, and I do not want to break the principle of "Test against the artifact that you are going to deploy" principle. Since karma currently builds the application for itself, it does not really rely on the artifact, that is going to be deployed, even though by the stage karma runs, it is already built.
My question is, if you have any idea/practice/example/experience with this topic?
Okay, so it seems so, that in order to achieve this, the spec files should be built with webpack during build time. For this, the easiest way seemed to be to simple introduce a new chunk entry point to the application.