Skip to content

Commit d73abff

Browse files
authored
Merge pull request #2301 from akshita31/cleanTests
Clean up the tests
2 parents 39ceb4f + 9a0e854 commit d73abff

File tree

1 file changed

+53
-42
lines changed

1 file changed

+53
-42
lines changed

test/unitTests/logging/WarningMessageObserver.test.ts

Lines changed: 53 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import { WarningMessageObserver } from '../../../src/observers/WarningMessageObserver';
77
import { assert, use as chaiUse, expect, should } from 'chai';
88
import { getFakeVsCode, getMSBuildDiagnosticsMessage, getOmnisharpMSBuildProjectDiagnosticsEvent, getOmnisharpServerOnErrorEvent } from '../testAssets/Fakes';
9-
import { BaseEvent } from '../../../src/omnisharp/loggingEvents';
109
import { vscode } from '../../../src/vscodeAdapter';
1110
import { TestScheduler } from 'rxjs/testing/TestScheduler';
1211
import { Observable } from 'rxjs/Observable';
@@ -73,7 +72,12 @@ suite('WarningMessageObserver', () => {
7372
let event = getOmnisharpMSBuildProjectDiagnosticsEvent("someFile",
7473
[getMSBuildDiagnosticsMessage("warningFile", "", "", 0, 0, 0, 0)],
7574
[]);
76-
observer.post(event);
75+
let marble = `a`;
76+
let marble_event_map = { a: event };
77+
let eventList = scheduler.createHotObservable(marble, marble_event_map);
78+
eventList.subscribe(e => observer.post(e));
79+
scheduler.flush();
80+
expect(warningMessages).to.be.empty;
7781
expect(invokedCommand).to.be.undefined;
7882
});
7983

@@ -82,88 +86,95 @@ suite('WarningMessageObserver', () => {
8286
let event = getOmnisharpMSBuildProjectDiagnosticsEvent("someFile",
8387
[getMSBuildDiagnosticsMessage("warningFile", "", "", 0, 0, 0, 0)],
8488
[getMSBuildDiagnosticsMessage("warningFile", "", "", 0, 0, 0, 0)]);
85-
newObserver.post(event);
89+
let marble = `a`;
90+
let marble_event_map = { a: event };
91+
let eventList = scheduler.createHotObservable(marble, marble_event_map);
92+
eventList.subscribe(e => newObserver.post(e));
93+
scheduler.flush();
8694
expect(warningMessages).to.be.empty;
95+
expect(invokedCommand).to.be.undefined;
8796
});
8897

