Skip to content

Commit 1e2ea90

Browse files
committed
Migrate O# logger observer test to fix flakiness
1 parent 0d538d6 commit 1e2ea90

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

omnisharptest/omnisharpUnitTests/logging/omnisharpLoggerObserver.test.ts renamed to omnisharptest/omnisharpJestTests/logging/omnisharpLoggerObserver.test.ts

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* Copyright (c) Microsoft Corporation. All rights reserved.
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
5-
import { should, expect } from 'chai';
65
import { getNullChannel } from '../../../test/unitTests/fakes';
6+
import { describe, test, expect, beforeEach } from '@jest/globals';
77
import { OmnisharpLoggerObserver } from '../../../src/observers/omnisharpLoggerObserver';
88
import {
99
OmnisharpServerMsBuildProjectDiagnostics,
@@ -20,9 +20,7 @@ import {
2020
import { OutputChannel } from 'vscode';
2121
import { PlatformInformation } from '../../../src/shared/platform';
2222

23-
suite('OmnisharpLoggerObserver', () => {
24-
suiteSetup(() => should());
25-
23+
describe('OmnisharpLoggerObserver', () => {
2624
let logOutput = '';
2725
const channel = <OutputChannel>{
2826
...getNullChannel(),
@@ -35,19 +33,19 @@ suite('OmnisharpLoggerObserver', () => {
3533
platform: 'TestOS',
3634
});
3735

38-
setup(() => {
36+
beforeEach(() => {
3937
logOutput = '';
4038
});
4139

42-
suite('OmnisharpServerMsBuildProjectDiagnostics', () => {
40+
describe('OmnisharpServerMsBuildProjectDiagnostics', () => {
4341
test('Logged message is empty if there are no warnings and erros', () => {
4442
const event = new OmnisharpServerMsBuildProjectDiagnostics({
4543
FileName: 'someFile',
4644
Warnings: [],
4745
Errors: [],
4846
});
4947
observer.post(event);
50-
expect(logOutput).to.be.empty;
48+
expect(logOutput).toBe('');
5149
});
5250

5351
test(`Logged message contains the Filename if there is atleast one error or warning`, () => {
@@ -67,7 +65,7 @@ suite('OmnisharpLoggerObserver', () => {
6765
Errors: [],
6866
});
6967
observer.post(event);
70-
expect(logOutput).to.contain(event.diagnostics.FileName);
68+
expect(logOutput).toContain(event.diagnostics.FileName);
7169
});
7270

7371
[
@@ -100,20 +98,20 @@ suite('OmnisharpLoggerObserver', () => {
10098
test(`Logged message contains the Filename, StartColumn, StartLine and Text for the diagnostic warnings`, () => {
10199
observer.post(event);
102100
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);
107105
});
108106
});
109107

110108
test(`Logged message contains the Filename, StartColumn, StartLine and Text for the diagnostics errors`, () => {
111109
observer.post(event);
112110
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);
117115
});
118116
});
119117
});
@@ -123,32 +121,32 @@ suite('OmnisharpLoggerObserver', () => {
123121
(event: EventWithMessage) => {
124122
test(`${event.constructor.name}: Message is logged`, () => {
125123
observer.post(event);
126-
expect(logOutput).to.contain(event.message);
124+
expect(logOutput).toContain(event.message);
127125
});
128126
}
129127
);
130128

131129
test(`OmnisharpServerOnServerError: Message is logged`, () => {
132130
const event = new OmnisharpServerOnServerError('on server error message');
133131
observer.post(event);
134-
expect(logOutput).to.contain(event.err);
132+
expect(logOutput).toContain(event.err);
135133
});
136134

137135
[new OmnisharpInitialisation([], new Date(5), 'somePath')].forEach((event: OmnisharpInitialisation) => {
138136
test(`${event.constructor.name}: TimeStamp and SolutionPath are logged`, () => {
139137
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);
142140
});
143141
});
144142

145143
test('OmnisharpFailure: Failure message is logged', () => {
146144
const event = new OmnisharpFailure('failureMessage', new Error('errorMessage'));
147145
observer.post(event);
148-
expect(logOutput).to.contain(event.message);
146+
expect(logOutput).toContain(event.message);
149147
});
150148

151-
suite('OmnisharpEventPacketReceived', () => {
149+
describe('OmnisharpEventPacketReceived', () => {
152150
[
153151
new OmnisharpEventPacketReceived('TRACE', 'foo', 'someMessage'),
154152
new OmnisharpEventPacketReceived('DEBUG', 'foo', 'someMessage'),
@@ -159,8 +157,8 @@ suite('OmnisharpLoggerObserver', () => {
159157
].forEach((event: OmnisharpEventPacketReceived) => {
160158
test(`${event.logLevel} messages are logged with name and the message`, () => {
161159
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);
164162
});
165163
});
166164

@@ -169,7 +167,7 @@ suite('OmnisharpLoggerObserver', () => {
169167
const fn = function () {
170168
observer.post(event);
171169
};
172-
expect(fn).to.throw(Error);
170+
expect(fn).toThrow(Error);
173171
});
174172

175173
test(`Information messages with name OmniSharp.Middleware.LoggingMiddleware and follow pattern /^/[/w]+: 200 d+ms/ are not logged`, () => {
@@ -179,11 +177,11 @@ suite('OmnisharpLoggerObserver', () => {
179177
'/codecheck: 200 339ms'
180178
);
181179
observer.post(event);
182-
expect(logOutput).to.be.empty;
180+
expect(logOutput).toBe('');
183181
});
184182
});
185183

186-
suite('OmnisharpLaunch', () => {
184+
describe('OmnisharpLaunch', () => {
187185
[
188186
{
189187
event: new OmnisharpLaunch('5.8.0', undefined, true, 'someCommand', 4),
@@ -222,39 +220,39 @@ suite('OmnisharpLoggerObserver', () => {
222220

223221
test(`Command and Pid are displayed`, () => {
224222
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());
227225
});
228226

229227
test(`Message is displayed depending on hostVersion and hostPath value`, () => {
230228
observer.post(event);
231-
expect(logOutput).to.contain(data.expected);
229+
expect(logOutput).toContain(data.expected);
232230
});
233231
});
234232
});
235233

236-
suite('OmnisharpServerOnError', () => {
234+
describe('OmnisharpServerOnError', () => {
237235
test(`Doesnot throw error if FileName is null`, () => {
238236
const event = new OmnisharpServerOnError({ Text: 'someText', FileName: null!, Line: 1, Column: 2 });
239237
const fn = function () {
240238
observer.post(event);
241239
};
242-
expect(fn).to.not.throw(Error);
240+
expect(fn).not.toThrow(Error);
243241
});
244242

245243
[new OmnisharpServerOnError({ Text: 'someText', FileName: 'someFile', Line: 1, Column: 2 })].forEach(
246244
(event: OmnisharpServerOnError) => {
247245
test(`Contains the error message text`, () => {
248246
observer.post(event);
249-
expect(logOutput).to.contain(event.errorMessage.Text);
247+
expect(logOutput).toContain(event.errorMessage.Text);
250248
});
251249

252250
test(`Contains the error message FileName, Line and column if FileName is not null`, () => {
253251
observer.post(event);
254252
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());
258256
}
259257
});
260258
}

0 commit comments

Comments
 (0)