Skip to content

Commit

Permalink
refactor: adjusts bash script for test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-zakharchenko committed Apr 16, 2019
1 parent 25bf9e2 commit 472acc1
Show file tree
Hide file tree
Showing 17 changed files with 453 additions and 450 deletions.
3 changes: 0 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Source code (distributed code lives in /lib)
/src

# Common for .gitignore and .npmignore
src-cov/
lcov/
Expand Down
47 changes: 26 additions & 21 deletions bin/gavel
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
var cmd = require('commander');
var httpParser = require('http-string-parser');
var curlParser = require('curl-trace-parser');
var gavel = require('../lib/gavel');
var gavel = require('../src/gavel');
var fs = require('fs');

cmd.version('0.0.1');

var stdin = "";
var stdin = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
Expand All @@ -18,42 +18,47 @@ process.stdin.on('data', function(data) {
});

process.stdin.on('end', function() {
fs.readFile(process.argv[2], 'utf8', function (err,string){
var expectedHttp = curlParser.parseBack(string);
fs.readFile(process.argv[2], 'utf8', function(err, string) {
var expectedHttp = curlParser.parseBack(string);

var realHttp = curlParser.parseBack(stdin);

var realRequest = httpParser.parseRequest(realHttp['request']);
var realResponse = httpParser.parseResponse(realHttp['response']);

var expectedRequest = httpParser.parseRequest(expectedHttp['request']);
var expectedResponse = httpParser.parseResponse(expectedHttp['response']);

var requestResult = false;
var requestResult = false;
var responseResult = false;

gavel.isValid(realRequest, expectedRequest, 'request',function (err, result){

gavel.isValid(realRequest, expectedRequest, 'request', function(
err,
result
) {
requestResult = result;
gavel.isValid(realResponse, expectedResponse, 'response', function (err, result){
gavel.isValid(realResponse, expectedResponse, 'response', function(
err,
result
) {
responseResult = result;
})
});
});
if(requestResult && responseResult){

if (requestResult && responseResult) {
process.exit(0);
} else {
process.exit(1);
};
})

}
});
});

// do not end unit stdin end
var busyLoop = function() {
setTimeout( function() {
if(stdin == ""){
process.stderr.write("ERROR: No input on stdin after 1s. Exiting. \n");
process.exit(1)
setTimeout(function() {
if (stdin == '') {
process.stderr.write('ERROR: No input on stdin after 1s. Exiting. \n');
process.exit(1);
}
busyLoop();
}, 1000);
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
"name": "gavel",
"version": "0.0.0-semantically-released",
"description": "Validator of HTTP transactions (JavaScript implementation)",
"main": "lib/gavel.js",
"main": "src/gavel.js",
"engines": {
"node": ">= 4"
},
"bin": {
"gavel": "bin/gavel"
},
"scripts": {
"build": "coffee -b -c -o lib/ src/",
"lint": "coffeelint src",
"test": "npm run test:server && npm run test:browser && npm run test:features",
"test:server": "mocha \"test/unit/**/*-test.coffee\"",
"test:browser": "mochify \"test/unit/**/*.coffee\" --transform=coffeeify --extension=.coffee",
"test:features": "coffee scripts/cucumber.coffee",
"prepublish": "npm run build",
"coverage": "scripts/cov",
"coveralls": "npm run coverage mocha-lcov-reporter | coveralls",
"ci:lint": "npm run lint",
Expand Down
1 change: 1 addition & 0 deletions scripts/cov
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mkdir ./src-cov ./lcov
$COV --exclude=node_modules,.git,test --path=relative . ./src-cov 1>&2
cp ./package.json ./src-cov
cp -r ./test ./src-cov/test
cp -r ./src ./src-cov/src

# Testing
$MOCHA ./src-cov/test/unit/**/*-test.coffee --reporter="$REPORTER"
Expand Down
Loading

0 comments on commit 472acc1

Please sign in to comment.