Skip to content

Commit f2dc6cf

Browse files
committed
test that you can auto-update from the just-packaged version
1 parent 747d2da commit f2dc6cf

File tree

4 files changed

+111
-71
lines changed

4 files changed

+111
-71
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@ export function execute(
88
): Promise<void> {
99
return new Promise((resolve, reject) => {
1010
console.log(command, ...args);
11+
1112
const p = spawn(command, args, {
1213
stdio: 'inherit',
1314
...options,
1415
});
16+
1517
p.on('error', (err: any) => {
1618
reject(err);
1719
});
20+
1821
p.on('close', (code: number | null, signal: NodeJS.Signals | null) => {
22+
process.off('exit', killChild);
23+
process.off('SIGINT', interruptChild);
24+
1925
if (code !== null) {
2026
if (code === 0) {
2127
resolve();
@@ -41,5 +47,11 @@ export function execute(
4147
}
4248
}
4349
});
50+
51+
// Exit child process if main process exits
52+
const killChild = () => p.kill();
53+
const interruptChild = () => p.kill('SIGINT');
54+
process.once('exit', killChild);
55+
process.once('SIGINT', interruptChild);
4456
});
4557
}

packages/compass-e2e-tests/smoke-test.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -284,33 +284,6 @@ async function downloadFile(url: string, targetFile: string): Promise<void> {
284284
});
285285
}
286286

287-
/*
288-
function testInstalledApp(
289-
pkg: Package,
290-
appInfo: InstalledAppInfo
291-
): Promise<void> {
292-
return execute(
293-
'npm',
294-
[
295-
'run',
296-
'--unsafe-perm',
297-
'test-packaged',
298-
'--workspace',
299-
'compass-e2e-tests',
300-
'--',
301-
'--test-filter=time-to-first-query',
302-
],
303-
{
304-
env: {
305-
...process.env,
306-
COMPASS_APP_NAME: pkg.appName,
307-
COMPASS_APP_PATH: appInfo.appPath,
308-
},
309-
}
310-
);
311-
}
312-
*/
313-
314287
run()
315288
.then(function () {
316289
console.log('done');

packages/compass-e2e-tests/smoketests/auto-update-from.ts

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
1-
import { expect } from 'chai';
2-
import {
3-
init,
4-
cleanup,
5-
//screenshotIfFailed,
6-
Selectors,
7-
} from '../helpers/compass';
8-
1+
import { execute } from '../installers/helpers';
92
import type { Package } from '../installers/types';
103

4+
function testInstalledApp(
5+
pkg: Package,
6+
appPath: string,
7+
env: Record<string, string>
8+
): Promise<void> {
9+
return execute(
10+
'npm',
11+
[
12+
'run',
13+
'--unsafe-perm',
14+
'test-packaged',
15+
'--workspace',
16+
'compass-e2e-tests',
17+
'--',
18+
'--test-filter=auto-update',
19+
],
20+
{
21+
env: {
22+
...process.env,
23+
HADRON_AUTO_UPDATE_ENDPOINT_OVERRIDE: 'http://localhost:8080',
24+
AUTO_UPDATE_UPDATABLE: pkg.updatable.toString(),
25+
COMPASS_APP_NAME: pkg.appName,
26+
COMPASS_APP_PATH: appPath,
27+
...env,
28+
},
29+
}
30+
);
31+
}
32+
1133
export async function testAutoUpdateFrom(pkg: Package) {
1234
// install the app
1335
console.log(`installing ${pkg.packageFilepath}`);
@@ -18,49 +40,16 @@ export async function testAutoUpdateFrom(pkg: Package) {
1840

1941
console.log(appPath);
2042

21-
process.env.COMPASS_APP_NAME = pkg.appName;
22-
process.env.COMPASS_APP_PATH = appPath;
23-
2443
try {
2544
// TODO: start the autoupdate server
2645
try {
27-
// run the app and wait for it to auto-update
28-
const compass = await init('auto-update from', { firstRun: true });
29-
const { browser } = compass;
30-
31-
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
32-
33-
if (pkg.updatable) {
34-
await browser.$(Selectors.AutoUpdateRestartButton).waitForDisplayed();
35-
} else {
36-
// When auto-update is not supported the toast contains a link to down
37-
const linkElement = browser.$(Selectors.AutoUpdateDownloadLink);
38-
await browser.$(linkElement).waitForDisplayed();
39-
expect(await linkElement.getAttribute('href')).to.equal(
40-
'https://www.mongodb.com/try/download/compass'
41-
);
42-
}
43-
44-
await cleanup(compass);
45-
46-
if (pkg.updatable) {
47-
// run the app again and check that the version changed
48-
const compass = await init('auto-update from restart', {
49-
firstRun: false,
50-
});
51-
const { browser } = compass;
52-
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
53-
await browser
54-
.$(Selectors.AutoUpdateReleaseNotesLink)
55-
.waitForDisplayed();
56-
}
46+
await testInstalledApp(pkg, appPath, {
47+
AUTO_UPDATE_FROM: 'true',
48+
});
5749
} finally {
5850
// TODO: stop the autoupdate server
5951
}
6052
} finally {
61-
delete process.env.COMPASS_APP_NAME;
62-
delete process.env.COMPASS_APP_PATH;
63-
6453
// remove the app
6554
await uninstall();
6655
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { expect } from 'chai';
2+
import {
3+
init,
4+
cleanup,
5+
//screenshotIfFailed,
6+
Selectors,
7+
} from '../helpers/compass';
8+
9+
describe('Auto-update', function () {
10+
it('auto-update from', async function () {
11+
if (!process.env.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+
const compass = await init('auto-update from', { firstRun: true });
20+
try {
21+
const { browser } = compass;
22+
23+
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
24+
25+
if (process.env.AUTO_UPDATE_UPDATABLE === 'true') {
26+
await browser.$(Selectors.AutoUpdateRestartButton).waitForDisplayed();
27+
} else {
28+
// When auto-update is not supported the toast contains a link to down
29+
const linkElement = browser.$(Selectors.AutoUpdateDownloadLink);
30+
await browser.$(linkElement).waitForDisplayed();
31+
expect(await linkElement.getAttribute('href')).to.equal(
32+
'https://www.mongodb.com/try/download/compass'
33+
);
34+
}
35+
} finally {
36+
await cleanup(compass);
37+
}
38+
39+
if (process.env.AUTO_UPDATE_UPDATABLE === 'true') {
40+
// run the app again and check that the version changed
41+
const compass = await init('auto-update from restart', {
42+
firstRun: false,
43+
});
44+
try {
45+
const { browser } = compass;
46+
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
47+
await browser
48+
.$(Selectors.AutoUpdateReleaseNotesLink)
49+
.waitForDisplayed();
50+
} finally {
51+
await cleanup(compass);
52+
}
53+
}
54+
});
55+
56+
it('auto-update to', function () {
57+
if (!process.env.AUTO_UPDATE_TO) {
58+
// we don't want this test to execute along with all the others under
59+
// normal circumstances because it is destructive - it overwrites Compass
60+
// itself
61+
this.skip();
62+
}
63+
64+
// TODO
65+
});
66+
});

0 commit comments

Comments
 (0)