Skip to content

Commit 29090f4

Browse files
lerouxbkraenhansen
andauthored
feat(smoke-tests): test updating from the latest release to the newly packaged app COMPASS-8532 COMPASS-8535 (#6669)
* test updating from the latest release to the newly packaged one * also run this in CI * better type assertions * auto-updating TO doesn't support windows yet because we don't have .exe installer support * the installer to use for the latest release is not necessarily the same as the package * check the text in the toasts * refactor * Update packages/compass-smoke-tests/src/releases.ts Co-authored-by: Kræn Hansen <[email protected]> --------- Co-authored-by: Kræn Hansen <[email protected]>
1 parent e8a3866 commit 29090f4

File tree

13 files changed

+614
-302
lines changed

13 files changed

+614
-302
lines changed

.evergreen/functions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,8 @@ functions:
678678
679679
if [[ "$IS_WINDOWS" == "true" ]]; then
680680
# TODO: windows_setup
681-
npm run --unsafe-perm --workspace @mongodb-js/compass-smoke-tests start -- --package=windows_zip --tests=auto-update-from
682-
npm run --unsafe-perm --workspace @mongodb-js/compass-smoke-tests start -- --package=windows_msi --tests=auto-update-from
681+
npm run --unsafe-perm --workspace @mongodb-js/compass-smoke-tests start -- --package=windows_zip --tests auto-update-from
682+
npm run --unsafe-perm --workspace @mongodb-js/compass-smoke-tests start -- --package=windows_msi --tests auto-update-from
683683
fi
684684
685685
if [[ "$IS_OSX" == "true" ]]; then

packages/compass-e2e-tests/tests/auto-update.test.ts

Lines changed: 82 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,66 +13,94 @@ function wait(ms: number) {
1313
}
1414

1515
describe('Auto-update', function () {
16-
it('auto-update from', async function () {
17-
if (process.env.TEST_NAME !== 'auto-update-from') {
18-
// we don't want this test to execute along with all the others under
19-
// normal circumstances because it is destructive - it overwrites Compass
20-
// itself
21-
this.skip();
22-
}
23-
24-
// run the app and wait for it to auto-update
25-
console.log('starting compass the first time');
26-
const compass = await init('auto-update from', { firstRun: true });
27-
const { browser } = compass;
28-
try {
29-
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
30-
31-
if (process.env.AUTO_UPDATE_UPDATABLE === 'true') {
32-
const restartButton = browser.$(Selectors.AutoUpdateRestartButton);
33-
await restartButton.waitForDisplayed();
34-
35-
// We could click the restart button to apply the update and restart the
36-
// app, but restarting the app confuses webdriverio or at least our test
37-
// helpers. So we're going to just restart the app manually.
38-
await browser.pause(1000);
39-
} else {
40-
// When auto-update is not supported the toast contains a link to
41-
// download
42-
const linkElement = browser.$(Selectors.AutoUpdateDownloadLink);
43-
await linkElement.waitForDisplayed();
44-
expect(await linkElement.getAttribute('href')).to.equal(
45-
'https://www.mongodb.com/try/download/compass?utm_source=compass&utm_medium=product'
46-
);
16+
for (const testName of ['auto-update-from', 'auto-update-to']) {
17+
it(testName, async function () {
18+
if (process.env.TEST_NAME !== testName) {
19+
// we don't want this test to execute along with all the others under
20+
// normal circumstances because it is destructive - it overwrites Compass
21+
// itself
22+
this.skip();
4723
}
48-
} finally {
49-
await browser.screenshot(screenshotPathName('auto-update-from'));
50-
await cleanup(compass);
51-
}
5224

53-
if (process.env.AUTO_UPDATE_UPDATABLE === 'true') {
54-
console.log(
55-
'pause to make sure the app properly exited before starting again'
56-
);
57-
await wait(10_000);
58-
59-
console.log('starting compass a second time');
60-
// run the app again and check that the version changed
61-
const compass = await init('auto-update from restart', {
62-
firstRun: false,
63-
});
25+
// run the app and wait for it to auto-update
26+
console.log('starting compass the first time');
27+
const compass = await init(testName, { firstRun: true });
6428
const { browser } = compass;
6529
try {
6630
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
67-
await browser
68-
.$(Selectors.AutoUpdateReleaseNotesLink)
69-
.waitForDisplayed();
31+
32+
if (process.env.AUTO_UPDATE_UPDATABLE === 'true') {
33+
const restartButton = browser.$(Selectors.AutoUpdateRestartButton);
34+
await restartButton.waitForDisplayed();
35+
36+
if (process.env.EXPECTED_UPDATE_VERSION) {
37+
expect(
38+
await browser.$(Selectors.AutoUpdateToast).getText()
39+
).to.contain(
40+
`Compass is ready to update to ${process.env.EXPECTED_UPDATE_VERSION}!`
41+
);
42+
}
43+
44+
// We could click the restart button to apply the update and restart the
45+
// app, but restarting the app confuses webdriverio or at least our test
46+
// helpers. So we're going to just restart the app manually.
47+
await browser.pause(1000);
48+
} else {
49+
// When auto-update is not supported the toast contains a link to
50+
// download
51+
const linkElement = browser.$(Selectors.AutoUpdateDownloadLink);
52+
await linkElement.waitForDisplayed();
53+
expect(await linkElement.getAttribute('href')).to.equal(
54+
'https://www.mongodb.com/try/download/compass?utm_source=compass&utm_medium=product'
55+
);
56+
57+
if (process.env.EXPECTED_UPDATE_VERSION) {
58+
expect(
59+
await browser.$(Selectors.AutoUpdateToast).getText()
60+
).to.contain(
61+
`Compass ${process.env.EXPECTED_UPDATE_VERSION} is available`
62+
);
63+
}
64+
}
7065
} finally {
71-
await browser.screenshot(
72-
screenshotPathName('auto-update-from-restart')
73-
);
66+
await browser.screenshot(screenshotPathName(testName));
7467
await cleanup(compass);
7568
}
76-
}
77-
});
69+
70+
if (process.env.AUTO_UPDATE_UPDATABLE === 'true') {
71+
console.log(
72+
'pause to make sure the app properly exited before starting again'
73+
);
74+
await wait(10_000);
75+
76+
console.log('starting compass a second time');
77+
// run the app again and check that the version changed
78+
const compass = await init(`${testName} restart`, {
79+
firstRun: false,
80+
});
81+
const { browser } = compass;
82+
try {
83+
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
84+
const releaseNotesLink = browser.$(
85+
Selectors.AutoUpdateReleaseNotesLink
86+
);
87+
await releaseNotesLink.waitForDisplayed();
88+
// for now we only know the new version in the auto-update-to case
89+
if (process.env.EXPECTED_UPDATE_VERSION) {
90+
expect(
91+
await browser.$(Selectors.AutoUpdateToast).getText()
92+
).to.contain(
93+
`Compass ${process.env.EXPECTED_UPDATE_VERSION} installed successfully`
94+
);
95+
expect(await releaseNotesLink.getAttribute('href')).to.equal(
96+
`https://github.com/mongodb-js/compass/releases/tag/v${process.env.EXPECTED_UPDATE_VERSION}`
97+
);
98+
}
99+
} finally {
100+
await browser.screenshot(screenshotPathName(`${testName}-restart`));
101+
await cleanup(compass);
102+
}
103+
}
104+
});
105+
}
78106
});

packages/compass-smoke-tests/src/build-info.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ import path from 'node:path';
55
import { handler as writeBuildInfo } from 'hadron-build/commands/info';
66

77
import { type PackageKind } from './packages';
8-
import { type SmokeTestsContext } from './context';
8+
import { type SmokeTestsContextWithSandbox } from './context';
99
import { pick } from 'lodash';
1010

11-
function assertObjectHasKeys(
12-
obj: unknown,
13-
name: string,
14-
keys: readonly string[]
15-
) {
11+
const SUPPORTED_CHANNELS = ['dev', 'beta', 'stable'] as const;
12+
13+
export type Channel = typeof SUPPORTED_CHANNELS[number];
14+
15+
function assertObjectHasKeys<
16+
Keys extends readonly string[],
17+
Obj extends Record<Keys[number], unknown>
18+
>(obj: unknown, name: string, keys: Keys): asserts obj is Obj {
1619
assert(
1720
typeof obj === 'object' && obj !== null,
18-
'Expected buildInfo to be an object'
21+
`Expected ${name} to be an object`
1922
);
2023

2124
for (const key of keys) {
@@ -25,13 +28,21 @@ function assertObjectHasKeys(
2528

2629
// subsets of the hadron-build info result
2730

28-
export const commonKeys = ['productName'] as const;
29-
export type CommonBuildInfo = Record<typeof commonKeys[number], string>;
31+
export const commonKeys = ['productName', 'version', 'channel'] as const;
32+
export type CommonBuildInfo = Record<typeof commonKeys[number], string> & {
33+
channel: Channel;
34+
};
3035

3136
export function assertCommonBuildInfo(
3237
buildInfo: unknown
3338
): asserts buildInfo is CommonBuildInfo {
3439
assertObjectHasKeys(buildInfo, 'buildInfo', commonKeys);
40+
assert(
41+
SUPPORTED_CHANNELS.includes(buildInfo.channel as Channel),
42+
`Expected ${JSON.stringify(
43+
buildInfo.channel
44+
)} to be in ${SUPPORTED_CHANNELS.join(',')}`
45+
);
3546
}
3647

3748
export const windowsFilenameKeys = [
@@ -221,7 +232,7 @@ export function readPackageDetails(
221232
}
222233

223234
export function writeAndReadPackageDetails(
224-
context: SmokeTestsContext
235+
context: SmokeTestsContextWithSandbox
225236
): PackageDetails {
226237
const compassDir = path.resolve(__dirname, '../../compass');
227238
const infoArgs = {

0 commit comments

Comments
 (0)