-
Notifications
You must be signed in to change notification settings - Fork 510
/
Copy pathUpdatePowerShell.test.ts
133 lines (120 loc) · 5.25 KB
/
UpdatePowerShell.test.ts
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import assert from "assert";
import { UpdatePowerShell } from "../../src/features/UpdatePowerShell";
import { Settings } from "../../src/settings";
import { IPowerShellVersionDetails } from "../../src/session";
import { testLogger } from "../utils";
describe("UpdatePowerShell feature", function () {
let currentUpdateSetting: string | undefined;
const settings = new Settings();
before(function () {
currentUpdateSetting = process.env.POWERSHELL_UPDATECHECK;
});
beforeEach(function () {
settings.promptToUpdatePowerShell = true;
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", function () {
settings.promptToUpdatePowerShell = false;
const version: IPowerShellVersionDetails = {
"version": "7.3.0",
"edition": "Core",
"commit": "7.3.0",
"architecture": "X64"
};
const updater = new UpdatePowerShell(settings, testLogger, version);
// @ts-expect-error method is private.
assert(!updater.shouldCheckForUpdate());
});
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(settings, 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(settings, 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(settings, 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(settings, 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(settings, 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.0.0",
"edition": "Core",
"commit": "7.0.0",
"architecture": "X64"
};
const updater = new UpdatePowerShell(settings, 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 LTS.
assert(tag?.startsWith("v7.2"));
});
it("Would update to stable", async function() {
const version: IPowerShellVersionDetails = {
"version": "7.0.0",
"edition": "Core",
"commit": "7.0.0",
"architecture": "X64"
};
const updater = new UpdatePowerShell(settings, 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.
assert(tag?.startsWith("v7.3"));
});
});
});