Skip to content

Commit 763f136

Browse files
committed
Test auto-updating from the version of Compass that was just packaged
1 parent a1610c2 commit 763f136

File tree

5 files changed

+154
-4
lines changed

5 files changed

+154
-4
lines changed

package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-e2e-tests/helpers/selectors.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,3 +1426,12 @@ export const GlobalWrites = {
14261426
SampleFindingDocuments: '[data-testid="sample-finding-documents"]',
14271427
SampleInsertingDocuments: '[data-testid="sample-inserting-documents"]',
14281428
};
1429+
1430+
// Auto-update toasts
1431+
export const AutoUpdateToast = '[data-testid="toast-compass-update"]';
1432+
export const AutoUpdateRestartButton =
1433+
'[data-testid="auto-update-restart-button"]';
1434+
export const AutoUpdateDownloadLink =
1435+
'[data-testid="auto-update-download-link"]';
1436+
export const AutoUpdateReleaseNotesLink =
1437+
'[data-testid="auto-update-release-notes-link"]';
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { expect } from 'chai';
2+
import {
3+
init,
4+
cleanup,
5+
Selectors,
6+
screenshotPathName,
7+
} from '../helpers/compass';
8+
9+
describe('Auto-update', function () {
10+
it('auto-update from', async function () {
11+
if (process.env.TEST_NAME !== 'AUTO_UPDATE_FROM') {
12+
// we don't want this test to execute along with all the others under
13+
// normal circumstances because it is destructive - it overwrites Compass
14+
// itself
15+
this.skip();
16+
}
17+
18+
// run the app and wait for it to auto-update
19+
console.log('starting compass the first time');
20+
const compass = await init('auto-update from', { firstRun: true });
21+
const { browser } = compass;
22+
try {
23+
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
24+
25+
if (process.env.AUTO_UPDATE_UPDATABLE === 'true') {
26+
const restartButton = browser.$(Selectors.AutoUpdateRestartButton);
27+
await restartButton.waitForDisplayed();
28+
29+
// We could click the restart button to apply the update and restart the
30+
// app, but restarting the app confuses webdriverio or at least our test
31+
// helpers. So we're going to just restart the app manually.
32+
await browser.pause(1000);
33+
} else {
34+
// When auto-update is not supported the toast contains a link to
35+
// download
36+
const linkElement = browser.$(Selectors.AutoUpdateDownloadLink);
37+
await linkElement.waitForDisplayed();
38+
expect(await linkElement.getAttribute('href')).to.equal(
39+
'https://www.mongodb.com/try/download/compass'
40+
);
41+
}
42+
} finally {
43+
await browser.screenshot(screenshotPathName('auto-update-from'));
44+
await cleanup(compass);
45+
}
46+
47+
if (process.env.AUTO_UPDATE_UPDATABLE === 'true') {
48+
console.log('starting compass a second time');
49+
// run the app again and check that the version changed
50+
const compass = await init('auto-update from restart', {
51+
firstRun: false,
52+
});
53+
const { browser } = compass;
54+
try {
55+
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
56+
await browser
57+
.$(Selectors.AutoUpdateReleaseNotesLink)
58+
.waitForDisplayed();
59+
} finally {
60+
await browser.screenshot(
61+
screenshotPathName('auto-update-from-restart')
62+
);
63+
await cleanup(compass);
64+
}
65+
}
66+
});
67+
});

packages/compass-smoke-tests/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@
3434
"@mongodb-js/eslint-config-compass": "^1.2.1",
3535
"@mongodb-js/prettier-config-compass": "^1.1.1",
3636
"@mongodb-js/tsconfig-compass": "^1.1.1",
37+
"cross-spawn": "^7.0.5",
3738
"depcheck": "^1.4.1",
3839
"eslint": "^7.25.0",
3940
"hadron-build": "^25.6.1",
4041
"lodash": "^4.17.21",
4142
"prettier": "^2.7.1",
43+
"tree-kill": "^1.2.2",
4244
"typescript": "^5.0.4",
4345
"yargs": "^17.7.2"
4446
}

