1
1
import { join } from "node:path" ;
2
2
import { fileURLToPath , URL } from "node:url" ;
3
- import { FailedInfoMap , IAssertResult } from "../../../src/interface.js" ;
4
- import { ExecutionResult } from "../../../src/executionResult.js" ;
3
+ import { FailedInfoMap , IExecutionResult } from "../../../src/interface.js" ;
4
+ import { ExecutionResultSummary } from "../../../src/executionResult.js" ;
5
5
import chalk from "chalk" ;
6
6
7
7
const __dirname = fileURLToPath ( new URL ( "." , import . meta. url ) ) ;
8
8
9
9
test ( "no failedInfo merge" , async ( ) => {
10
- const executionResult = new ExecutionResult ( ) ;
11
- const testcaseA : IAssertResult = {
10
+ const executionResult = new ExecutionResultSummary ( ) ;
11
+ const testcaseA : IExecutionResult = {
12
12
fail : 0 ,
13
13
total : 28 ,
14
+ crashInfo : new Set < string > ( ) ,
14
15
failedInfo : { } ,
15
16
failedLogMessages : { } ,
16
17
} ;
@@ -21,13 +22,14 @@ test("no failedInfo merge", async () => {
21
22
expect ( executionResult . failedInfos ) . toEqual ( new Map < string , string [ ] > ( ) ) ;
22
23
} ) ;
23
24
24
- test ( "equal failed" , async ( ) => {
25
- const executionResult = new ExecutionResult ( ) ;
25
+ test ( "equal assert failed" , async ( ) => {
26
+ const executionResult = new ExecutionResultSummary ( ) ;
26
27
const actualString = "A long sentence for testing errorMsg.length > 160 in executionResult.ts merge function" ;
27
28
const expectString = "= A long sentence for testing errorMsg.length > 160 in executionResult.ts merge function " ;
28
- const testcaseA : IAssertResult = {
29
+ const testcaseA : IExecutionResult = {
29
30
fail : 1 ,
30
31
total : 28 ,
32
+ crashInfo : new Set < string > ( ) ,
31
33
failedInfo : {
32
34
A : [
33
35
[ "1" , "100" , "= 200" ] ,
@@ -44,6 +46,7 @@ test("equal failed", async () => {
44
46
await executionResult . merge ( testcaseA , expectInfoFIlePath ) ;
45
47
const expectFailedInfo : FailedInfoMap = new Map ( ) ;
46
48
expectFailedInfo . set ( "A" , {
49
+ hasCrash : false ,
47
50
assertMessages : [
48
51
"tests/as/comparison.test.ts:10:20 value: 100 expect: = 200" ,
49
52
"tests/as/comparison.test.ts:15:27 value: [10] expect: = [1]" ,
@@ -57,31 +60,90 @@ test("equal failed", async () => {
57
60
expect ( executionResult . failedInfos ) . toEqual ( expectFailedInfo ) ;
58
61
} ) ;
59
62
60
- test ( "print" , async ( ) => {
61
- const executionResult = new ExecutionResult ( ) ;
62
- const testcaseA : IAssertResult = {
63
+ test ( "equal crash" , async ( ) => {
64
+ const executionResult = new ExecutionResultSummary ( ) ;
65
+ const actualString = "A long sentence for testing errorMsg.length > 160 in executionResult.ts merge function" ;
66
+ const expectString = "= A long sentence for testing errorMsg.length > 160 in executionResult.ts merge function " ;
67
+ const testcaseA : IExecutionResult = {
63
68
fail : 1 ,
64
- total : 28 ,
65
- failedInfo : {
66
- A : [ [ "1" , "100" , "= 200" ] ] ,
67
- } ,
69
+ total : 1 ,
70
+ crashInfo : new Set < string > ( ) ,
71
+ failedInfo : { } ,
68
72
failedLogMessages : {
69
73
A : [ "log message 1" , "log message 2" , "log message 3" ] ,
70
74
} ,
71
75
} ;
76
+ testcaseA . crashInfo . add ( "A" ) ;
72
77
const expectInfoFIlePath = join ( __dirname , ".." , "fixture" , "assertResultTest.expectInfo.json" ) ;
73
78
await executionResult . merge ( testcaseA , expectInfoFIlePath ) ;
79
+ const expectFailedInfo : FailedInfoMap = new Map ( ) ;
80
+ expectFailedInfo . set ( "A" , {
81
+ hasCrash : true ,
82
+ assertMessages : [ ] ,
83
+ logMessages : [ "log message 1" , "log message 2" , "log message 3" ] ,
84
+ } ) ;
85
+ expect ( executionResult . fail ) . toEqual ( 1 ) ;
86
+ expect ( executionResult . total ) . toEqual ( 1 ) ;
87
+ expect ( executionResult . failedInfos ) . toEqual ( expectFailedInfo ) ;
88
+ } ) ;
89
+
90
+ describe ( "print" , ( ) => {
91
+ test ( "assert failed" , async ( ) => {
92
+ const executionResult = new ExecutionResultSummary ( ) ;
93
+ const testcaseA : IExecutionResult = {
94
+ fail : 1 ,
95
+ total : 28 ,
96
+ crashInfo : new Set < string > ( ) ,
97
+ failedInfo : {
98
+ A : [ [ "1" , "100" , "= 200" ] ] ,
99
+ } ,
100
+ failedLogMessages : {
101
+ A : [ "log message 1" , "log message 2" , "log message 3" ] ,
102
+ } ,
103
+ } ;
104
+ const expectInfoFIlePath = join ( __dirname , ".." , "fixture" , "assertResultTest.expectInfo.json" ) ;
105
+ await executionResult . merge ( testcaseA , expectInfoFIlePath ) ;
74
106
75
- {
76
- const outputs : string [ ] = [ ] ;
77
- chalk . level = 0 ; // disable color
78
- executionResult . print ( ( msg ) => outputs . push ( msg ) ) ;
79
- expect ( outputs . join ( "\n" ) ) . toMatchSnapshot ( ) ;
80
- }
81
- {
82
- const outputs : string [ ] = [ ] ;
83
- chalk . level = 1 ; // force enable color
84
- executionResult . print ( ( msg ) => outputs . push ( msg ) ) ;
85
- expect ( outputs . join ( "\n" ) ) . toMatchSnapshot ( ) ;
86
- }
107
+ {
108
+ const outputs : string [ ] = [ ] ;
109
+ chalk . level = 0 ; // disable color
110
+ executionResult . print ( ( msg ) => outputs . push ( msg ) ) ;
111
+ expect ( outputs . join ( "\n" ) ) . toMatchSnapshot ( ) ;
112
+ }
113
+ {
114
+ const outputs : string [ ] = [ ] ;
115
+ chalk . level = 1 ; // force enable color
116
+ executionResult . print ( ( msg ) => outputs . push ( msg ) ) ;
117
+ expect ( outputs . join ( "\n" ) ) . toMatchSnapshot ( ) ;
118
+ }
119
+ } ) ;
120
+
121
+ test ( "crash" , async ( ) => {
122
+ const executionResult = new ExecutionResultSummary ( ) ;
123
+ const testcaseA : IExecutionResult = {
124
+ fail : 1 ,
125
+ total : 28 ,
126
+ crashInfo : new Set < string > ( ) ,
127
+ failedInfo : { } ,
128
+ failedLogMessages : {
129
+ A : [ "log message 1" , "log message 2" , "log message 3" ] ,
130
+ } ,
131
+ } ;
132
+ testcaseA . crashInfo . add ( "A" ) ;
133
+ const expectInfoFIlePath = join ( __dirname , ".." , "fixture" , "assertResultTest.expectInfo.json" ) ;
134
+ await executionResult . merge ( testcaseA , expectInfoFIlePath ) ;
135
+
136
+ {
137
+ const outputs : string [ ] = [ ] ;
138
+ chalk . level = 0 ; // disable color
139
+ executionResult . print ( ( msg ) => outputs . push ( msg ) ) ;
140
+ expect ( outputs . join ( "\n" ) ) . toMatchSnapshot ( ) ;
141
+ }
142
+ {
143
+ const outputs : string [ ] = [ ] ;
144
+ chalk . level = 1 ; // force enable color
145
+ executionResult . print ( ( msg ) => outputs . push ( msg ) ) ;
146
+ expect ( outputs . join ( "\n" ) ) . toMatchSnapshot ( ) ;
147
+ }
148
+ } ) ;
87
149
} ) ;
0 commit comments