Skip to content

Commit

Permalink
chore(ci): run packaged app test outside of git repository COMPASS-5515
Browse files Browse the repository at this point in the history
… (#4910)

This works nicely on Linux and macOS, not so much on Windows
unfortunately. This probably still gives us decent coverage for
the problem this is intended to prevent (Compass accidentally relying
on npm packages inside the repository).
  • Loading branch information
addaleax authored Sep 26, 2023
1 parent 9bdab8f commit 8596ab8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
45 changes: 27 additions & 18 deletions .evergreen/functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ variables:
# WARN: This version is behind our electron runtime, but updating it will
# drop support for some older linux platforms, so we are keeping them out of
# sync for now
# TODO: https://jira.mongodb.org/browse/COMPASS-6915
# TODO: https://jira.mongodb.org/browse/COMPASS-6915
NODE_JS_VERSION: '16.20.2'
NPM_VERSION: '8.19.4'
# secrets
Expand Down Expand Up @@ -323,38 +323,42 @@ functions:
shell: bash
env:
<<: *compass-env
COMPASS_APP_PATH: ${appPath}
COMPASS_APP_NAME: ${packagerOptions.name}
COMPASS_APP_PATH_ORIGINAL: ${appPath}
script: |
set -e
# Load environment variables
eval $(.evergreen/print-compass-env.sh)
set -x
# Check the app bundle size.
npm run --workspace mongodb-compass check-bundled-app-size
echo "Unpacking ${app_archive_name} ..."
if [[ "$IS_WINDOWS" == "true" ]]; then
COMPASS_OUTDIR="$COMPASS_APP_PATH_ORIGINAL"
else
# Unpack outside the Compass working tree to avoid interactions with
# npm packages from inside it.
# (This doesn't seem to work on Windows without issues around being
# able to spawn the extracted executable, unfortunately.)
COMPASS_OUTDIR="$PWD/../tmp/from-packaged"
fi
mkdir -p "$COMPASS_OUTDIR"
echo "Unpacking ${app_archive_name} to $COMPASS_OUTDIR ..."
# Unpack the app archive
if [[ "${app_archive_name}" == *.zip ]]; then
COMPASS_OUTDIR="$COMPASS_APP_PATH"
if [[ "$IS_OSX" == "true" ]]; then
# unzip on macos needs a different path to avoid nesting the .app
# inside another .app dir
COMPASS_OUTDIR=$(dirname "$COMPASS_APP_PATH")
fi
echo "Unpacking ${app_archive_name} to $COMPASS_OUTDIR ..."
mkdir -p "$COMPASS_OUTDIR"
unzip "packages/compass/dist/${app_archive_name}" -d "$COMPASS_OUTDIR"
else
COMPASS_OUTDIR="packages/compass/dist"
echo "Unpacking ${app_archive_name} to $COMPASS_OUTDIR ..."
mkdir -p "$COMPASS_OUTDIR"
tar -xzf "packages/compass/dist/${app_archive_name}" -C "$COMPASS_OUTDIR"
fi
# Print folder content to confirm that it worked
ls -la packages/compass/dist
ls -la "$COMPASS_OUTDIR"
if [[ "$IS_WINDOWS" == "true" ]]; then
chmod +x "$COMPASS_OUTDIR"/*.exe
fi
e2e-coverage:
- command: shell.exec
Expand Down Expand Up @@ -387,7 +391,7 @@ functions:
shell: bash
env:
<<: *compass-env
COMPASS_APP_PATH: ${appPath}
COMPASS_APP_PATH_ORIGINAL: ${appPath}
COMPASS_APP_NAME: ${packagerOptions.name}
DEBUG: ${debug|}
MONGODB_VERSION: ${mongodb_version|}
Expand All @@ -398,10 +402,15 @@ functions:
eval $(.evergreen/print-compass-env.sh)
source .evergreen/start-docker-envs.sh
if [[ "$IS_WINDOWS" == "true" ]]; then
export COMPASS_APP_PATH="$COMPASS_APP_PATH_ORIGINAL"
else
export COMPASS_APP_PATH="$PWD/../tmp/from-packaged/$(basename "$COMPASS_APP_PATH_ORIGINAL")"
fi
echo "Running tests against packaged app at $COMPASS_APP_PATH for MongoDB $MONGODB_VERSION..."
if [[ "$IS_OSX" == "true" ]]; then
echo "Disabling keychain usage in Compass (TODO: https://jira.mongodb.org/browse/BUILD-14458)"
echo "Disabling keychain usage in Compass (TODO: https://jira.mongodb.org/browse/COMPASS-7102)"
export COMPASS_E2E_DISABLE_KEYCHAIN_USAGE="true"
echo "Disabling clipboard usage in e2e tests (TODO: https://jira.mongodb.org/browse/BUILD-14780)"
export COMPASS_E2E_DISABLE_CLIPBOARD_USAGE="true"
Expand Down
6 changes: 4 additions & 2 deletions packages/compass-e2e-tests/helpers/compass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,12 @@ async function getCompassBuildMetadata(): Promise<BinPathOptions> {
}
// Double-checking that Compass app path exists, not only the metadata
await fs.stat(metadata.appPath);
debug('Existing Compass found', metadata);
return metadata;
} catch (e) {
} catch (e: any) {
debug('Existing Compass build not found', e);
throw new Error(
"Compass package metadata doesn't exist. Make sure you built Compass before running e2e tests"
`Compass package metadata doesn't exist. Make sure you built Compass before running e2e tests: ${e.message}`
);
}
}
Expand Down

0 comments on commit 8596ab8

Please sign in to comment.