From e33064b17cfedaea8e3f5f2aec5d1685eb7ac2f1 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Fri, 20 Feb 2026 09:33:49 +0100 Subject: [PATCH] feat: make cli command customizable --- src/init.emulator.ts | 7 ++- src/page-objects/_cli-context.page.ts | 23 +++++++++ src/page-objects/cli.page.ts | 67 ++++++++++++--------------- 3 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 src/page-objects/_cli-context.page.ts diff --git a/src/init.emulator.ts b/src/init.emulator.ts index 5cccdd6..c6d46ad 100644 --- a/src/init.emulator.ts +++ b/src/init.emulator.ts @@ -1,4 +1,5 @@ import {test} from '@playwright/test'; +import type {CliContextPageParams} from './page-objects/_cli-context.page'; import {CliPage} from './page-objects/cli.page'; import {ConsolePage} from './page-objects/console.page'; @@ -8,9 +9,11 @@ interface EmulatorSuitePages { } export const initEmulatorSuite = ({ - satelliteKind + satelliteKind, + cli }: { satelliteKind: 'website' | 'application'; + cli?: CliContextPageParams; }): (() => EmulatorSuitePages) => { let consolePage: ConsolePage; let cliPage: CliPage; @@ -33,7 +36,7 @@ export const initEmulatorSuite = ({ const satelliteId = await consolePage.copySatelliteID(); - cliPage = await CliPage.initWithEmulatorLogin({satelliteId}); + cliPage = await CliPage.initWithEmulatorLogin({satelliteId, ...cli}); }); test.afterAll(async () => { diff --git a/src/page-objects/_cli-context.page.ts b/src/page-objects/_cli-context.page.ts new file mode 100644 index 0000000..1fbe446 --- /dev/null +++ b/src/page-objects/_cli-context.page.ts @@ -0,0 +1,23 @@ +const JUNO_CLI = {command: 'juno', args: []}; + +const JUNO_TEST_ARGS = ['--mode', 'development', '--headless']; + +export interface CliContextPageParams { + command?: {command: string; args: string[]}; +} + +export abstract class CliContextPage { + protected readonly command: string; + protected readonly commandArgs: string[]; + + protected constructor({command}: CliContextPageParams) { + const {command: cmd, args} = command ?? JUNO_CLI; + + this.command = cmd; + this.commandArgs = args; + } + + protected buildArgs(args: string[]): string[] { + return [...this.commandArgs, ...args, ...JUNO_TEST_ARGS]; + } +} diff --git a/src/page-objects/cli.page.ts b/src/page-objects/cli.page.ts index e6b4c08..43186ad 100644 --- a/src/page-objects/cli.page.ts +++ b/src/page-objects/cli.page.ts @@ -4,27 +4,20 @@ import {execute, spawn} from '@junobuild/cli-tools'; import {statSync} from 'node:fs'; import {readdir, readFile, writeFile} from 'node:fs/promises'; import {join} from 'node:path'; - -const DEV = (process.env.NODE_ENV ?? 'production') === 'development'; +import { type CliContextPageParams,CliContextPage} from './_cli-context.page'; const JUNO_CONFIG = join(process.cwd(), 'juno.config.ts'); -const JUNO_TEST_ARGS = ['--mode', 'development', '--headless']; - -const {command: JUNO_CMD, args: JUNO_CDM_ARGS} = DEV - ? {command: 'node', args: ['dist/index.js']} - : {command: 'juno', args: []}; - -const buildArgs = (args: string[]): string[] => [...JUNO_CDM_ARGS, ...args, ...JUNO_TEST_ARGS]; - -export interface CliPageParams { +export interface CliPageParams extends CliContextPageParams { satelliteId: PrincipalText; } -export class CliPage { +export class CliPage extends CliContextPage { #satelliteId: PrincipalText; - private constructor({satelliteId}: CliPageParams) { + private constructor({satelliteId, command}: CliPageParams) { + super({command}); + this.#satelliteId = satelliteId; } @@ -64,36 +57,36 @@ export class CliPage { protected async loginWithEmulator(): Promise { await execute({ - command: JUNO_CMD, - args: buildArgs(['login', '--emulator']) + command: this.command, + args: this.buildArgs(['login', '--emulator']) }); } async applyConfig(): Promise { await execute({ - command: JUNO_CMD, - args: buildArgs(['config', 'apply', '--force']) + command: this.command, + args: this.buildArgs(['config', 'apply', '--force']) }); } private async logout(): Promise { await execute({ - command: JUNO_CMD, - args: buildArgs(['logout']) + command: this.command, + args: this.buildArgs(['logout']) }); } async clearHosting(): Promise { await execute({ - command: JUNO_CMD, - args: buildArgs(['hosting', 'clear']) + command: this.command, + args: this.buildArgs(['hosting', 'clear']) }); } async deployHosting({clear}: {clear: boolean}): Promise { await execute({ - command: JUNO_CMD, - args: buildArgs(['hosting', 'deploy', ...(clear ? ['--clear'] : [])]) + command: this.command, + args: this.buildArgs(['hosting', 'deploy', ...(clear ? ['--clear'] : [])]) }); } @@ -103,8 +96,8 @@ export class CliPage { target: 'satellite' | 'orbiter' | 'mission-control'; }): Promise { await execute({ - command: JUNO_CMD, - args: buildArgs(['snapshot', 'create', '--target', target]) + command: this.command, + args: this.buildArgs(['snapshot', 'create', '--target', target]) }); } @@ -114,8 +107,8 @@ export class CliPage { target: 'satellite' | 'orbiter' | 'mission-control'; }): Promise { await execute({ - command: JUNO_CMD, - args: buildArgs(['snapshot', 'restore', '--target', target]) + command: this.command, + args: this.buildArgs(['snapshot', 'restore', '--target', target]) }); } @@ -125,8 +118,8 @@ export class CliPage { target: 'satellite' | 'orbiter' | 'mission-control'; }): Promise { await execute({ - command: JUNO_CMD, - args: buildArgs(['snapshot', 'delete', '--target', target]) + command: this.command, + args: this.buildArgs(['snapshot', 'delete', '--target', target]) }); } @@ -136,8 +129,8 @@ export class CliPage { target: 'satellite' | 'orbiter' | 'mission-control'; }): Promise<{snapshotFolder: string}> { await execute({ - command: JUNO_CMD, - args: buildArgs(['snapshot', 'download', '--target', target]) + command: this.command, + args: this.buildArgs(['snapshot', 'download', '--target', target]) }); return await this.getSnapshotFsFolder(); @@ -171,8 +164,8 @@ export class CliPage { folder: string; }): Promise { await execute({ - command: JUNO_CMD, - args: buildArgs(['snapshot', 'upload', '--target', target, '--dir', folder]) + command: this.command, + args: this.buildArgs(['snapshot', 'upload', '--target', target, '--dir', folder]) }); } @@ -184,8 +177,8 @@ export class CliPage { let output = ''; await spawn({ - command: JUNO_CMD, - args: buildArgs(['snapshot', 'list', '--target', target]), + command: this.command, + args: this.buildArgs(['snapshot', 'list', '--target', target]), stdout: (o) => (output += o), silentErrors: true }); @@ -198,8 +191,8 @@ export class CliPage { let output = ''; await spawn({ - command: JUNO_CMD, - args: buildArgs(['whoami']), + command: this.command, + args: this.buildArgs(['whoami']), stdout: (o) => (output += o), silentErrors: true });