Skip to content

Commit

Permalink
test: testing desktop tests in gha
Browse files Browse the repository at this point in the history
  • Loading branch information
andrcj committed May 20, 2024
1 parent 3e14473 commit 95d8120
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 60 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/test-suite-desktop-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: "[Build/Test] suite-desktop e2e"
# this action builds a desktop version of Suite and runs basic test suite for it

# run only if there are changes in suite or related libs paths
on:
pull_request:
branches:
- develop
paths-ignore:
- "suite-native/**"
- "packages/connect*/**"
- "packages/react-native-usb/**"
# ignore unrelated github workflows config files
- ".github/workflows/connect*"
- ".github/workflows/suite-native*"
- ".github/workflows/build-desktop*"
- ".github/workflows/release*"
- ".github/workflows/template*"

jobs:
run-desktop-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- TEST_FILE: "spawn-bridge"
CONTAINERS: "trezor-user-env-unix"
- TEST_FILE: "suite-guide"
CONTAINERS: "trezor-user-env-unix"
- TEST_FILE: "wallet-discovery"
CONTAINERS: "trezor-user-env-unix"
# - TEST_FILE: "cardano-discovery"
# CONTAINERS: "trezor-user-env-unix"
# - TEST_FILE: "eap-modal"
# CONTAINERS: "trezor-user-env-unix"
- TEST_FILE: "electrum"
CONTAINERS: "trezor-user-env-unix electrum-regtest"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: yarn

