@@ -4,7 +4,7 @@ import fs from 'fs-extra';
4
4
import { runRstestCli } from '../scripts' ;
5
5
6
6
it ( 'coverage-istanbul' , async ( ) => {
7
- const { expectExecSuccess } = await runRstestCli ( {
7
+ const { expectExecSuccess, expectLog , cli } = await runRstestCli ( {
8
8
command : 'rstest' ,
9
9
args : [ 'run' ] ,
10
10
options : {
@@ -16,7 +16,91 @@ it('coverage-istanbul', async () => {
16
16
17
17
await expectExecSuccess ( ) ;
18
18
19
+ const logs = cli . stdout . split ( '\n' ) . filter ( Boolean ) ;
20
+
21
+ expectLog ( 'Coverage enabled with istanbul' , logs ) ;
22
+
23
+ // test coverage
24
+ expect (
25
+ logs . find (
26
+ ( log ) =>
27
+ log . includes ( 'index.ts' ) &&
28
+ log . replaceAll ( ' ' , '' ) . includes ( '100|100|100|100' ) ,
29
+ ) ,
30
+ ) . toBeTruthy ( ) ;
31
+ expect (
32
+ logs . find (
33
+ ( log ) =>
34
+ log . includes ( 'string.ts' ) &&
35
+ log . replaceAll ( ' ' , '' ) . includes ( '93.75|100|83.33|92.85|7' ) ,
36
+ ) ,
37
+ ) . toBeTruthy ( ) ;
38
+ // TODO: should not include test files
39
+ expect (
40
+ logs . find (
41
+ ( log ) =>
42
+ log . includes ( 'All files' ) &&
43
+ log . replaceAll ( ' ' , '' ) . includes ( '99.43|100|98.68|99.41' ) ,
44
+ ) ,
45
+ ) . toBeTruthy ( ) ;
46
+
47
+ // text reporter
48
+ expectLog ( '% Stmts' , logs ) ;
49
+
50
+ // html reporter
51
+ expect (
52
+ fs . existsSync ( join ( __dirname , 'fixtures/coverage/index.html' ) ) ,
53
+ ) . toBeTruthy ( ) ;
54
+
55
+ // clover reporter
56
+ expect (
57
+ fs . existsSync ( join ( __dirname , 'fixtures/coverage/clover.xml' ) ) ,
58
+ ) . toBeTruthy ( ) ;
59
+
60
+ // json reporter
19
61
expect (
20
62
fs . existsSync ( join ( __dirname , 'fixtures/coverage/coverage-final.json' ) ) ,
21
63
) . toBeTruthy ( ) ;
22
64
} ) ;
65
+
66
+ it ( 'coverage-istanbul with custom options' , async ( ) => {
67
+ const { expectExecSuccess, expectLog, cli } = await runRstestCli ( {
68
+ command : 'rstest' ,
69
+ args : [ 'run' , '-c' , 'rstest.skipFull.config.ts' ] ,
70
+ options : {
71
+ nodeOptions : {
72
+ cwd : join ( __dirname , 'fixtures' ) ,
73
+ } ,
74
+ } ,
75
+ } ) ;
76
+
77
+ await expectExecSuccess ( ) ;
78
+
79
+ const logs = cli . stdout . split ( '\n' ) . filter ( Boolean ) ;
80
+
81
+ expectLog ( 'Coverage enabled with istanbul' , logs ) ;
82
+
83
+ // test coverage
84
+ expect (
85
+ logs . find (
86
+ ( log ) =>
87
+ log . includes ( 'index.ts' ) &&
88
+ log . replaceAll ( ' ' , '' ) . includes ( '100|100|100|100' ) ,
89
+ ) ,
90
+ ) . toBeFalsy ( ) ;
91
+ expect (
92
+ logs . find (
93
+ ( log ) =>
94
+ log . includes ( 'string.ts' ) &&
95
+ log . replaceAll ( ' ' , '' ) . includes ( '93.75|100|83.33|92.85|7' ) ,
96
+ ) ,
97
+ ) . toBeTruthy ( ) ;
98
+
99
+ // text reporter
100
+ expectLog ( '% Stmts' , logs ) ;
101
+
102
+ // TODO: should clean and not generate html reporter
103
+ expect (
104
+ fs . existsSync ( join ( __dirname , 'fixtures/coverage/index.html' ) ) ,
105
+ ) . toBeTruthy ( ) ;
106
+ } ) ;
0 commit comments