Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 01a8545

Browse files
committed
fix(ci): Save stdout and stderr from test runs on CircleCI.
Helps with debugging on CircleCI. If the test times out or is killed, we'll be able to see what it was doing. Also removes the unused alwaysEnableStdio() method.
1 parent 9bf3d3f commit 01a8545

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

scripts/test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
var path = require('path');
23

34
var Executor = require('./test/test_util').Executor;
45

@@ -144,4 +145,9 @@ executor.addCommandlineTest('node built/cli.js spec/angular2TimeoutConf.js')
144145
{message: 'Timed out waiting for asynchronous Angular tasks to finish'},
145146
]);
146147

147-
executor.execute();
148+
// If we're running on CircleCI, save stdout and stderr from the test run to a log file.
149+
if (process.env['CIRCLE_ARTIFACTS']) {
150+
executor.execute(path.join(process.env['CIRCLE_ARTIFACTS'], 'test_log.txt'));
151+
} else {
152+
executor.execute();
153+
}

scripts/test/test_util.js

+23-23
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,9 @@ var CommandlineTest = function(command) {
88
var self = this;
99
this.command_ = command;
1010
this.expectedExitCode_ = 0;
11-
this.stdioOnlyOnFailures_ = true;
1211
this.expectedErrors_ = [];
1312
this.assertExitCodeOnly_ = false;
14-
15-
// If stdioOnlyOnFailures_ is true, do not stream stdio unless test failed.
16-
// This is to prevent tests with expected failures from polluting the output.
17-
this.alwaysEnableStdio = function() {
18-
self.stdioOnlyOnFailures_ = false;
19-
return self;
20-
};
13+
this.testLogStream = undefined;
2114

2215
// Only assert the exit code and not failures.
2316
// This must be true if the command you're running does not support
@@ -27,6 +20,10 @@ var CommandlineTest = function(command) {
2720
return self;
2821
};
2922

23+
this.setTestLogFile = function(filename) {
24+
self.testLogStream = fs.createWriteStream(filename, {flags: 'a'});
25+
};
26+
3027
// Set the expected exit code for the test command.
3128
this.expectExitCode = function(exitCode) {
3229
self.expectedExitCode_ = exitCode;
@@ -75,22 +72,18 @@ var CommandlineTest = function(command) {
7572

7673
var test_process;
7774

78-
if (self.stdioOnlyOnFailures_) {
79-
test_process = child_process.spawn(args[0], args.slice(1));
75+
test_process = child_process.spawn(args[0], args.slice(1));
8076

81-
test_process.stdout.on('data', function(data) {
82-
process.stdout.write('.');
83-
output += data;
84-
});
77+
var processData = function(data) {
78+
process.stdout.write('.');
79+
output += data;
80+
if (self.testLogStream) {
81+
self.testLogStream.write(data);
82+
}
83+
};
8584

86-
test_process.stderr.on('data', function(data) {
87-
process.stdout.write('.');
88-
output += data;
89-
});
90-
} else {
91-
test_process = child_process
92-
.spawn(args[0], args.slice(1), {stdio: 'inherit', stderr: 'inherit'});
93-
}
85+
test_process.stdout.on('data', processData);
86+
test_process.stderr.on('data', processData);
9487

9588
test_process.on('error', function(err) {
9689
reject(err);
@@ -105,6 +98,10 @@ var CommandlineTest = function(command) {
10598
', actual: ' + exitCode);
10699
}
107100

101+
if (self.testLogStream) {
102+
self.testLogStream.end();
103+
}
104+
108105
// Skip the rest if we are only verify exit code.
109106
// Note: we're expecting a file populated by '--resultJsonOutputFile' after
110107
// this point.
@@ -205,12 +202,15 @@ exports.Executor = function() {
205202
return test;
206203
};
207204

208-
this.execute = function() {
205+
this.execute = function(logFile) {
209206
var failed = false;
210207

211208
(function runTests(i) {
212209
if (i < tests.length) {
213210
console.log('running: ' + tests[i].command_);
211+
if (logFile) {
212+
tests[i].setTestLogFile(logFile);
213+
}
214214
tests[i].run().then(function() {
215215
console.log('\n>>> \033[1;32mpass\033[0m');
216216
}, function(err) {

0 commit comments

Comments
 (0)