Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run e2e tests against emulator from URL or firmware branch #15689

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

grdddj
Copy link
Contributor

@grdddj grdddj commented Dec 2, 2024

Allow for running e2e tests not only with emulators hardcoded in tenv, but also from:

  • specified URL
  • firmware branch

The way of running these is either:

  • hardcoding these in packages/connect/e2e/run.ts:
const firmwareArg = process.env.TESTS_FIRMWARE;
const firmwareUrl = process.env.TESTS_FIRMWARE_URL;
const firmwareModel = process.env.TESTS_FIRMWARE_MODEL;
const firmwareBranch = process.env.TESTS_FIRMWARE_BRANCH;
const firmwareBtcOnly = process.env.TESTS_FIRMWARE_BTC_ONLY === 'true';
  • setting ENV variable when spawning the tests:
TESTS_FIRMWARE_MODEL="T3T1" TESTS_FIRMWARE_URL="https://data.trezor.io/dev/firmware/emu-branches/grdddj/emulator_upload_all_branches/trezor-emu-core-T3T1-universal" yarn workspace @trezor/connect-web test:e2e:node
TESTS_FIRMWARE_MODEL="T3T1" TESTS_FIRMWARE_BRANCH="obrusvit/refactor-confirm-summary" TESTS_FIRMWARE_BTC_ONLY="true" yarn workspace @trezor/connect-web test:e2e:node

NOTE: for local development, emulators from branches do not support ARM, so it will work for you only in CI

Copy link
Contributor

@mroz22 mroz22 left a comment

Choose a reason for hiding this comment

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

this is definitely a nice step forward. maybe cc @szymonlesisz who asked for this feature.

@@ -22,10 +22,33 @@ export interface StartEmu {
model?: Model;
}

interface StartEmuFromUrl extends Omit<StartEmu, 'version'> {
interface StartEmuType extends StartEmu {
type?: 'emulator-start';
Copy link
Contributor

Choose a reason for hiding this comment

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

should type be optional here?

Copy link
Contributor

Choose a reason for hiding this comment

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

also for StartEmuType should wipe and model be optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

type needs to be optional here so everything is working in runtime and is typescript-correct in packages/connect/e2e/common.setup.ts. Crucial lines are below:

const emulatorStartOpts: EmuStartOptsType =
    (process.env.emulatorStartOpts as any) || global.emulatorStartOpts || {};
const emuStartType = emulatorStartOpts.type;

switch (emuStartType) {
  case 'emulator-start':
  case undefined:
   ...

For runtime, it is possible that the process.env.emulatorStartOpts is empty, so it will try to take global.emulatorStartOpts ... I did not know where it is defined, I see only the interface:

    var emulatorStartOpts: {
        version: string;
        model: 'T1B1' | 'T2T1' | 'T2B1' | 'T3T1';
    };

So one possibility is to add type: 'emulator-start' there, and the second one was to make it optional and account for the undefined in switch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, in StartEmuType almost all parameters are needed - version, model, wipe - that probably means not extending from StartEmu, as it overrides almost everything

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correction - it was now possible to get rid of the type optionality - 3eddfc5

However, now the version needs to be optional, because it is potentially undefined in this case:

const latest = getLatestFirmware(model);
const version = firmwareArg
    ? firmwareArg?.endsWith('-latest')
        ? latest
        : firmwareArg
    : latest;
emulatorStartOpts = {
    type: 'emulator-start',
    wipe: true,
    version,
    model,
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants