Skip to content

Commit 6b2148a

Browse files
committed
Test auto-updating from the version of Compass that was just packaged
1 parent fa77bbb commit 6b2148a

File tree

13 files changed

+302
-15
lines changed

13 files changed

+302
-15
lines changed

.evergreen/buildvariants-and-tasks.in.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ tasks:
469469
- func: bootstrap
470470
vars:
471471
scope: 'compass-e2e-tests'
472+
- func: get-compass-mongodb-com
472473
- func: smoketest-packaged-app
473474
vars:
474475
mongodb_version: latest-enterprise

.evergreen/buildvariants-and-tasks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ tasks:
495495
- func: bootstrap
496496
vars:
497497
scope: compass-e2e-tests
498+
- func: get-compass-mongodb-com
498499
- func: smoketest-packaged-app
499500
vars:
500501
mongodb_version: latest-enterprise

.evergreen/functions.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,36 @@ functions:
648648
649649
npm run --unsafe-perm --workspace compass-e2e-tests test-packaged-ci
650650
651+
get-compass-mongodb-com:
652+
- command: github.generate_token
653+
params:
654+
owner: 10gen
655+
repo: compass-mongodb-com
656+
expansion_name: generated_token
657+
permissions: # optional
658+
contents: read
659+
- command: shell.exec
660+
type: setup
661+
params:
662+
working_dir: src
663+
shell: bash
664+
env:
665+
<<: *compass-env
666+
script: |
667+
set -e
668+
eval $(.evergreen/print-compass-env.sh)
669+
git clone https://x-access-token:${generated_token}@github.com/10gen/compass-mongodb-com.git ../compass-mongodb-com
670+
cd ../compass-mongodb-com
671+
echo "Using node version:";
672+
node -v;
673+
echo "Using npm version:";
674+
npm -v;
675+
echo "Using gcc version:"
676+
gcc --version;
677+
echo "Using g++ version:"
678+
g++ --version;
679+
npm ci --engine-strict=false
680+
651681
smoketest-packaged-app:
652682
- command: shell.exec
653683
# Fail the task if it's idle for 10 mins
@@ -676,8 +706,8 @@ functions:
676706
if [[ "$IS_OSX" == "true" ]]; then
677707
echo "Disabling clipboard usage in e2e tests (TODO: https://jira.mongodb.org/browse/BUILD-14780)"
678708
export COMPASS_E2E_DISABLE_CLIPBOARD_USAGE="true"
679-
npm run --unsafe-perm --workspace @mongodb-js/compass-smoke-tests start -- --package=osx_dmg
680709
npm run --unsafe-perm --workspace @mongodb-js/compass-smoke-tests start -- --package=osx_zip
710+
npm run --unsafe-perm --workspace @mongodb-js/compass-smoke-tests start -- --package=osx_dmg
681711
fi
682712
683713
#if [[ "$IS_UBUNTU" == "true" ]]; then

.evergreen/preinstall.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ echo "APPDATA: $APPDATA"
1313
echo "PATH: $PATH"
1414

1515
# these are super useful if you want to run the smoke tests locally
16-
echo "DEV_VERSION_IDENTIFIER: $DEV_VERSION_IDENTIFIER"
17-
echo "EVERGREEN_BUCKET_NAME: $EVERGREEN_BUCKET_NAME"
18-
echo "EVERGREEN_BUCKET_KEY_PREFIX: $EVERGREEN_BUCKET_KEY_PREFIX"
16+
echo "export DEV_VERSION_IDENTIFIER=$DEV_VERSION_IDENTIFIER"
17+
echo "export EVERGREEN_BUCKET_KEY_PREFIX=$EVERGREEN_BUCKET_KEY_PREFIX"
18+
echo "export EVERGREEN_BUCKET_NAME=$EVERGREEN_BUCKET_NAME"
1919

