Skip to content

Commit e7ec2c2

Browse files
authored
Fix background task provider tests on windows (#21887)
1 parent 12cd9d7 commit e7ec2c2

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

extensions/mssql/test/unit/backgroundTasksProvider.test.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import * as os from "os";
67
import * as vscode from "vscode";
78
import * as sinon from "sinon";
89
import sinonChai from "sinon-chai";
@@ -18,6 +19,7 @@ import {
1819
import { initializeIconUtils } from "./utils";
1920

2021
chai.use(sinonChai);
22+
const tooltipLineSeparator = `${os.EOL}${os.EOL}`;
2123

2224
suite("Background Tasks Provider Tests", () => {
2325
let sandbox: sinon.SinonSandbox;
@@ -69,7 +71,9 @@ suite("Background Tasks Provider Tests", () => {
6971
expect(node.label).to.equal("Import complete");
7072
expect(node.description).to.equal("100% | localhost/AdventureWorks2022 | 5s");
7173
expect(node.tooltip).to.equal(
72-
"Import finished\n\nIn progress\n\nCompleted successfully\n\nElapsed time: 5s",
74+
["Import finished", "In progress", "Completed successfully", "Elapsed time: 5s"].join(
75+
tooltipLineSeparator,
76+
),
7377
);
7478
expect((node.iconPath as vscode.ThemeIcon).id).to.equal("pass");
7579
});
@@ -91,7 +95,9 @@ suite("Background Tasks Provider Tests", () => {
9195
expect(nodes).to.have.length(1);
9296
expect(node.description).to.equal("3s");
9397
expect(node.contextValue).to.contain("completed=true");
94-
expect(node.tooltip).to.equal("Exporting\n\nSucceeded\n\nDone\n\nElapsed time: 3s");
98+
expect(node.tooltip).to.equal(
99+
["Exporting", "Succeeded", "Done", "Elapsed time: 3s"].join(tooltipLineSeparator),
100+
);
95101
expect((node.iconPath as vscode.ThemeIcon).id).to.equal("pass");
96102
expect((node.iconPath as vscode.ThemeIcon).color?.id).to.equal("testing.iconPassed");
97103
});
@@ -110,12 +116,15 @@ suite("Background Tasks Provider Tests", () => {
110116
const node = provider.getChildren()[0] as BackgroundTaskNode;
111117

112118
expect(node.description).to.equal("250ms");
113-
expect(node.tooltip).to.equal("Running\n\nFailed\n\nFailed badly\n\nElapsed time: 250ms");
119+
expect(node.tooltip).to.equal(
120+
["Running", "Failed", "Failed badly", "Elapsed time: 250ms"].join(tooltipLineSeparator),
121+
);
114122
expect((node.iconPath as vscode.ThemeIcon).id).to.equal("error");
115123
expect((node.iconPath as vscode.ThemeIcon).color?.id).to.equal("testing.iconFailed");
116124
});
117125

118126
test("canceled tasks use the canceled theme icon", () => {
127+
sandbox.useFakeTimers();
119128
const provider = new BackgroundTasksProvider();
120129
const handle = provider.backgroundTasksService.registerTask({
121130
displayText: "Canceled task",
@@ -127,7 +136,9 @@ suite("Background Tasks Provider Tests", () => {
127136
const node = provider.getChildren()[0] as BackgroundTaskNode;
128137

129138
expect(node.tooltip).to.equal(
130-
"Running\n\nCanceled\n\nStopped by user\n\nElapsed time: 0ms",
139+
["Running", "Canceled", "Stopped by user", "Elapsed time: 0ms"].join(
140+
tooltipLineSeparator,
141+
),
131142
);
132143
expect((node.iconPath as vscode.ThemeIcon).id).to.equal("circle-slash");
133144
});
@@ -148,7 +159,9 @@ suite("Background Tasks Provider Tests", () => {
148159

149160
node = provider.getChildren()[0] as BackgroundTaskNode;
150161
expect(node.description).to.equal("1m 5s");
151-
expect(node.tooltip).to.equal("Working\n\nIn progress\n\nElapsed time: 01:05");
162+
expect(node.tooltip).to.equal(
163+
["Working", "In progress", "Elapsed time: 01:05"].join(tooltipLineSeparator),
164+
);
152165
});
153166

154167
test("clearFinished removes only completed tasks", () => {
@@ -248,6 +261,7 @@ suite("Background Tasks Provider Tests", () => {
248261
});
249262

250263
test("cancel command restores task state when the cancel callback fails", async () => {
264+
sandbox.useFakeTimers();
251265
const provider = new BackgroundTasksProvider();
252266
const cancelError = new Error("cancel failed");
253267
const handle = provider.backgroundTasksService.registerTask({
@@ -268,8 +282,8 @@ suite("Background Tasks Provider Tests", () => {
268282

269283
expect(actualError).to.equal(cancelError);
270284
const refreshedNode = provider.getChildren()[0] as BackgroundTaskNode;
271-
expect(refreshedNode.tooltip).to.match(
272-
/^Cancelable\n\nIn progress\n\nElapsed time: \d+ms$/,
285+
expect(refreshedNode.tooltip).to.equal(
286+
["Cancelable", "In progress", "Elapsed time: 0ms"].join(tooltipLineSeparator),
273287
);
274288
expect(refreshedNode.contextValue).to.contain("cancelable=true");
275289
handle.remove();

0 commit comments

Comments
 (0)