packages/compass-smoke-tests/src/cli.ts

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import assert from 'node:assert/strict';
33
import fs from 'node:fs';
44
import path from 'node:path';
55

6+
import crossSpawn from 'cross-spawn';
7+
import kill from 'tree-kill';
68
import yargs from 'yargs';
79
import { hideBin } from 'yargs/helpers';
810
import { pick } from 'lodash';
@@ -175,7 +177,9 @@ async function run() {
175177
])
176178
);
177179

178-
const { kind, buildInfo, filepath } = await getTestSubject(context);
180+
const { kind, buildInfo, filepath, autoUpdatable } = await getTestSubject(
181+
context
182+
);
179183
const install = getInstaller(kind);
180184

181185
try {
@@ -188,7 +192,25 @@ async function run() {
188192
});
189193

190194
try {
191-
runTest({ appName, appPath });
195+
const server = startAutoUpdateServer({
196+
allowDowngrades: true,
197+
port: 8080,
198+
});
199+
try {
200+
runTest({
201+
appName,
202+
appPath,
203+
autoUpdatable,
204+
testName: 'AUTO_UPDATE_FROM',
205+
});
206+
} finally {
207+
if (server.pid) {
208+
console.log('Stopping auto-update server');
209+
kill(server.pid, 'SIGINT');
210+
} else {
211+
console.log('cannnot stop auto-update server because no pid');
212+
}
213+
}
192214
} finally {
193215
await uninstall();
194216
}
@@ -198,12 +220,55 @@ async function run() {
198220
}
199221
}
200222

223+
type AutoUpdateServerOptions = {
224+
port: number;
225+
allowDowngrades?: boolean;
226+
};
227+
228+
function startAutoUpdateServer({
229+
port,
230+
allowDowngrades,
231+
}: AutoUpdateServerOptions) {
232+
const env: Record<string, string> = {
233+
...process.env,
234+
PORT: port.toString(),
235+
};
236+
if (allowDowngrades) {
237+
env.UPDATE_CHECKER_ALLOW_DOWNGRADES = 'true';
238+
}
239+
240+
// a git repo that is not published to npm that evergreen clones for us in CI
241+
// next to the Compass code
242+
const cwd = path.join(
243+
__dirname,
244+
'..',
245+
'..',
246+
'..',
247+
'..',
248+
'compass-mongodb-com'
249+
);
250+
251+
if (!fs.existsSync(cwd)) {
252+
throw new Error(`compass-mongodb-com does not exist: ${cwd}`);
253+
}
254+
255+
console.log('Starting auto-update server');
256+
return crossSpawn('npm', ['run', 'start'], { env, cwd, shell: true });
257+
}
258+
201259
type RunTestOptions = {
202260
appName: string;
203261
appPath: string;
262+
autoUpdatable?: boolean;
263+
testName: string;
204264
};
205265

206-
function runTest({ appName, appPath }: RunTestOptions) {
266+
function runTest({
267+
appName,
268+
appPath,
269+
autoUpdatable,
270+
testName,
271+
}: RunTestOptions) {
207272
execute(
208273
'npm',
209274
[
@@ -213,11 +278,14 @@ function runTest({ appName, appPath }: RunTestOptions) {
213278
'--workspace',
214279
'compass-e2e-tests',
215280
'--',
216-
'--test-filter=time-to-first-query',
281+
'--test-filter=auto-update',
217282
],
218283
{
219284
env: {
220285
...process.env,
286+
HADRON_AUTO_UPDATE_ENDPOINT_OVERRIDE: 'http://localhost:8080',
287+
AUTO_UPDATE_UPDATABLE: (!!autoUpdatable).toString(),
288+
TEST_NAME: testName,
221289
COMPASS_APP_NAME: appName,
222290
COMPASS_APP_PATH: appPath,
223291
},

0 commit comments

Comments
 (0)