dwyl / learn-istanbul Goto Github PK
View Code? Open in Web Editor NEW:checkered_flag: Learn how to use the Istanbul JavaScript Code Coverage Tool
:checkered_flag: Learn how to use the Istanbul JavaScript Code Coverage Tool
http=>https
CodeCov is a service we use to track the test coverage of our projects over time.
see: https://codecov.io/#features
example: https://codecov.io/github/dwyl/hapi-login-example-postgres?ref=7aef31d1eb5daf5b9d48308222594423f992d834
Sometimes you want to ignore a specific file or even a folder from being checked by Istanbul
e.g you include a 3rd party library or code in your project (instead of putting it on a CDN)
You can define a list of excludes
files in a .istanbul.yml
at the root of your project/repo.
Its not an especially well-documented feature... There's only one reference to
.istanbul.yml
in the entire Istanbul project, see: https://github.com/gotwarlost/istanbul/search?l=markdown&q=.istanbul.yml&utf8=%E2%9C%93
There are examples on the StackOverflows if you search for them. e.g: http://stackoverflow.com/a/34685175/1148249
instrumentation:
root: .
extensions:
- .js
default-excludes: true
excludes: ['**/tinymce/**', '**/lib/**', '**/tools/**', '**/build/**']
include-all-sources: true
a more detailed sample file: https://github.com/vesln/todo/blob/master/.istanbul.yml
@nikhilaravi needed this today in our project, it reminded me we should add it to the readme.
This doc needs some TLC.
istanbul
has recently been deprecated https://www.npmjs.com/package/istanbul
Should we switch from istanbul
to nyc
? https://www.npmjs.com/package/nyc
See: https://github.com/istanbuljs/nyc#readme
I expect that it will take a couple of hours to update this tutorial/example and then a few minutes for each of our JS repos which are using istanbul
...
Thoughts? Anyone want to volunteer to do this?
How to cover all the files in the directory recursively
Update the screenshots and remove the images from the repo to reduce bloat.
https://github.com/dwyl/learn-istanbul/blob/d8ebff630bdb7fdfcbd7a67cf3e56b66654ff358/test.js
and
https://github.com/dwyl/learn-istanbul/blob/d8ebff630bdb7fdfcbd7a67cf3e56b66654ff358/test1.js
appear to be identical. is this intentional? do we need both?
Hi,
I am not sure if this was intended in the first place or a typo. I was learning from your article and the first time I ran code coverage on mischief.js, it had a 100% coverage. After scratching my head for sometime, I realized it's doing what the test asked it to do. I had to update the 20000 to number < 10000 to have the right output.
console.log("\nExpect Account1 Opening Balance "+getAccountBalance(account1) +" === 0 \u2713 ");
creditAccount(account1, 2000, 'Add Funds');
transferMoney(account1,account2, 100, 'Give money to friend');
transferMoney(account2,account1, 10, 'Transfer back 10');
In the "Tracking Coverage as-a Service" section:
https://github.com/dwyl/learn-istanbul/tree/bb027a62b40558ad1717fd8f168291777b95b8cd#tracking-coverage-as-a-service
We are currently advising people to use the "old" way:
We can simplify this a lot by simply running the bash command:
bash <(curl -s https://codecov.io/bash)
relates to #12
if anyone has time to go through this readme and check that all the links work, please do. thanks!
I'm trying to use Codecov on Travis without using the key as you told me it can be done without and so in the name of efficiency I want to learn how it's done!
My .travis.yml and package.json look like yours:
https://github.com/Cleop/triumph-website/blob/master/.travis.yml#L3-L6
https://github.com/Cleop/triumph-website/blob/master/package.json#L10
And I'm registered on Codecov and have selected the repo.
However I'm not getting any data on Codecov when I merge PR or on the badge on my README.
Any advice would be greatly appreciated ๐ Thank you!
I'm using istanbul 0.4.5 (with istanbul-lib-coverage 1.2.0 and istanbul-lib-instrument 1.10.1) to check coverage of my jasmine unit tests over my ES6 source, and I found a branches count which is not mentioned in your document.
If my function has a default value for input parameter, like this (this is a class used to create an AngularJS service):
class UserDataService {
getClientData() {
return this.client;
}
setClientData(obj = { foo: 'bar' }) {
this.client = obj;
}
}
export default UserDataService;
Notice the default value for setClientData
parameter obj
.
If my test suite is:
import moduleUnderTesting from './userData';
describe('Service: UserDataService', () => {
let service;
beforeEach(() => {
angular.mock.module(moduleUnderTesting);
});
beforeEach(inject((_UserDataService_) => {
service = _UserDataService_;
}));
describe('method setClientData and getClientData', () => {
it('should set/get clientData correctly', () => {
const cData = { one: 1, two: 2 };
service.setClientData(cData);
expect(service.getClientData()).toBe(cData);
});
});
});
The test run reports 1 branch not covered:
While, if I add a test case that makes setClientData
use the default value for obj
parameter, like this:
import moduleUnderTesting from './userData';
describe('Service: UserDataService', () => {
let service;
beforeEach(() => {
angular.mock.module(moduleUnderTesting);
});
beforeEach(inject((_UserDataService_) => {
service = _UserDataService_;
}));
describe('method setClientData and getClientData', () => {
it('should set/get clientData correctly', () => {
const cData = { one: 1, two: 2 };
service.setClientData(cData);
expect(service.getClientData()).toBe(cData);
});
it('should set/get clientData correctly using default value', () => {
service.setClientData();
expect(service.getClientData()).toEqual({ foo: 'bar' });
});
});
});
Test run reports full coverage:
This is an issue of istanbul itself, because the coverage should show what's the missing branch; anyway, I'm reporting it here as well in order for it to be pointed out in your document.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.