Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/compass-e2e-tests/helpers/compass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ async function processCommonOpts({
// Ensure that the user data dir exists
await fs.mkdir(defaultUserDataDir, { recursive: true });

console.log({ defaultUserDataDir });

// Chromedriver will fail if log path doesn't exist, webdriver doesn't care,
// for consistency let's mkdir for both of them just in case
await fs.mkdir(path.dirname(chromedriverLogPath), { recursive: true });
Expand Down
8 changes: 8 additions & 0 deletions packages/compass-e2e-tests/helpers/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1430,3 +1430,11 @@ export const GlobalWrites = {
SampleFindingDocuments: '[data-testid="sample-finding-documents"]',
SampleInsertingDocuments: '[data-testid="sample-inserting-documents"]',
};

export const AutoUpdateToast = '[data-testid="toast-compass-update"]';
export const AutoUpdateRestartButton =
'[data-testid="auto-update-restart-button"]';
export const AutoUpdateDownloadLink =
'[data-testid="auto-update-download-link"]';
export const AutoUpdateReleaseNotesLink =
'[data-testid="auto-update-release-notes-link"]';
12 changes: 12 additions & 0 deletions packages/compass-e2e-tests/installers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ export function execute(
): Promise<void> {
return new Promise((resolve, reject) => {
console.log(command, ...args);

const p = spawn(command, args, {
stdio: 'inherit',
...options,
});

p.on('error', (err: any) => {
reject(err);
});

p.on('close', (code: number | null, signal: NodeJS.Signals | null) => {
process.off('exit', killChild);
process.off('SIGINT', interruptChild);

if (code !== null) {
if (code === 0) {
resolve();
Expand All @@ -41,5 +47,11 @@ export function execute(
}
}
});

// Exit child process if main process exits
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from https://github.com/kraenhansen/bufout which we should probably just use.

const killChild = () => p.kill();
const interruptChild = () => p.kill('SIGINT');
process.once('exit', killChild);
process.once('SIGINT', interruptChild);
});
}
1 change: 1 addition & 0 deletions packages/compass-e2e-tests/installers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type Package = {
packageFilepath: string;
// TODO: once we can download the most recent release
//releaseFilepath: string;
updatable: boolean;
installer: Installer;
};

Expand Down
51 changes: 11 additions & 40 deletions packages/compass-e2e-tests/smoke-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import { hideBin } from 'yargs/helpers';
import https from 'https';
import { pick } from 'lodash';
import { handler as writeBuildInfo } from 'hadron-build/commands/info';
import type { InstalledAppInfo, Package, Installer } from './installers/types';
import type { Package, Installer } from './installers/types';
import { installMacDMG } from './installers/mac-dmg';
import { execute } from './installers/helpers';
import {
assertBuildInfoIsOSX,
assertBuildInfoIsRHEL,
assertBuildInfoIsUbuntu,
assertBuildInfoIsWindows,
assertCommonBuildInfo,
} from './helpers/buildinfo';
import { testAutoUpdateFrom } from './smoketests/auto-update-from';

const argv = yargs(hideBin(process.argv))
.scriptName('smoke-tests')
Expand Down Expand Up @@ -202,13 +202,15 @@ async function run() {
}

if (match) {
const pkg = {
const pkg: Package = {
// we need appName because it is the name of the executable inside the
// package, regardless of what the package filename is named or where it
// gets installed
appName: buildInfo.productName,
packageFilepath: path.join(compassDir, 'dist', match.filename),
// TODO: releaseFilepath once we download the most recent released version too
updatable: match.updatable,
// TODO(COMPASS-8532): releaseFilepath once we download the most recent
// released version too
installer: match.installer,
};

Expand All @@ -222,7 +224,8 @@ async function run() {
console.log(url);
await downloadFile(url, pkg.packageFilepath);

// TODO: we need to also download releaseFilepath once we have that
// TODO(COMPASS-8532): we need to also download releaseFilepath once we
// have that
}

if (!existsSync(pkg.packageFilepath)) {
Expand All @@ -231,16 +234,9 @@ async function run() {
);
}

// TODO: installing either the packaged file or the released file is better
// done as part of tests so we can also clean up and install one after the
// other, but that's for a separate PR.
console.log('installing', pkg.packageFilepath);
const installedInfo = await pkg.installer({
appName: pkg.appName,
filepath: pkg.packageFilepath,
});
console.log('testing', installedInfo.appPath);
await testInstalledApp(pkg, installedInfo);
await testAutoUpdateFrom(pkg);
// TODO(COMPASS-8535)
//await testAutoUpdateTo(pkg);
} else {
throw new Error(`${context.package} not implemented`);
}
Expand Down Expand Up @@ -278,31 +274,6 @@ async function downloadFile(url: string, targetFile: string): Promise<void> {
});
}

function testInstalledApp(
pkg: Package,
appInfo: InstalledAppInfo
): Promise<void> {
return execute(
'npm',
[
'run',
'--unsafe-perm',
'test-packaged',
'--workspace',
'compass-e2e-tests',
'--',
'--test-filter=time-to-first-query',
],
{
env: {
...process.env,
COMPASS_APP_NAME: pkg.appName,
COMPASS_APP_PATH: appInfo.appPath,
},
}
);
}

run()
.then(function () {
console.log('done');
Expand Down
57 changes: 57 additions & 0 deletions packages/compass-e2e-tests/smoketests/auto-update-from.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { execute } from '../installers/helpers';
import type { Package } from '../installers/types';

// TODO: move this since we'll use the same for testing TO
function testInstalledApp(
pkg: Package,
appPath: string,
env: Record<string, string>
): Promise<void> {
return execute(
'npm',
[
'run',
'--unsafe-perm',
'test-packaged',
'--workspace',
'compass-e2e-tests',
'--',
'--test-filter=auto-update',
],
{
env: {
...process.env,
HADRON_AUTO_UPDATE_ENDPOINT_OVERRIDE: 'http://localhost:8080',
AUTO_UPDATE_UPDATABLE: pkg.updatable.toString(),
COMPASS_APP_NAME: pkg.appName,
COMPASS_APP_PATH: appPath,
...env,
},
}
);
}

export async function testAutoUpdateFrom(pkg: Package) {
// install the app
console.log(`installing ${pkg.packageFilepath}`);
const { appPath, uninstall } = await pkg.installer({
appName: pkg.appName,
filepath: pkg.packageFilepath,
});

console.log(appPath);

try {
// TODO: start the autoupdate server
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An actual TODO for this PR. We could also start the autoupdate server on the outside and just leave it running, but I think we'll want to run it with a different configuration once we get to the "autoupdate TO" tests.

try {
await testInstalledApp(pkg, appPath, {
AUTO_UPDATE_FROM: 'true',
});
} finally {
// TODO: stop the autoupdate server
}
} finally {
// remove the app
await uninstall();
}
}
72 changes: 72 additions & 0 deletions packages/compass-e2e-tests/tests/auto-update.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { expect } from 'chai';
import {
init,
cleanup,
//screenshotIfFailed,
Selectors,
} from '../helpers/compass';

describe('Auto-update', function () {
it('auto-update from', async function () {
if (!process.env.AUTO_UPDATE_FROM) {
// we don't want this test to execute along with all the others under
// normal circumstances because it is destructive - it overwrites Compass
// itself
this.skip();
}

// run the app and wait for it to auto-update
const compass = await init('auto-update from', { firstRun: true });
try {
const { browser } = compass;

await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();

if (process.env.AUTO_UPDATE_UPDATABLE === 'true') {
const restartButton = browser.$(Selectors.AutoUpdateRestartButton);
await restartButton.waitForDisplayed();

// We could click the restart button to apply the update and restart the
// app, but restarting the app confuses webdriverio or at least our test
// helpers. So we're going to just restart the app manually.
} else {
// When auto-update is not supported the toast contains a link to
// download
const linkElement = browser.$(Selectors.AutoUpdateDownloadLink);
await linkElement.waitForDisplayed();
expect(await linkElement.getAttribute('href')).to.equal(
'https://www.mongodb.com/try/download/compass'
);
}
} finally {
await cleanup(compass);
}

if (process.env.AUTO_UPDATE_UPDATABLE === 'true') {
// run the app again and check that the version changed
const compass = await init('auto-update from restart', {
firstRun: false,
});
try {
const { browser } = compass;
await browser.$(Selectors.AutoUpdateToast).waitForDisplayed();
await browser
.$(Selectors.AutoUpdateReleaseNotesLink)
.waitForDisplayed();
} finally {
await cleanup(compass);
}
}
});

it('auto-update to', function () {
if (!process.env.AUTO_UPDATE_TO) {
// we don't want this test to execute along with all the others under
// normal circumstances because it is destructive - it overwrites Compass
// itself
this.skip();
}

// TODO
});
});
3 changes: 3 additions & 0 deletions packages/compass/src/app/components/update-toasts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const RestartCompassToastContent = ({
<button
className={cx(buttonStyles, darkmode && buttonDarkStyles)}
onClick={onUpdateClicked}
data-testid="auto-update-restart-button"
>
Restart
</button>
Expand Down Expand Up @@ -83,6 +84,7 @@ export function onAutoupdateExternally({
Compass features.
</Body>
<Link
data-testid="auto-update-download-link"
as="a"
target="_blank"
href={'https://www.mongodb.com/try/download/compass'}
Expand Down Expand Up @@ -137,6 +139,7 @@ export function onAutoupdateInstalled({ newVersion }: { newVersion: string }) {
title: `Compass ${newVersion} installed successfully`,
description: (
<Link
data-testid="auto-update-release-notes-link"
as="a"
target="_blank"
href={`https://github.com/mongodb-js/compass/releases/tag/v${newVersion}`}
Expand Down
4 changes: 2 additions & 2 deletions packages/compass/src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ const app = {
}

if (
semver.gt(APP_VERSION, state.previousVersion) &&
state.previousVersion !== DEFAULT_APP_VERSION
state.previousVersion !== DEFAULT_APP_VERSION &&
APP_VERSION !== state.previousVErsion
) {
// Wait a bit before showing the update toast.
setTimeout(() => {
Expand Down
Loading