How to set test coverage threshold of new code only (Jest) - reactjs

How to set coverage checking of every new chunk of code before merging and skip this particular merge if test coverage of new code in it is less than 80%? We already have the global threshold of 80% but this setting doesn't assume that each pull request will be covered with tests less than 80% (some can be covered with 60% and some with 100% - it's unfair).
Stack (React, Next, Jest)
Thanks for the help!

Related

In Jest coverage report, how can I find the test that was responsible for testing a specific line of code?

This is a general question, that may apply to any code coverage report.
In my example above, highlighted line was tested over 77x times, but I'm unable to find the test itself which is testing it (I'm working on a very big repo).
What would be the best way to know this? Is there any flag I'm missing to add this info on top?
Thanks.
I don't believe that this is possible. Under the hood, the Istanbul code coverage tool is simply instrumenting your code into something like
cov_2ano4xc2b8().s[26]++;
const container = document.getElementById('container');
cov_2ano4xc2b8().s[27]++;
camera = new THREE.PerspectiveCamera();
cov_2ano4xc2b8().s[28]++;
(It may also be able to use V8's built-in code coverage features, but I expect the behavior for those is similar.)
To get per-test coverage, you could probably maintain a separate set of code coverage statistics for every test, then aggregate all of those when done, but I'm not aware of any existing tool that does this.
Absent that, there are manual alternatives, such as setting a breakpoint on an interesting line and then running the entire test suite in a debugger, or adding a throw new Error("THIS LINE WAS HIT"); at an interesting line then seeing which tests fail.

How to move tasks thus sprint is not always 100% completed

we use azuredevops in our team and try to understand our efficency by using analytics, especially sprint burndown.
When we come to the end of our sprint, we move tasks that are not completed in next sprint. Now, burndown chart show always 100% because tasks are in the next sprint- which I could understand.
But how is it possible to see the real %? How and when do we have to move tasks, thus it is not always 100% cause we dont finish all tasks every sprint.
I couldnt imagine that we have to copy tasks, so that the right % of completed work is shown.
Thanks for help. Best Laura

how upgrade perf and minimize main thread work next/Dynamic

I got optimization question about SEO & Performance, as a lot of us I'm challenging my selft to have the best score on the lighthouse to have the best chance to raise in the google index. So I reduce a lot of my assets, use module.css but even if my score is over 95 on desktop my mobile score is only over 75/60 ​​points ...
I found to way to increase the performance, I noticed the request number is a bit to hight, 105 requests:
So it’s follows that’s following warning:
Which is impact the FCP and the LCP, So I look at about kind of solution to split the code and call it when the are required (lazy load). So next / Dynamic from next should be the solution but I’m a bit confused because I don’t know exactly how to use it, I mean:
-What is the good case to import component with or without next / Dynamic?
-Will I get worse if I abuse of it?
-Should I use AMP?

What are these numbers in green color represent when testing react component and running test coverage?

I am writing Unit test cases for react components and after successfully implementing the test case. I run code coverage for that particular file.
There is one thing that I noticed which is the numbers written in green color before the statements and branches. I am providing the snapshot of it. So I want to know what this represent.
They represent how many times that line or piece of code was executed. In react testing this number could easily be higher than 1x because of all renders.

Salesforce Event updates parent record (Apex After Insert Trigger)

I have a basic trigger below that should update the field, Last Meeting Date, after saving a new event. The code works fine in my Sandbox environment, however it shows 0% code coverage and will not allow me to roll out into production. Any help would be appreciated.
trigger createLastReviewDate on Event (after insert) {
//map object to store account id and task create date
Map<Id,Date> accIds = new Map<Id,Date>();
//iterate over the new triggers and get the account id and task create date
for(Event e : trigger.new){
accIds.put(e.AccountId,Date.valueOf(e.StartDateTime));
}
//get the accounts to be updated
List<Account> acctsToUpdate = [Select Id,Last_Meeting_Date__c from Account where id in:accIds.keySet()];
//update the custom date field
for(Account acc : acctsToUpdate){
acc.Last_Meeting_Date__c = accIds.get(acc.Id);
}
update acctsToUpdate;
}
Salesforce has a built-in control that requires that all Apex code - Classes, Triggers, etc - include Unit Test classes. In order to promote code from a sandbox to Production, your code base must include 75% code coverage - calculated by line coverage.
Often times, developing good test classes/methods can take more time that writing the actual code. This is because you should include positive and negative tests and need to take the time to actually build your test data.
Please review the Salesforce Developer Guide for information about how to develop test classes and Salesforce's testing best practices: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_best_practices.htm Developing good habits around Unit Testing is critical to becoming a good developer. Half of my interview questions are based around testing - if you can write good test code, you can write good code.
Do you have test class written? If so please share it.
Your Trigger is simple and should not create issues for you.
All you need is 1% code coverage on Apex Triggers to deploy. Overall Code Coverage of 75% is must for Classes.

Resources