2
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
- import { should , expect } from 'chai' ;
6
5
import { getNullChannel } from '../../../test/unitTests/fakes' ;
6
+ import { describe , test , expect , beforeEach } from '@jest/globals' ;
7
7
import { OmnisharpLoggerObserver } from '../../../src/observers/omnisharpLoggerObserver' ;
8
8
import {
9
9
OmnisharpServerMsBuildProjectDiagnostics ,
@@ -20,9 +20,7 @@ import {
20
20
import { OutputChannel } from 'vscode' ;
21
21
import { PlatformInformation } from '../../../src/shared/platform' ;
22
22
23
- suite ( 'OmnisharpLoggerObserver' , ( ) => {
24
- suiteSetup ( ( ) => should ( ) ) ;
25
-
23
+ describe ( 'OmnisharpLoggerObserver' , ( ) => {
26
24
let logOutput = '' ;
27
25
const channel = < OutputChannel > {
28
26
...getNullChannel ( ) ,
@@ -35,19 +33,19 @@ suite('OmnisharpLoggerObserver', () => {
35
33
platform : 'TestOS' ,
36
34
} ) ;
37
35
38
- setup ( ( ) => {
36
+ beforeEach ( ( ) => {
39
37
logOutput = '' ;
40
38
} ) ;
41
39
42
- suite ( 'OmnisharpServerMsBuildProjectDiagnostics' , ( ) => {
40
+ describe ( 'OmnisharpServerMsBuildProjectDiagnostics' , ( ) => {
43
41
test ( 'Logged message is empty if there are no warnings and erros' , ( ) => {
44
42
const event = new OmnisharpServerMsBuildProjectDiagnostics ( {
45
43
FileName : 'someFile' ,
46
44
Warnings : [ ] ,
47
45
Errors : [ ] ,
48
46
} ) ;
49
47
observer . post ( event ) ;
50
- expect ( logOutput ) . to . be . empty ;
48
+ expect ( logOutput ) . toBe ( '' ) ;
51
49
} ) ;
52
50
53
51
test ( `Logged message contains the Filename if there is atleast one error or warning` , ( ) => {
@@ -67,7 +65,7 @@ suite('OmnisharpLoggerObserver', () => {
67
65
Errors : [ ] ,
68
66
} ) ;
69
67
observer . post ( event ) ;
70
- expect ( logOutput ) . to . contain ( event . diagnostics . FileName ) ;
68
+ expect ( logOutput ) . toContain ( event . diagnostics . FileName ) ;
71
69
} ) ;
72
70
73
71
[
@@ -100,20 +98,20 @@ suite('OmnisharpLoggerObserver', () => {
100
98
test ( `Logged message contains the Filename, StartColumn, StartLine and Text for the diagnostic warnings` , ( ) => {
101
99
observer . post ( event ) ;
102
100
event . diagnostics . Warnings . forEach ( ( element ) => {
103
- expect ( logOutput ) . to . contain ( element . FileName ) ;
104
- expect ( logOutput ) . to . contain ( element . StartLine ) ;
105
- expect ( logOutput ) . to . contain ( element . StartColumn ) ;
106
- expect ( logOutput ) . to . contain ( element . Text ) ;
101
+ expect ( logOutput ) . toContain ( element . FileName ) ;
102
+ expect ( logOutput ) . toContain ( element . StartLine . toString ( ) ) ;
103
+ expect ( logOutput ) . toContain ( element . StartColumn . toString ( ) ) ;
104
+ expect ( logOutput ) . toContain ( element . Text ) ;
107
105
} ) ;
108
106
} ) ;
109
107
110
108
test ( `Logged message contains the Filename, StartColumn, StartLine and Text for the diagnostics errors` , ( ) => {
111
109
observer . post ( event ) ;
112
110
event . diagnostics . Errors . forEach ( ( element ) => {
113
- expect ( logOutput ) . to . contain ( element . FileName ) ;
114
- expect ( logOutput ) . to . contain ( element . StartLine ) ;
115
- expect ( logOutput ) . to . contain ( element . StartColumn ) ;
116
- expect ( logOutput ) . to . contain ( element . Text ) ;
111
+ expect ( logOutput ) . toContain ( element . FileName ) ;
112
+ expect ( logOutput ) . toContain ( element . StartLine . toString ( ) ) ;
113
+ expect ( logOutput ) . toContain ( element . StartColumn . toString ( ) ) ;
114
+ expect ( logOutput ) . toContain ( element . Text ) ;
117
115
} ) ;
118
116
} ) ;
119
117
} ) ;
@@ -123,32 +121,32 @@ suite('OmnisharpLoggerObserver', () => {
123
121
( event : EventWithMessage ) => {
124
122
test ( `${ event . constructor . name } : Message is logged` , ( ) => {
125
123
observer . post ( event ) ;
126
- expect ( logOutput ) . to . contain ( event . message ) ;
124
+ expect ( logOutput ) . toContain ( event . message ) ;
127
125
} ) ;
128
126
}
129
127
) ;
130
128
131
129
test ( `OmnisharpServerOnServerError: Message is logged` , ( ) => {
132
130
const event = new OmnisharpServerOnServerError ( 'on server error message' ) ;
133
131
observer . post ( event ) ;
134
- expect ( logOutput ) . to . contain ( event . err ) ;
132
+ expect ( logOutput ) . toContain ( event . err ) ;
135
133
} ) ;
136
134
137
135
[ new OmnisharpInitialisation ( [ ] , new Date ( 5 ) , 'somePath' ) ] . forEach ( ( event : OmnisharpInitialisation ) => {
138
136
test ( `${ event . constructor . name } : TimeStamp and SolutionPath are logged` , ( ) => {
139
137
observer . post ( event ) ;
140
- expect ( logOutput ) . to . contain ( event . timeStamp . toLocaleString ( ) ) ;
141
- expect ( logOutput ) . to . contain ( event . solutionPath ) ;
138
+ expect ( logOutput ) . toContain ( event . timeStamp . toLocaleString ( ) ) ;
139
+ expect ( logOutput ) . toContain ( event . solutionPath ) ;
142
140
} ) ;
143
141
} ) ;
144
142
145
143
test ( 'OmnisharpFailure: Failure message is logged' , ( ) => {
146
144
const event = new OmnisharpFailure ( 'failureMessage' , new Error ( 'errorMessage' ) ) ;
147
145
observer . post ( event ) ;
148
- expect ( logOutput ) . to . contain ( event . message ) ;
146
+ expect ( logOutput ) . toContain ( event . message ) ;
149
147
} ) ;
150
148
151
- suite ( 'OmnisharpEventPacketReceived' , ( ) => {
149
+ describe ( 'OmnisharpEventPacketReceived' , ( ) => {
152
150
[
153
151
new OmnisharpEventPacketReceived ( 'TRACE' , 'foo' , 'someMessage' ) ,
154
152
new OmnisharpEventPacketReceived ( 'DEBUG' , 'foo' , 'someMessage' ) ,
@@ -159,8 +157,8 @@ suite('OmnisharpLoggerObserver', () => {
159
157
] . forEach ( ( event : OmnisharpEventPacketReceived ) => {
160
158
test ( `${ event . logLevel } messages are logged with name and the message` , ( ) => {
161
159
observer . post ( event ) ;
162
- expect ( logOutput ) . to . contain ( event . name ) ;
163
- expect ( logOutput ) . to . contain ( event . message ) ;
160
+ expect ( logOutput ) . toContain ( event . name ) ;
161
+ expect ( logOutput ) . toContain ( event . message ) ;
164
162
} ) ;
165
163
} ) ;
166
164
@@ -169,7 +167,7 @@ suite('OmnisharpLoggerObserver', () => {
169
167
const fn = function ( ) {
170
168
observer . post ( event ) ;
171
169
} ;
172
- expect ( fn ) . to . throw ( Error ) ;
170
+ expect ( fn ) . toThrow ( Error ) ;
173
171
} ) ;
174
172
175
173
test ( `Information messages with name OmniSharp.Middleware.LoggingMiddleware and follow pattern /^/[/w]+: 200 d+ms/ are not logged` , ( ) => {
@@ -179,11 +177,11 @@ suite('OmnisharpLoggerObserver', () => {
179
177
'/codecheck: 200 339ms'
180
178
) ;
181
179
observer . post ( event ) ;
182
- expect ( logOutput ) . to . be . empty ;
180
+ expect ( logOutput ) . toBe ( '' ) ;
183
181
} ) ;
184
182
} ) ;
185
183
186
- suite ( 'OmnisharpLaunch' , ( ) => {
184
+ describe ( 'OmnisharpLaunch' , ( ) => {
187
185
[
188
186
{
189
187
event : new OmnisharpLaunch ( '5.8.0' , undefined , true , 'someCommand' , 4 ) ,
@@ -222,39 +220,39 @@ suite('OmnisharpLoggerObserver', () => {
222
220
223
221
test ( `Command and Pid are displayed` , ( ) => {
224
222
observer . post ( event ) ;
225
- expect ( logOutput ) . to . contain ( event . command ) ;
226
- expect ( logOutput ) . to . contain ( event . pid ) ;
223
+ expect ( logOutput ) . toContain ( event . command ) ;
224
+ expect ( logOutput ) . toContain ( event . pid . toString ( ) ) ;
227
225
} ) ;
228
226
229
227
test ( `Message is displayed depending on hostVersion and hostPath value` , ( ) => {
230
228
observer . post ( event ) ;
231
- expect ( logOutput ) . to . contain ( data . expected ) ;
229
+ expect ( logOutput ) . toContain ( data . expected ) ;
232
230
} ) ;
233
231
} ) ;
234
232
} ) ;
235
233
236
- suite ( 'OmnisharpServerOnError' , ( ) => {
234
+ describe ( 'OmnisharpServerOnError' , ( ) => {
237
235
test ( `Doesnot throw error if FileName is null` , ( ) => {
238
236
const event = new OmnisharpServerOnError ( { Text : 'someText' , FileName : null ! , Line : 1 , Column : 2 } ) ;
239
237
const fn = function ( ) {
240
238
observer . post ( event ) ;
241
239
} ;
242
- expect ( fn ) . to . not . throw ( Error ) ;
240
+ expect ( fn ) . not . toThrow ( Error ) ;
243
241
} ) ;
244
242
245
243
[ new OmnisharpServerOnError ( { Text : 'someText' , FileName : 'someFile' , Line : 1 , Column : 2 } ) ] . forEach (
246
244
( event : OmnisharpServerOnError ) => {
247
245
test ( `Contains the error message text` , ( ) => {
248
246
observer . post ( event ) ;
249
- expect ( logOutput ) . to . contain ( event . errorMessage . Text ) ;
247
+ expect ( logOutput ) . toContain ( event . errorMessage . Text ) ;
250
248
} ) ;
251
249
252
250
test ( `Contains the error message FileName, Line and column if FileName is not null` , ( ) => {
253
251
observer . post ( event ) ;
254
252
if ( event . errorMessage . FileName ) {
255
- expect ( logOutput ) . to . contain ( event . errorMessage . FileName ) ;
256
- expect ( logOutput ) . to . contain ( event . errorMessage . Line ) ;
257
- expect ( logOutput ) . to . contain ( event . errorMessage . Column ) ;
253
+ expect ( logOutput ) . toContain ( event . errorMessage . FileName ) ;
254
+ expect ( logOutput ) . toContain ( event . errorMessage . Line . toString ( ) ) ;
255
+ expect ( logOutput ) . toContain ( event . errorMessage . Column . toString ( ) ) ;
258
256
}
259
257
} ) ;
260
258
}
0 commit comments