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

fix(ci): Log test output on CircleCI #3882

Merged
merged 2 commits into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion scripts/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
var path = require('path');

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

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

executor.execute();
// If we're running on CircleCI, save stdout and stderr from the test run to a log file.
if (process.env['CIRCLE_ARTIFACTS']) {
executor.execute(path.join(process.env['CIRCLE_ARTIFACTS'], 'test_log.txt'));
} else {
executor.execute();
}
47 changes: 25 additions & 22 deletions scripts/test/test_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@ var CommandlineTest = function(command) {
var self = this;
this.command_ = command;
this.expectedExitCode_ = 0;
this.stdioOnlyOnFailures_ = true;
this.expectedErrors_ = [];
this.assertExitCodeOnly_ = false;

// If stdioOnlyOnFailures_ is true, do not stream stdio unless test failed.
// This is to prevent tests with expected failures from polluting the output.
this.alwaysEnableStdio = function() {
self.stdioOnlyOnFailures_ = false;
return self;
};
this.testLogStream = undefined;

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

this.setTestLogFile = function(filename) {
self.testLogStream = fs.createWriteStream(filename, {flags: 'a'});
};

// Set the expected exit code for the test command.
this.expectExitCode = function(exitCode) {
self.expectedExitCode_ = exitCode;
Expand Down Expand Up @@ -75,19 +72,18 @@ var CommandlineTest = function(command) {

var test_process;

if (self.stdioOnlyOnFailures_) {
test_process = child_process.spawn(args[0], args.slice(1));
test_process = child_process.spawn(args[0], args.slice(1));

test_process.stdout.on('data', function(data) {
output += data;
});
var processData = function(data) {
process.stdout.write('.');
output += data;
if (self.testLogStream) {
self.testLogStream.write(data);
}
};

test_process.stderr.on('data', function(data) {
output += data;
});
} else {
test_process = child_process.spawn(args[0], args.slice(1), {stdio: 'inherit'});
}
test_process.stdout.on('data', processData);
test_process.stderr.on('data', processData);

test_process.on('error', function(err) {
reject(err);
Expand All @@ -102,6 +98,10 @@ var CommandlineTest = function(command) {
', actual: ' + exitCode);
}

if (self.testLogStream) {
self.testLogStream.end();
}

// Skip the rest if we are only verify exit code.
// Note: we're expecting a file populated by '--resultJsonOutputFile' after
// this point.
Expand Down Expand Up @@ -202,17 +202,20 @@ exports.Executor = function() {
return test;
};

this.execute = function() {
this.execute = function(logFile) {
var failed = false;

(function runTests(i) {
if (i < tests.length) {
console.log('running: ' + tests[i].command_);
if (logFile) {
tests[i].setTestLogFile(logFile);
}
tests[i].run().then(function() {
console.log('>>> \033[1;32mpass\033[0m');
console.log('\n>>> \033[1;32mpass\033[0m');
}, function(err) {
failed = true;
console.log('>>> \033[1;31mfail: ' + err.toString() + '\033[0m');
console.log('\n>>> \033[1;31mfail: ' + err.toString() + '\033[0m');
}).fin(function() {
runTests(i + 1);
}).done();
Expand Down