8998
[
90-
getOmnisharpMSBuildProjectDiagnosticsEvent("someFile",
91-
[getMSBuildDiagnosticsMessage("warningFile", "", "", 1, 2, 3, 4)],
92-
[getMSBuildDiagnosticsMessage("errorFile", "", "", 5, 6, 7, 8)]),
93-
getOmnisharpServerOnErrorEvent("someText", "someFile", 1, 2)
94-
].forEach((event: BaseEvent) => {
95-
suite(`${event.constructor.name}`, () => {
96-
99+
{
100+
eventA: getOmnisharpMSBuildProjectDiagnosticsEvent("someFile",
101+
[getMSBuildDiagnosticsMessage("warningFile", "", "", 1, 2, 3, 4)],
102+
[getMSBuildDiagnosticsMessage("errorFile", "", "", 5, 6, 7, 8)]),
103+
104+
eventB: getOmnisharpMSBuildProjectDiagnosticsEvent("BFile",
105+
[getMSBuildDiagnosticsMessage("warningFile", "", "", 1, 2, 3, 4)],
106+
[getMSBuildDiagnosticsMessage("errorFile", "", "", 5, 6, 7, 8)]),
107+
108+
eventC: getOmnisharpMSBuildProjectDiagnosticsEvent("CFile",
109+
[getMSBuildDiagnosticsMessage("warningFile", "", "", 1, 2, 3, 4)],
110+
[getMSBuildDiagnosticsMessage("errorFile", "", "", 5, 6, 7, 8)]),
111+
assertion1: '[1] Some projects have trouble loading. Please review the output for more details.',
112+
assertion2: '[2] Some projects have trouble loading. Please review the output for more details.',
113+
expected: "Some projects have trouble loading. Please review the output for more details.",
114+
command: "o.showOutput"
115+
},
116+
{
117+
eventA: getOmnisharpServerOnErrorEvent("someText1", "someFile1", 1, 2),
118+
eventB: getOmnisharpServerOnErrorEvent("someText2", "someFile2", 1, 2),
119+
eventC: getOmnisharpServerOnErrorEvent("someText3", "someFile3", 1, 2),
120+
assertion1: '[1] Some projects have trouble loading. Please review the output for more details.',
121+
assertion2: '[2] Some projects have trouble loading. Please review the output for more details.',
122+
expected: "Some projects have trouble loading. Please review the output for more details.",
123+
command: "o.showOutput"
124+
}
125+
].forEach(elem => {
126+
suite(`${elem.eventA.constructor.name}`, () => {
97127
test(`When the event is fired then a warning message is displayed`, () => {
98128
let marble = `${timeToMarble(1500)}a`;
99-
let marble_event_map = { a: event };
129+
let marble_event_map = { a: elem.eventA };
100130
let eventList = scheduler.createHotObservable(marble, marble_event_map);
101131
eventList.subscribe(e => observer.post(e));
102-
scheduler.expectObservable(assertionObservable).toBe(`${timeToMarble(3000)}a`, { a: '[1] Some projects have trouble loading. Please review the output for more details.' });
132+
scheduler.expectObservable(assertionObservable).toBe(`${timeToMarble(3000)}a`, { a: elem.assertion1 });
103133
scheduler.flush();
104-
105134
expect(warningMessages.length).to.be.equal(1);
106-
expect(warningMessages[0]).to.be.equal("Some projects have trouble loading. Please review the output for more details.");
135+
expect(warningMessages[0]).to.be.equal(elem.expected);
107136
});
108137

109138
test(`When events are fired rapidly, then they are debounced by 1500 ms`, () => {
110139
let marble = `${timeToMarble(1000)}a${timeToMarble(500)}b${timeToMarble(500)}c`;
111-
112-
let eventB = getOmnisharpMSBuildProjectDiagnosticsEvent("BFile",
113-
[getMSBuildDiagnosticsMessage("warningFile", "", "", 1, 2, 3, 4)],
114-
[getMSBuildDiagnosticsMessage("errorFile", "", "", 5, 6, 7, 8)]);
115-
116-
let eventC = getOmnisharpMSBuildProjectDiagnosticsEvent("CFile",
117-
[getMSBuildDiagnosticsMessage("warningFile", "", "", 1, 2, 3, 4)],
118-
[getMSBuildDiagnosticsMessage("errorFile", "", "", 5, 6, 7, 8)]);
119-
120-
let marble_event_map = { a: event, b: eventB, c: eventC };
140+
let marble_event_map = { a: elem.eventA, b: elem.eventB, c: elem.eventC };
121141
let eventList = scheduler.createHotObservable(marble, marble_event_map);
122142
eventList.subscribe(e => observer.post(e));
123-
scheduler.expectObservable(assertionObservable).toBe(`${timeToMarble(3520)}a`, { a: '[1] Some projects have trouble loading. Please review the output for more details.' });
143+
scheduler.expectObservable(assertionObservable).toBe(`${timeToMarble(3520)}a`, { a: elem.assertion1 });
124144
scheduler.flush();
125145

126146
expect(warningMessages.length).to.be.equal(1);
127-
expect(warningMessages[0]).to.be.equal("Some projects have trouble loading. Please review the output for more details.");
147+
expect(warningMessages[0]).to.be.equal(elem.expected);
128148
});
129149

130150
test(`When events are 1500 ms apart, then they are not debounced`, () => {
131151
let marble = `${timeToMarble(1000)}a${timeToMarble(490)}b${timeToMarble(1500)}c`;
132-
133-
let eventB = getOmnisharpMSBuildProjectDiagnosticsEvent("BFile",
134-
[getMSBuildDiagnosticsMessage("warningFile", "", "", 1, 2, 3, 4)],
135-
[getMSBuildDiagnosticsMessage("errorFile", "", "", 5, 6, 7, 8)]);
136-
137-
let eventC = getOmnisharpMSBuildProjectDiagnosticsEvent("CFile",
138-
[getMSBuildDiagnosticsMessage("warningFile", "", "", 1, 2, 3, 4)],
139-
[getMSBuildDiagnosticsMessage("errorFile", "", "", 5, 6, 7, 8)]);
140-
141-
let marble_event_map = { a: event, b: eventB, c: eventC };
152+
let marble_event_map = { a: elem.eventA, b: elem.eventB, c: elem.eventC };
142153
let eventList = scheduler.createHotObservable(marble, marble_event_map);
143154
eventList.subscribe(e => observer.post(e));
144155
scheduler.expectObservable(assertionObservable).toBe(`${timeToMarble(3000)}a${timeToMarble(1500)}b`,
145156
{
146-
a: '[1] Some projects have trouble loading. Please review the output for more details.',
147-
b: '[2] Some projects have trouble loading. Please review the output for more details.'
157+
a: elem.assertion1,
158+
b: elem.assertion2
148159
});
149160
scheduler.flush();
150161
expect(warningMessages.length).to.be.equal(2);
151-
expect(warningMessages[0]).to.be.equal("Some projects have trouble loading. Please review the output for more details.");
162+
expect(warningMessages[0]).to.be.equal(elem.expected);
152163
});
153164

154165
test(`Given a warning message, when the user clicks ok the command is executed`, async () => {
155166
let marble = `${timeToMarble(1500)}a`;
156-
let eventList = scheduler.createHotObservable(marble, { a: event });
167+
let eventList = scheduler.createHotObservable(marble, { a: elem.eventA });
157168
scheduler.expectObservable(eventList.map(e => observer.post(e)));
158169
scheduler.flush();
159170
doClickOk();
160171
await commandDone;
161-
expect(invokedCommand).to.be.equal("o.showOutput");
172+
expect(invokedCommand).to.be.equal(elem.command);
162173
});
163174

164175
test(`Given a warning message, when the user clicks cancel the command is not executed`, async () => {
165176
let marble = `${timeToMarble(1500)}a--|`;
166-
let eventList = scheduler.createHotObservable(marble, { a: event });
177+
let eventList = scheduler.createHotObservable(marble, { a: elem.eventA });
167178
scheduler.expectObservable(eventList.map(e => observer.post(e)));
168179
scheduler.flush();
169180
doClickCancel();

0 commit comments

Comments
 (0)