2020
echo "IS_OSX: $IS_OSX"
2121
echo "IS_LINUX: $IS_LINUX"

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
@@ -1380,3 +1380,12 @@ export const GlobalWrites = {
13801380
SampleFindingDocuments: '[data-testid="sample-finding-documents"]',
13811381
SampleInsertingDocuments: '[data-testid="sample-inserting-documents"]',
13821382
};
1383+
1384+
// Auto-update toasts
1385+
export const AutoUpdateToast = '[data-testid="toast-compass-update"]';
1386+
export const AutoUpdateRestartButton =
1387+
'[data-testid="auto-update-restart-button"]';
1388+
export const AutoUpdateDownloadLink =
1389+
'[data-testid="auto-update-download-link"]';
1390+
export const AutoUpdateReleaseNotesLink =
1391+
'[data-testid="auto-update-release-notes-link"]';
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import { expect } from 'chai';
4+
import {
5+
init,
6+
cleanup,
7+
Selectors,
8+
screenshotPathName,
9+
} from '../helpers/compass';
10+
import { LOG_PATH } from '../helpers/test-runner-paths';
11+
12+
function wait(ms: number) {
13+
return new Promise((resolve) => {
14+
setTimeout(resolve, ms);
15+
});
16+
}
17+
18+
describe('Auto-update', function () {
19+
it('auto-update from', async function () {
20+
if (process.env.TEST_NAME !== 'AUTO_UPDATE_FROM') {
21+
// we don't want this test to execute along with all the others under
22+
// normal circumstances because it is destructive - it overwrites Compass
23+
// itself
24+
this.skip();
25+
}
26+
27+
// run the app and wait for it to auto-update
28+
console.log('starting compass the first time');
29+
const compass = await init('auto-update from', { firstRun: true });
30+
const { browser } = compass;
31+
try {
32+
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
33+
34+
if (process.env.AUTO_UPDATE_UPDATABLE === 'true') {
35+
const restartButton = browser.$(Selectors.AutoUpdateRestartButton);
36+
await restartButton.waitForDisplayed();
37+
38+
// We could click the restart button to apply the update and restart the
39+
// app, but restarting the app confuses webdriverio or at least our test
40+
// helpers. So we're going to just restart the app manually.
41+
await browser.pause(1000);
42+
} else {
43+
// When auto-update is not supported the toast contains a link to
44+
// download
45+
const linkElement = browser.$(Selectors.AutoUpdateDownloadLink);
46+
await linkElement.waitForDisplayed();
47+
expect(await linkElement.getAttribute('href')).to.equal(
48+
'https://www.mongodb.com/try/download/compass?utm_source=compass&utm_medium=product'
49+
);
50+
}
51+
} finally {
52+
await browser.screenshot(screenshotPathName('auto-update-from'));
53+
await cleanup(compass);
54+
55+
if (process.platform === 'darwin' && process.env.HOME) {
56+
console.log('copying ShipIt dir if it exits');
57+
const shipitDir = path.resolve(
58+
process.env.HOME,
59+
'Library',
60+
'Caches',
61+
'com.mongodb.compass.dev.ShipIt'
62+
);
63+
64+
if (fs.existsSync(shipitDir)) {
65+
console.log(`copying ${shipitDir}`);
66+
fs.cpSync(shipitDir, `${LOG_PATH}/ShipIt`, { recursive: true });
67+
} else {
68+
console.log(`${shipitDir} does not exist`);
69+
}
70+
}
71+
}
72+
73+
if (process.env.AUTO_UPDATE_UPDATABLE === 'true') {
74+
console.log(
75+
'pause to make sure the app properly exited before starting again'
76+
);
77+
await wait(60_000);
78+
79+
console.log('starting compass a second time');
80+
// run the app again and check that the version changed
81+
const compass = await init('auto-update from restart', {
82+
firstRun: false,
83+
});
84+
const { browser } = compass;
85+
try {
86+
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
87+
await browser
88+
.$(Selectors.AutoUpdateReleaseNotesLink)
89+
.waitForDisplayed();
90+
} finally {
91+
await browser.screenshot(
92+
screenshotPathName('auto-update-from-restart')
93+
);
94+
await cleanup(compass);
95+
}
96+
}
97+
});
98+
});

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.5",
3535
"@mongodb-js/prettier-config-compass": "^1.1.5",
3636
"@mongodb-js/tsconfig-compass": "^1.1.5",
37+
"cross-spawn": "^7.0.5",
3738
"depcheck": "^1.4.1",
3839
"eslint": "^7.25.0",
3940
"hadron-build": "^25.6.5",
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: 115 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';
@@ -179,7 +181,9 @@ async function run() {
179181
])
180182
);
181183

