Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit fbf17d2

Browse files
remove timer because slow CI servers need more than half a second before data is flowing - switch to use --pipe or -l as signal to codecov to recieve data via stdin
1 parent b145b19 commit fbf17d2

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

bin/codecov

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,21 @@ var args = argv.option([
2020
{name: 'slug', short: 'r', type: 'string', description: "Specify repository slug for Enterprise ex. owner/repo"},
2121
{name: 'url', short: 'u', type: 'string', description: "Your Codecov endpoint"},
2222
{name: 'flags', short: 'F', type: 'string', description: "Codecov Flags"},
23-
{name: 'dump', type: 'boolean', description: "Dump collected data and do not send to Codecov"}
23+
{name: 'dump', type: 'boolean', description: "Dump collected data and do not send to Codecov"},
24+
{name: 'pipe', short: 'l', type: 'boolean', description: "Listen to stdin for coverage data"}
2425
]).run();
2526

26-
// listen for piped input for 500ms
27-
var listeningTime = 500;
28-
var readingPiped = false;
29-
process.stdin.setEncoding('utf8');
30-
process.stdin.on('data', function(report) {
31-
if (report !== null) {
32-
readingPiped = true;
33-
clearTimeout(timer);
34-
if (!args.options.pipe) args.options.pipe = [];
27+
if (args.options.pipe) {
28+
process.stdin.setEncoding('utf8');
29+
args.options.pipe = [];
30+
31+
process.stdin.on('data', function(report) {
3532
args.options.pipe.push(report);
36-
}
37-
});
38-
process.stdin.on('end', function() {
39-
if (readingPiped) codecov.upload(args);
40-
});
33+
});
4134

42-
var timer = setTimeout(function() {
43-
if (!readingPiped) {
35+
process.stdin.on('end', function() {
4436
codecov.upload(args);
45-
process.exit();
46-
}
47-
}, listeningTime);
37+
});
38+
} else {
39+
codecov.upload(args);
40+
}

test/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ describe("Codecov", function(){
3838
});
3939

4040
it("can specify report in cli", function(){
41-
var res = codecov.upload({options: {dump: true, file: 'test' + pathSeparator + 'coverage.json'}});
42-
expect(res.files[0].split(pathSeparator).pop()).to.eql('coverage.json');
41+
var res = codecov.upload({options: {dump: true, file: 'test' + pathSeparator + 'example.coverage.txt'}});
42+
expect(res.files[0].split(pathSeparator).pop()).to.eql('example.coverage.txt');
4343
expect(res.body).to.contain('this file is intentionally left blank');
4444
});
4545

@@ -134,7 +134,7 @@ describe("Codecov", function(){
134134

135135
it("can read piped reports", function(done){
136136
var exec = require('child_process').exec;
137-
var childProcess = exec('cat test/coverage.json | bin/codecov --dump --disable=gcov', function(err, stdout, stderr){
137+
var childProcess = exec('cat test/example.coverage.txt | bin/codecov -l --dump --disable=gcov', function(err, stdout, stderr){
138138
expect(stdout.toString()).to.contain('path=piped');
139139
expect(stdout.toString()).to.contain('this file is intentionally left blank');
140140
childProcess.kill();

0 commit comments

Comments
 (0)