-
Notifications
You must be signed in to change notification settings - Fork 547
Expand file tree
/
Copy pathUpdatePowerShell.test.ts
More file actions
149 lines (136 loc) · 5.81 KB
/
UpdatePowerShell.test.ts
File metadata and controls
149 lines (136 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import assert from "assert";
import * as vscode from "vscode";
import { UpdatePowerShell } from "../../src/features/UpdatePowerShell";
import type { IPowerShellVersionDetails } from "../../src/session";
import { changeSetting } from "../../src/settings";
import { testLogger } from "../utils";
describe("UpdatePowerShell feature", function () {
let currentUpdateSetting: string | undefined;
before(function () {
currentUpdateSetting = process.env.POWERSHELL_UPDATECHECK;
});
beforeEach(function () {
process.env.POWERSHELL_UPDATECHECK = "Default";
});
after(function () {
process.env.POWERSHELL_UPDATECHECK = currentUpdateSetting;
});
describe("When it should check for an update", function () {
it("Won't check if 'promptToUpdatePowerShell' is false", async function () {
await changeSetting(
"promptToUpdatePowerShell",
false,
vscode.ConfigurationTarget.Workspace,
undefined,
);
try {
const version: IPowerShellVersionDetails = {
version: "7.3.0",
edition: "Core",
commit: "7.3.0",
architecture: "X64",
};
const updater = new UpdatePowerShell(testLogger, version);
// @ts-expect-error method is private.
assert(!updater.shouldCheckForUpdate());
} finally {
await changeSetting(
"promptToUpdatePowerShell",
undefined,
vscode.ConfigurationTarget.Workspace,
undefined,
);
}
});
it("Won't check for Windows PowerShell", function () {
const version: IPowerShellVersionDetails = {
version: "5.1.22621",
edition: "Desktop",
commit: "5.1.22621",
architecture: "X64",
};
const updater = new UpdatePowerShell(testLogger, version);
// @ts-expect-error method is private.
assert(!updater.shouldCheckForUpdate());
});
it("Won't check for a development build of PowerShell", function () {
const version: IPowerShellVersionDetails = {
version: "7.3.0-preview.3",
edition: "Core",
commit: "7.3.0-preview.3-508-g07175ae0ff8eb7306fe0b0fc7d19bdef4fbf2d67",
architecture: "Arm64",
};
const updater = new UpdatePowerShell(testLogger, version);
// @ts-expect-error method is private.
assert(!updater.shouldCheckForUpdate());
});
it("Won't check for a daily build of PowerShell", function () {
const version: IPowerShellVersionDetails = {
version: "7.3.0-daily20221206.1",
edition: "Core",
commit: "7.3.0-daily20221206.1",
architecture: "Arm64",
};
const updater = new UpdatePowerShell(testLogger, version);
// @ts-expect-error method is private.
assert(!updater.shouldCheckForUpdate());
});
it("Won't check if POWERSHELL_UPDATECHECK is 'Off'", function () {
process.env.POWERSHELL_UPDATECHECK = "Off";
const version: IPowerShellVersionDetails = {
version: "7.3.0",
edition: "Core",
commit: "7.3.0",
architecture: "X64",
};
const updater = new UpdatePowerShell(testLogger, version);
// @ts-expect-error method is private.
assert(!updater.shouldCheckForUpdate());
});
it("Should otherwise check to update PowerShell", function () {
const version: IPowerShellVersionDetails = {
version: "7.3.0",
edition: "Core",
commit: "7.3.0",
architecture: "X64",
};
const updater = new UpdatePowerShell(testLogger, version);
// @ts-expect-error method is private.
assert(updater.shouldCheckForUpdate());
});
});
describe("Which version it gets", function () {
it("Would update to LTS", async function () {
process.env.POWERSHELL_UPDATECHECK = "LTS";
const version: IPowerShellVersionDetails = {
version: "7.2.0",
edition: "Core",
commit: "7.2.0",
architecture: "X64",
};
const updater = new UpdatePowerShell(testLogger, version);
// @ts-expect-error method is private.
const tag: string = (await updater.maybeGetNewRelease()) ?? "";
// NOTE: This will need to be updated each time an LTS is released.
// Also sometimes the prior LTS is more recently updated than the latest LTS.
assert(tag.startsWith("v7.4"));
});
it("Would update to stable", async function () {
const version: IPowerShellVersionDetails = {
version: "7.3.0",
edition: "Core",
commit: "7.3.0",
architecture: "X64",
};
const updater = new UpdatePowerShell(testLogger, version);
// @ts-expect-error method is private.
const tag: string | undefined = await updater.maybeGetNewRelease();
// NOTE: This will need to be updated each new major stable.
// TODO: Upstream bug causes LTS releases to update the stable info.
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
assert(tag?.startsWith("v7.6") || tag?.startsWith("v7.4"));
});
});
});