- name: Install deps and build libs
run: |
yarn install --immutable
yarn message-system-sign-config
yarn workspace @trezor/suite-data build:lib
yarn workspace @trezor/connect-iframe build:lib
yarn workspace @trezor/transport-bridge build:lib
- name: Build linux suite-desktop
run: |
yarn workspace @trezor/suite-desktop build:linux
bash packages/suite-desktop-core/scripts/gnupg-sign.sh
mv packages/suite-desktop/build-electron/* .
- name: Run e2e desktop tests
env:
COMPOSE_FILE: ./docker/docker-compose.suite-desktop-ci.yml
TEST_FILE: ${{ matrix.TEST_FILE }}
run: |
docker compose pull
docker compose up -d ${{ matrix.CONTAINERS }}
docker compose run test-run
- name: cleanup
env:
COMPOSE_FILE: ./docker/docker-compose.suite-desktop-ci.yml
run: docker compose down

# TODO: currently only uploads trace.zip, figure out why screens are not uploaded
- name: Upload artifacts
# this will run the upload artifacts even if the previous steps failed (e.g. tests failed). It wont run if the workflow was cancelled.
if: ${{ ! cancelled() }}
uses: actions/upload-artifact@v4
with:
name: test-artifacts-${{ matrix.TEST_FILE }}
path: |
./packages/suite-desktop-core/e2e/test-results
94 changes: 47 additions & 47 deletions ci/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,55 @@
- /^release\//

# @trezor/suite-desktop
.e2e desktop:
stage: integration testing
retry: 1
dependencies:
- install
variables:
COMPOSE_PROJECT_NAME: $CI_JOB_ID # for unique containers
COMPOSE_FILE: ./docker/docker-compose.suite-desktop-ci.yml
TEST_FILE: $TEST_FILE
before_script:
- docker login $CI_DEPENDENCY_PROXY_SERVER -u $CI_DEPENDENCY_PROXY_USER -p $CI_DEPENDENCY_PROXY_PASSWORD
script:
- yarn install --immutable
# 3 next steps could be removed if we passed packages/suite-desktop/dist and build folder as an artifact
# but since this is run only in nightly builds it can be probably built inside the job for now..
- yarn message-system-sign-config
- yarn workspace @trezor/suite-desktop build:linux
- docker-compose pull
- docker-compose up -d ${CONTAINERS}
- docker-compose run test-run
after_script:
- docker-compose down
- docker network prune -f
artifacts:
expire_in: 7 days
when: always
paths:
- "**/test-results/**"
interruptible: true
parallel:
matrix:
- TEST_FILE: ["spawn-tor", "spawn-bridge", "suite-guide", "wallet-discovery"]
CONTAINERS: "trezor-user-env-unix"
- TEST_FILE: ["electrum"]
CONTAINERS: "trezor-user-env-unix electrum-regtest"
# commented out. coinjoin test is not adapted to current state of this feature
# - TEST_FILE: ["coinjoin"]
# CONTAINERS: "trezor-user-env-unix coinjoin-backend"
# .e2e desktop:
# stage: integration testing
# retry: 1
# dependencies:
# - install
# variables:
# COMPOSE_PROJECT_NAME: $CI_JOB_ID # for unique containers
# COMPOSE_FILE: ./docker/docker-compose.suite-desktop-ci.yml
# TEST_FILE: $TEST_FILE
# before_script:
# - docker login $CI_DEPENDENCY_PROXY_SERVER -u $CI_DEPENDENCY_PROXY_USER -p $CI_DEPENDENCY_PROXY_PASSWORD
# script:
# - yarn install --immutable
# # 3 next steps could be removed if we passed packages/suite-desktop/dist and build folder as an artifact
# # but since this is run only in nightly builds it can be probably built inside the job for now..
# - yarn message-system-sign-config
# - yarn workspace @trezor/suite-desktop build:linux
# - docker-compose pull
# - docker-compose up -d ${CONTAINERS}
# - docker-compose run test-run
# after_script:
# - docker-compose down
# - docker network prune -f
# artifacts:
# expire_in: 7 days
# when: always
# paths:
# - "**/test-results/**"
# interruptible: true
# parallel:
# matrix:
# - TEST_FILE: ["spawn-tor", "spawn-bridge", "suite-guide", "wallet-discovery"]
# CONTAINERS: "trezor-user-env-unix"
# - TEST_FILE: ["electrum"]
# CONTAINERS: "trezor-user-env-unix electrum-regtest"
# # commented out. coinjoin test is not adapted to current state of this feature
# # - TEST_FILE: ["coinjoin"]
# # CONTAINERS: "trezor-user-env-unix coinjoin-backend"

suite desktop:
extends: .e2e desktop
only:
<<: *run_everything_rules
# suite desktop:
# extends: .e2e desktop
# only:
# <<: *run_everything_rules

suite desktop manual:
extends: .e2e desktop
except:
<<: *run_everything_rules
when: manual
# suite desktop manual:
# extends: .e2e desktop
# except:
# <<: *run_everything_rules
# when: manual

.connect-popup legacy npm package base:
stage: integration testing
Expand Down
10 changes: 5 additions & 5 deletions docker/docker-compose.suite-desktop-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ services:
- ../:/trezor-suite
network_mode: service:trezor-user-env-unix

coinjoin-backend:
image: ghcr.io/trezor/coinjoin-backend:latest
network_mode: service:trezor-user-env-unix
volumes:
- ../:/coinjoin-backend
# coinjoin-backend:
# image: ghcr.io/trezor/coinjoin-backend:latest
# network_mode: service:trezor-user-env-unix
# volumes:
# - ../:/coinjoin-backend
7 changes: 5 additions & 2 deletions packages/suite-desktop-core/e2e/support/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ import { Page, _electron as electron } from '@playwright/test';
import path from 'path';
import fs from 'fs';

import { TrezorUserEnvLink } from '@trezor/trezor-user-env-link';

export const launchSuite = async () => {
const appDir = path.join(__dirname, '../../../suite-desktop');
const desiredLogLevel = process.env.LOGLEVEL ?? 'error';
await TrezorUserEnvLink.api.startBridge();
const electronApp = await electron.launch({
cwd: appDir,
args: [
path.join(appDir, './dist/app.js'),
`--log-level=${desiredLogLevel}`,
'--bridge-node-test',
// '--bridge-node-test',
// uncomment to use legacy bridge
// '--bridge-legacy-test'
'--bridge-legacy-test',
],
// when testing electron, video needs to be setup like this. it works locally but not in docker
// recordVideo: { dir: 'test-results' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,23 @@ import { waitForDataTestSelector } from '../common';
class DashboardActions {
async passThroughInitialRun(window: Page) {
await waitForDataTestSelector(window, '@welcome/title');
await window.screenshot({
path: './test-results/zacatek-initial-runu.png',
fullPage: true,
type: 'png',
});
await window.getByTestId('@analytics/continue-button').click();
await window.screenshot({
path: './test-results/po-continue-runu.png',
fullPage: true,
type: 'png',
});
await window.getByTestId('@onboarding/exit-app-button').click();
await window.screenshot({
path: './test-results/po-exitu-runu.png',
fullPage: true,
type: 'png',
});
}

async discoveryShouldFinish(window: Page) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class SettingsActions {
desiredLocationTestid = '@settings/debug/github';
break;
case 'general':
desiredLocationTestid = '@settings/language';
desiredLocationTestid = '@general-settings/language';
break;
case 'device':
desiredLocationTestid = '@settings/device/backup-recovery-seed';
Expand All @@ -39,7 +39,9 @@ class SettingsActions {
}
await window.getByTestId(`@settings/menu/${desiredLocation}`).click();
await window
.getByTestId(desiredLocationTestid)
.locator(`[data-test="${desiredLocationTestid}"]`)
// TODO: fix data-testid selectors in the app
// .getByTestId(desiredLocationTestid)
.waitFor({ state: 'visible', timeout: 10_000 });
}

Expand Down Expand Up @@ -74,6 +76,11 @@ class SettingsActions {
}

async joinEarlyAccessProgram(window: Page) {
await window.screenshot({
path: './test-results/settings.png',
fullPage: true,
type: 'png',
});
await window.getByTestId('@settings/early-access-join-button').scrollIntoViewIfNeeded();
await window.getByTestId('@settings/early-access-join-button').click();
const eapModal = window.getByTestId('@modal');
Expand Down
2 changes: 1 addition & 1 deletion packages/suite-desktop-core/e2e/tests/coinjoin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const passThroughInitialRun = async (window: Page) => {
await window.waitForSelector('[data-test="@dashboard/graph"]');
};

testPlaywright.describe('Coinjoin', () => {
testPlaywright.describe.skip('Coinjoin', () => {
testPlaywright.beforeAll(async () => {
testPlaywright.setTimeout(timeout * 10);

Expand Down
10 changes: 8 additions & 2 deletions packages/suite-desktop-core/e2e/tests/general/eap-modal.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { test as testPlaywright, ElectronApplication, Page } from '@playwright/test';
import {
test as testPlaywright,
ElectronApplication,
Page,
expect as expectPlaywright,
} from '@playwright/test';

import { launchSuite, rmDirRecursive } from '../../support/common';
import { onTopBar } from '../../support/pageActions/topBarActions';
Expand All @@ -25,12 +30,13 @@ testPlaywright.afterAll(() => {
* 4. Confrim the EAP modal
* 5. Check if there is a button with `Leave` on it
*/
// TODO: FIX settings cleanup: eap setting is remembered even after cache cleanup at the beginning of the test. This shouldn't affect gha run but breaks the local one.
testPlaywright('Join early access button', async () => {
const buttonText = 'Leave';

await onTopBar.openSettings(window);
await onSettingsPage.goToDesiredSettingsPlace(window, 'general');
await onSettingsPage.joinEarlyAccessProgram(window);

await expect(onSettingsPage.getEarlyAccessButtonText(window)).toContain(buttonText);
expectPlaywright(await onSettingsPage.getEarlyAccessButtonText(window)).toContain(buttonText);
});
2 changes: 1 addition & 1 deletion packages/suite-desktop-core/e2e/tests/spawn-tor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const turnOnTorInSettings = async (window: Page, shouldEnableTor = true) => {
await window.waitForTimeout(1000);
};

testPlaywright.describe('Tor loading screen', () => {
testPlaywright.describe.skip('Tor loading screen', () => {
testPlaywright('Tor loading screen: happy path', async () => {
testPlaywright.setTimeout(timeout);

Expand Down

0 comments on commit 95d8120

Please sign in to comment.