New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to save report output to a file #509
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ tunnel | |
node_modules | ||
.idea | ||
.coverage_data | ||
cover_html | ||
cover_html | ||
test-results.xml | ||
reports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var fs = require('fs') | ||
var path = require('path') | ||
var mkdirp = require('mkdirp') | ||
var PassThrough = require('stream').PassThrough | ||
|
||
function ReportFile(reportFile, out) { | ||
this.file = reportFile | ||
|
||
this.outputStream = new PassThrough() | ||
|
||
mkdirp.sync(path.dirname(path.resolve(reportFile))) | ||
|
||
var fileStream = fs.createWriteStream(reportFile, 'w+') | ||
|
||
this.outputStream.on('data', function(data) { | ||
out.write(data) | ||
fileStream.write(data) | ||
}) | ||
|
||
this.outputStream.on('end', function(data) { | ||
out.end(data) | ||
fileStream.end(data) | ||
}) | ||
|
||
this.stream = this.outputStream | ||
} | ||
|
||
module.exports = ReportFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
var fs = require('fs') | ||
var App = require('../../lib/ci') | ||
var TestReporter = require('../../lib/ci/test_reporters/tap_reporter') | ||
var Config = require('../../lib/config') | ||
var bd = require('bodydouble') | ||
var mock = bd.mock | ||
var stub = bd.stub | ||
var assert = require('chai').assert | ||
var expect = require('chai').expect | ||
var Process = require('did_it_work') | ||
var exec = require('child_process').exec | ||
var rimraf = require('rimraf') | ||
var path = require('path') | ||
var PassThrough = require('stream').PassThrough | ||
var ReportFile = require('../../lib/ci/report_file') | ||
var XUnitReporter = require('../../lib/ci/test_reporters/xunit_reporter') | ||
var tmp = require('tmp') | ||
|
||
describe('report file output', function() { | ||
var mainReportDir, reportDir, filename; | ||
before(function(done) { | ||
tmp.dir(function(err, path) { | ||
mainReportDir = path | ||
done() | ||
}) | ||
}) | ||
after(function(done) { | ||
rimraf(mainReportDir, function() { | ||
done() | ||
}) | ||
}) | ||
|
||
beforeEach(function(done) { | ||
tmp.dir({template: path.join(mainReportDir, '/reports-XXXXXX')}, function(err, dirPath){ | ||
if(err) throw err | ||
reportDir = dirPath | ||
|
||
tmp.file({dir: dirPath, name: 'test-reports.xml'}, function(err, filePath) { | ||
filename = filePath | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('allows passing in report_file from config', function(){ | ||
var fakeReporter = {} | ||
var config = new Config('ci', { | ||
reporter: fakeReporter, | ||
report_file: filename | ||
}) | ||
var app = new App(config) | ||
assert.strictEqual(app.reportFileName, filename) | ||
}) | ||
|
||
it("doesn't create a file if the report_file parameter is not passed in", function(done){ | ||
var filename = tmp.tmpNameSync() | ||
var fakeReporter = {} | ||
var config = new Config('ci', { | ||
reporter: fakeReporter, | ||
}) | ||
var app = new App(config) | ||
fs.readFile(filename, function(error, data) { | ||
expect(error).not.to.be.null | ||
done() | ||
}) | ||
}) | ||
|
||
it('writes out results to the normal output stream', function(){ | ||
var fakeStdout = new PassThrough() | ||
var reportFile = new ReportFile(filename, fakeStdout) | ||
reportFile.stream.write('some test results') | ||
var output = fakeStdout.read().toString() | ||
assert.match(output, /some test results/) | ||
}) | ||
|
||
it('writes out results to the file', function(done){ | ||
var stream = new PassThrough() | ||
var reportFile = new ReportFile(filename, stream) | ||
var reportStream = reportFile.stream | ||
|
||
reportStream.on('finish', function() { | ||
fs.readFile(filename, function(error, data) { | ||
assert.match(data, /test data/) | ||
done() | ||
}) | ||
}) | ||
reportStream.write('test data') | ||
reportStream.end() | ||
}) | ||
|
||
it("creates folders in the path if they don't exist", function(done) { | ||
var nestedFilename = tmp.tmpNameSync({dir: reportDir, name: 'nested/test/folders/test-reports.xml'}) | ||
|
||
var fakeStdout = new PassThrough() | ||
var reportFile = new ReportFile(nestedFilename, fakeStdout) | ||
|
||
fs.open(nestedFilename, 'r', function(error, fd) { | ||
expect(error).to.be.null | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be removed, when
tmp.dir({unsafeCleanup: true}, cb)
is used in before.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that and it was still throwing crazy errors on Windows and folders were still hanging around.
On Mar 4, 2015, at 12:10 AM, Johannes W?rbach <notifications@github.commailto:notifications@github.com> wrote:
In tests/ci/report_file_tests.jshttps://github.com//pull/509#discussion_r25757807:
This could be removed, when tmp.dir({unsafeCleanup: true}, cb) is used in before.
Reply to this email directly or view it on GitHubhttps://github.com//pull/509/files#r25757807.