Skip to content

Commit

Permalink
FAB-932 Gulp task to run tests with coverage reports
Browse files Browse the repository at this point in the history
"gulp test" to run the whole test bucket
"gulp test-headless" to run just the headless tests
both should print a report in the output and generate the HTMLs for the coverage report

Rebased on latest in master
Modified chain names in tests to avoid collision when
running together by "gulp test"

Change-Id: I477ec4853d29cea241c7a48cdf9609310862c3b2
Signed-off-by: Jim Zhang <[email protected]>
  • Loading branch information
jimthematrix committed Nov 3, 2016
1 parent 3262fee commit 3ca4e6f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The following tests require setting up a local blockchain network as the target.
* run `docker-compose up --force-recreate` to launch the network
* Back in your native host (MacOS, or Windows, or Ubuntu, etc), run the following tests:
* Clear out your previous keyvalue store if needed (rm -fr /tmp/KeyValStore*)
* Run `gulp test` to run the entire test bucket and generate coverage reports (both in console output and HTMLs)
* Test user management with a member services, run `node test/unit/ca-tests.js`
* Test happy path from end to end, run `node test/unit/end-2-end.js`
* Test transaction proposals, run `node test/unit/endorser-tests.js`
Expand All @@ -42,13 +43,10 @@ The following check-list is for code contributors to make sure their changesets
Check the coding styles, run the following command and make sure no ESLint violations are present:
* `gulp`

Run the full unit test bucket:
* `node test/unit/headless-tests.js`
* `node test/unit/ca-tests.js`
* `node test/unit/end-2-end.js`
* `node test/unit/endorser-tests.js`
* `node test/unit/orderer-tests.js`
* `node test/unit/orderer-member-tests.js`
Run the full unit test bucket and make sure 100% are passing:
* `gulp test`

The gulp test command above also generates code coverage reports. Your new code should be accompanied with unit tests and pass 80% lines coverage or above.

### HFC objects and reference documentation
For a high-level design specificiation for Fabric SDKs of all languages, visit [this google doc](https://docs.google.com/document/d/1R5RtIBMW9fZpli37E5Li5_Q9ve3BnQ4q3gWmGZj6Sv4/edit?usp=sharing) (Work-In-Progress).
Expand Down
28 changes: 27 additions & 1 deletion build/tasks/test.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
'use strict';

var gulp = require('gulp');
require('gulp-npm-test')(gulp);
var tape = require('gulp-tape');
var tapColorize = require('tap-colorize');
var istanbul = require('gulp-istanbul');

gulp.task('pre-test', function() {
return gulp.src(['lib/**/*.js'])
.pipe(istanbul())
.pipe(istanbul.hookRequire());
});

gulp.task('test', ['pre-test'], function() {
return gulp.src('test/unit/*.js')
.pipe(tape({
reporter: tapColorize()
}))
.pipe(istanbul.writeReports());
});

gulp.task('test-headless', ['pre-test'], function() {
return gulp.src('test/unit/headless-tests.js')
.pipe(tape({
reporter: tapColorize()
}))
.pipe(istanbul.writeReports());
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
"fs-extra": "^0.30.0",
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-istanbul": "^1.1.1",
"gulp-jsdoc3": "^0.3.0",
"gulp-npm-test": "0.0.4",
"gulp-tape": "0.0.9",
"intercept-stdout": "^0.1.2",
"log4js": "^0.6.38",
"require-dir": "^0.3.0",
"tap-colorize": "^1.2.0",
"tape": "^4.5.1",
"tape-promise": "^1.1.0",
"winston": "^2.2.0"
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ca-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('Test enroll() and registrar privileges with registerAndEnroll()', function
//
// Create and configure the test chain
//
var chain = hfc.newChain('testChain');
var chain = hfc.newChain('testChain-ca');
var expect = '';
var found = '';
var webUser;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/end-to-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var testUtil = require('./util.js');

var _fabricProto = grpc.load(path.join(__dirname,'../../lib/protos/fabric_next.proto')).protos;

var chain = hfc.newChain('testChain');
var chain = hfc.newChain('testChain-e2e');
var webUser;

testUtil.setupChaincodeDeploy();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/endorser-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test('endorser test', function(t) {
//
// Create and configure the test chain
//
var chain = hfc.newChain('testChain');
var chain = hfc.newChain('testChain-endorser');
var expect = '';
var found = '';
var webUser;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/orderer-member-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test('\n\n** TEST ** orderer via chain setOrderer/getOrderer', function(t) {
//
// Create and configure the test chain
//
var chain = hfc.getChain('testChain', true);
var chain = hfc.getChain('testChain-orderer-member', true);
try {
var order_address = 'grpc://localhost:5151';
chain.setOrderer(order_address);
Expand Down

0 comments on commit 3ca4e6f

Please sign in to comment.