File tree Expand file tree Collapse file tree 5 files changed +73
-9
lines changed Expand file tree Collapse file tree 5 files changed +73
-9
lines changed Original file line number Diff line number Diff line change @@ -134,7 +134,8 @@ function constructDefaultArgs () {
134
134
functions : 0 ,
135
135
lines : 0 ,
136
136
statements : 0 ,
137
- jobs : 1
137
+ jobs : 1 ,
138
+ outputFile : null
138
139
}
139
140
140
141
if ( process . env . TAP_COLORS !== undefined )
@@ -162,7 +163,8 @@ function parseArgs (args, defaults) {
162
163
j : 'jobs' ,
163
164
R : 'reporter' ,
164
165
t : 'timeout' ,
165
- s : 'save'
166
+ s : 'save' ,
167
+ o : 'output-file'
166
168
}
167
169
168
170
// If we're running under Travis-CI with a Coveralls.io token,
@@ -350,6 +352,12 @@ function parseArgs (args, defaults) {
350
352
options . color = false
351
353
continue
352
354
355
+ case '--output-file' :
356
+ val = val || args [ ++ i ]
357
+ if ( val !== undefined )
358
+ options . outputFile = val
359
+ continue
360
+
353
361
case '--no-timeout' :
354
362
options . timeout = 0
355
363
continue
@@ -727,12 +735,16 @@ function runTests (options) {
727
735
var tap = require ( '../lib/tap.js' )
728
736
729
737
tap . jobs = options . jobs
738
+ tap . patchProcess ( )
730
739
731
740
// if not -Rtap, then output what the user wants.
732
- if ( options . reporter !== 'tap' ) {
733
- tap . unpipe ( process . stdout )
734
- tap . pipe ( makeReporter ( options ) )
735
- }
741
+ // otherwise just dump to stdout
742
+ tap . pipe ( options . reporter === 'tap' ? process . stdout : makeReporter ( options ) )
743
+
744
+ // need to replay the first version line, because the previous
745
+ // line will have flushed it out to stdout or the reporter already.
746
+ if ( options . outputFile !== null )
747
+ tap . pipe ( fs . createWriteStream ( options . outputFile ) ) . write ( 'TAP version 13\n' )
736
748
737
749
saveFails ( options , tap )
738
750
Original file line number Diff line number Diff line change @@ -44,6 +44,12 @@ Options:
44
44
Available reporters:
45
45
@@REPORTERS@@
46
46
47
+ -o<file> Send the raw TAP output to the specified
48
+ --output-file=<file> file. Reporter output will still be
49
+ printed to stdout, but the file will
50
+ contain the raw TAP for later reply or
51
+ analysis.
52
+
47
53
-s<file> --save=<file> If <file> exists, then it should be a line-
48
54
delimited list of test files to run. If
49
55
<file> is not present, then all command-line
Original file line number Diff line number Diff line change @@ -74,15 +74,17 @@ function onExitEvent (code) {
74
74
TAP . prototype . push = function push ( ) {
75
75
// this resets push and pipe to standard values
76
76
this . pipe ( process . stdout )
77
+ this . patchProcess ( )
78
+ return this . push . apply ( this , arguments )
79
+ }
77
80
81
+ TAP . prototype . patchProcess = function ( ) {
78
82
monkeypatchEpipe ( )
79
83
monkeypatchExit ( )
80
84
process . on ( 'uncaughtException' , this . threw )
81
85
process . on ( 'unhandledRejection' , function ( er ) {
82
86
this . threw ( er )
83
87
} . bind ( this ) )
84
-
85
- return this . push . apply ( this , arguments )
86
88
}
87
89
88
90
TAP . prototype . onbail = function ( ) {
Original file line number Diff line number Diff line change @@ -29,7 +29,8 @@ var defaults = {
29
29
jobs : 1 ,
30
30
lines : 0 ,
31
31
statements : 0 ,
32
- rcFile : osHomedir ( ) + '/.taprc'
32
+ rcFile : osHomedir ( ) + '/.taprc' ,
33
+ outputFile : null
33
34
}
34
35
35
36
function runTest ( rcFile , expect ) { return function ( t ) {
Original file line number Diff line number Diff line change
1
+ var t = require ( '../' )
2
+ var spawn = require ( 'child_process' ) . spawn
3
+ var run = require . resolve ( '../bin/run.js' )
4
+ var fs = require ( 'fs' )
5
+ var node = process . execPath
6
+ var ok = require . resolve ( './test/ok.js' )
7
+
8
+ var args = [
9
+ '-ofile.txt' ,
10
+ '-Co file.txt' ,
11
+ '-bCco=file.txt' ,
12
+ '-o=file.txt' ,
13
+ '--output-file=file.txt' ,
14
+ '--output-file file.txt'
15
+ ]
16
+
17
+ args . forEach ( function ( arg ) {
18
+ t . test ( arg , function ( t ) {
19
+ try { fs . unlinkSync ( 'file.txt' ) } catch ( er ) { }
20
+ arg = arg . split ( ' ' )
21
+ var child = spawn ( node , [ run , '-c' , ok ] . concat ( arg ) )
22
+ var gotStdout = false
23
+ child . stdout . on ( 'data' , function ( c ) {
24
+ gotStdout = true
25
+ } )
26
+ child . stderr . on ( 'data' , function ( c ) {
27
+ throw new Error ( 'should not write to stderr' )
28
+ } )
29
+ child . on ( 'close' , function ( code , sig ) {
30
+ t . equal ( code , 0 )
31
+ t . equal ( sig , null )
32
+ t . ok ( gotStdout , 'got standard output' )
33
+ t . match ( fs . readFileSync ( 'file.txt' , 'utf8' ) , / ^ T A P v e r s i o n 1 3 \n / )
34
+ t . end ( )
35
+ } )
36
+ } )
37
+ } )
38
+
39
+ t . test ( 'cleanup' , function ( t ) {
40
+ try { fs . unlinkSync ( 'file.txt' ) } catch ( er ) { }
41
+ t . done ( )
42
+ } )
43
+
You can’t perform that action at this time.
0 commit comments