182-
const { kind, filepath, appName } = await getTestSubject(context);
184+
const { kind, appName, filepath, autoUpdatable } = await getTestSubject(
185+
context
186+
);
183187
const install = getInstaller(kind);
184188

185189
try {
@@ -190,7 +194,21 @@ async function run() {
190194
});
191195

192196
try {
193-
runTest({ appName, appPath });
197+
if (context.platform === 'darwin' && process.env.CI) {
198+
// Auto-update does not work on mac in CI at the moment. So in that case
199+
// we just run the E2E tests to make sure the app at least starts up.
200+
runE2ETest({
201+
appName,
202+
appPath,
203+
});
204+
} else {
205+
runUpdateTest({
206+
appName,
207+
appPath,
208+
autoUpdatable,
209+
testName: 'AUTO_UPDATE_FROM',
210+
});
211+
}
194212
} finally {
195213
await uninstall();
196214
}
@@ -200,12 +218,53 @@ async function run() {
200218
}
201219
}
202220

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

208-
function runTest({ appName, appPath }: RunTestOptions) {
267+
function runE2ETest({ appName, appPath }: RunE2ETestOptions) {
209268
execute(
210269
'npm',
211270
[
@@ -229,6 +288,58 @@ function runTest({ appName, appPath }: RunTestOptions) {
229288
);
230289
}
231290

291+
type RunUpdateTestOptions = {
292+
appName: string;
293+
appPath: string;
294+
autoUpdatable?: boolean;
295+
testName: string;
296+
};
297+
298+
function runUpdateTest({
299+
appName,
300+
appPath,
301+
autoUpdatable,
302+
testName,
303+
}: RunUpdateTestOptions) {
304+
const server = startAutoUpdateServer({
305+
allowDowngrades: true,
306+
port: 8080,
307+
});
308+
try {
309+
execute(
310+
'npm',
311+
[
312+
'run',
313+
'--unsafe-perm',
314+
'test-packaged',
315+
'--workspace',
316+
'compass-e2e-tests',
317+
'--',
318+
'--test-filter=auto-update',
319+
],
320+
{
321+
// We need to use a shell to get environment variables setup correctly
322+
shell: true,
323+
env: {
324+
...process.env,
325+
HADRON_AUTO_UPDATE_ENDPOINT_OVERRIDE: 'http://localhost:8080',
326+
AUTO_UPDATE_UPDATABLE: (!!autoUpdatable).toString(),
327+
TEST_NAME: testName,
328+
COMPASS_APP_NAME: appName,
329+
COMPASS_APP_PATH: appPath,
330+
},
331+
}
332+
);
333+
} finally {
334+
if (server.pid) {
335+
console.log('Stopping auto-update server');
336+
kill(server.pid, 'SIGINT');
337+
} else {
338+
console.log('cannnot stop auto-update server because no pid');
339+
}
340+
}
341+
}
342+
232343
run()
233344
.then(function () {
234345
console.log('done');

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export function execute(
66
args: string[],
77
options?: SpawnOptions
88
) {
9+
// print the command so that when it outputs to stdout we can see where it
10+
// comes from
11+
console.log(command, args);
12+
913
const { status, signal } = spawnSync(command, args, {
1014
stdio: 'inherit',
1115
...options,

0 commit comments

Comments
 (0)