@@ -18,7 +18,7 @@ function findCoverageFileForPid(pid) {
18
18
} ) ;
19
19
}
20
20
21
- function getCoverageFixtureReport ( ) {
21
+ function getTapCoverageFixtureReport ( ) {
22
22
const report = [
23
23
'# start of coverage report' ,
24
24
'# file | line % | branch % | funcs % | uncovered lines' ,
@@ -37,64 +37,120 @@ function getCoverageFixtureReport() {
37
37
return report ;
38
38
}
39
39
40
- test ( '--experimental-test-coverage and --test cannot be combined' , ( ) => {
41
- // TODO(cjihrig): This test can be removed once multi-process code coverage
42
- // is supported.
43
- const args = [ '--test' , '--experimental-test-coverage' ] ;
44
- const result = spawnSync ( process . execPath , args ) ;
45
-
46
- // 9 is the documented exit code for an invalid CLI argument.
47
- assert . strictEqual ( result . status , 9 ) ;
48
- assert . match (
49
- result . stderr . toString ( ) ,
50
- / - - e x p e r i m e n t a l - t e s t - c o v e r a g e c a n n o t b e u s e d w i t h - - t e s t /
51
- ) ;
52
- } ) ;
40
+ function getSpecCoverageFixtureReport ( ) {
41
+ const report = [
42
+ '\u2139 start of coverage report' ,
43
+ '\u2139 file | line % | branch % | funcs % | uncovered lines' ,
44
+ '\u2139 test/fixtures/test-runner/coverage.js | 78.65 | 38.46 | 60.00 | 12, ' +
45
+ '13, 16, 17, 18, 19, 20, 21, 22, 27, 39, 43, 44, 61, 62, 66, 67, 71, 72' ,
46
+ '\u2139 test/fixtures/test-runner/invalid-tap.js | 100.00 | 100.00 | 100.00 | ' ,
47
+ '\u2139 test/fixtures/v8-coverage/throw.js | 71.43 | 50.00 | 100.00 | 5, 6' ,
48
+ '\u2139 all files | 78.35 | 43.75 | 60.00 |' ,
49
+ '\u2139 end of coverage report' ,
50
+ ] . join ( '\n' ) ;
53
51
54
- test ( 'handles the inspector not being available' , ( t ) => {
55
- if ( process . features . inspector ) {
56
- return ;
52
+ if ( common . isWindows ) {
53
+ return report . replaceAll ( '/' , '\\' ) ;
57
54
}
58
55
59
- const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
60
- const args = [ '--experimental-test-coverage' , fixture ] ;
61
- const result = spawnSync ( process . execPath , args ) ;
56
+ return report ;
57
+ }
62
58
63
- assert ( ! result . stdout . toString ( ) . includes ( '# start of coverage report' ) ) ;
64
- assert ( result . stderr . toString ( ) . includes ( 'coverage could not be collected' ) ) ;
65
- assert . strictEqual ( result . status , 0 ) ;
66
- assert ( ! findCoverageFileForPid ( result . pid ) ) ;
67
- } ) ;
59
+ test ( 'test coverage report' , async ( t ) => {
60
+ await t . test ( '--experimental-test-coverage and --test cannot be combined' , ( ) => {
61
+ // TODO(cjihrig): This test can be removed once multi-process code coverage
62
+ // is supported.
63
+ const args = [ '--test' , '--experimental-test-coverage' ] ;
64
+ const result = spawnSync ( process . execPath , args ) ;
65
+
66
+ // 9 is the documented exit code for an invalid CLI argument.
67
+ assert . strictEqual ( result . status , 9 ) ;
68
+ assert . match (
69
+ result . stderr . toString ( ) ,
70
+ / - - e x p e r i m e n t a l - t e s t - c o v e r a g e c a n n o t b e u s e d w i t h - - t e s t /
71
+ ) ;
72
+ } ) ;
68
73
69
- test ( 'coverage is reported and dumped to NODE_V8_COVERAGE if present ' , ( t ) => {
70
- if ( ! process . features . inspector ) {
71
- return ;
72
- }
74
+ await t . test ( 'handles the inspector not being available ' , ( t ) => {
75
+ if ( process . features . inspector ) {
76
+ return ;
77
+ }
73
78
74
- const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
75
- const args = [ '--experimental-test-coverage' , fixture ] ;
76
- const options = { env : { ...process . env , NODE_V8_COVERAGE : tmpdir . path } } ;
77
- const result = spawnSync ( process . execPath , args , options ) ;
78
- const report = getCoverageFixtureReport ( ) ;
79
+ const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
80
+ const args = [ '--experimental-test-coverage' , fixture ] ;
81
+ const result = spawnSync ( process . execPath , args ) ;
79
82
80
- assert ( result . stdout . toString ( ) . includes ( report ) ) ;
81
- assert . strictEqual ( result . stderr . toString ( ) , '' ) ;
82
- assert . strictEqual ( result . status , 0 ) ;
83
- assert ( findCoverageFileForPid ( result . pid ) ) ;
83
+ assert ( ! result . stdout . toString ( ) . includes ( '# start of coverage report' ) ) ;
84
+ assert ( result . stderr . toString ( ) . includes ( 'coverage could not be collected' ) ) ;
85
+ assert . strictEqual ( result . status , 0 ) ;
86
+ assert ( ! findCoverageFileForPid ( result . pid ) ) ;
87
+ } ) ;
84
88
} ) ;
85
89
86
- test ( 'coverage is reported without NODE_V8_COVERAGE present' , ( t ) => {
87
- if ( ! process . features . inspector ) {
88
- return ;
89
- }
90
+ test ( 'test tap coverage reporter' , async ( t ) => {
91
+ await t . test ( 'coverage is reported and dumped to NODE_V8_COVERAGE if present' , ( t ) => {
92
+ if ( ! process . features . inspector ) {
93
+ return ;
94
+ }
95
+
96
+ const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
97
+ const args = [ '--experimental-test-coverage' , '--test-reporter' , 'tap' , fixture ] ;
98
+ const options = { env : { ...process . env , NODE_V8_COVERAGE : tmpdir . path } } ;
99
+ const result = spawnSync ( process . execPath , args , options ) ;
100
+ const report = getTapCoverageFixtureReport ( ) ;
101
+
102
+ assert ( result . stdout . toString ( ) . includes ( report ) ) ;
103
+ assert . strictEqual ( result . stderr . toString ( ) , '' ) ;
104
+ assert . strictEqual ( result . status , 0 ) ;
105
+ assert ( findCoverageFileForPid ( result . pid ) ) ;
106
+ } ) ;
107
+
108
+ await t . test ( 'coverage is reported without NODE_V8_COVERAGE present' , ( t ) => {
109
+ if ( ! process . features . inspector ) {
110
+ return ;
111
+ }
112
+
113
+ const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
114
+ const args = [ '--experimental-test-coverage' , '--test-reporter' , 'tap' , fixture ] ;
115
+ const result = spawnSync ( process . execPath , args ) ;
116
+ const report = getTapCoverageFixtureReport ( ) ;
90
117
91
- const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
92
- const args = [ '--experimental-test-coverage' , fixture ] ;
93
- const result = spawnSync ( process . execPath , args ) ;
94
- const report = getCoverageFixtureReport ( ) ;
118
+ assert ( result . stdout . toString ( ) . includes ( report ) ) ;
119
+ assert . strictEqual ( result . stderr . toString ( ) , '' ) ;
120
+ assert . strictEqual ( result . status , 0 ) ;
121
+ assert ( ! findCoverageFileForPid ( result . pid ) ) ;
122
+ } ) ;
123
+ } ) ;
95
124
96
- assert ( result . stdout . toString ( ) . includes ( report ) ) ;
97
- assert . strictEqual ( result . stderr . toString ( ) , '' ) ;
98
- assert . strictEqual ( result . status , 0 ) ;
99
- assert ( ! findCoverageFileForPid ( result . pid ) ) ;
125
+ test ( 'test spec coverage reporter' , async ( t ) => {
126
+ await t . test ( 'coverage is reported and dumped to NODE_V8_COVERAGE if present' , ( t ) => {
127
+ if ( ! process . features . inspector ) {
128
+ return ;
129
+ }
130
+ const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
131
+ const args = [ '--experimental-test-coverage' , '--test-reporter' , 'spec' , fixture ] ;
132
+ const options = { env : { ...process . env , NODE_V8_COVERAGE : tmpdir . path } } ;
133
+ const result = spawnSync ( process . execPath , args , options ) ;
134
+ const report = getSpecCoverageFixtureReport ( ) ;
135
+
136
+ assert ( result . stdout . toString ( ) . includes ( report ) ) ;
137
+ assert . strictEqual ( result . stderr . toString ( ) , '' ) ;
138
+ assert . strictEqual ( result . status , 0 ) ;
139
+ assert ( findCoverageFileForPid ( result . pid ) ) ;
140
+ } ) ;
141
+
142
+ await t . test ( 'coverage is reported without NODE_V8_COVERAGE present' , ( t ) => {
143
+ if ( ! process . features . inspector ) {
144
+ return ;
145
+ }
146
+ const fixture = fixtures . path ( 'test-runner' , 'coverage.js' ) ;
147
+ const args = [ '--experimental-test-coverage' , '--test-reporter' , 'spec' , fixture ] ;
148
+ const result = spawnSync ( process . execPath , args ) ;
149
+ const report = getSpecCoverageFixtureReport ( ) ;
150
+
151
+ assert ( result . stdout . toString ( ) . includes ( report ) ) ;
152
+ assert . strictEqual ( result . stderr . toString ( ) , '' ) ;
153
+ assert . strictEqual ( result . status , 0 ) ;
154
+ assert ( ! findCoverageFileForPid ( result . pid ) ) ;
155
+ } ) ;
100
156
} ) ;
0 commit comments