Skip to content

Commit 18fa13b

Browse files
feat: make cli command customizable (#3)
1 parent 462e4fb commit 18fa13b

3 files changed

Lines changed: 58 additions & 39 deletions

File tree

src/init.emulator.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {test} from '@playwright/test';
2+
import type {CliContextPageParams} from './page-objects/_cli-context.page';
23
import {CliPage} from './page-objects/cli.page';
34
import {ConsolePage} from './page-objects/console.page';
45

@@ -8,9 +9,11 @@ interface EmulatorSuitePages {
89
}
910

1011
export const initEmulatorSuite = ({
11-
satelliteKind
12+
satelliteKind,
13+
cli
1214
}: {
1315
satelliteKind: 'website' | 'application';
16+
cli?: CliContextPageParams;
1417
}): (() => EmulatorSuitePages) => {
1518
let consolePage: ConsolePage;
1619
let cliPage: CliPage;
@@ -33,7 +36,7 @@ export const initEmulatorSuite = ({
3336

3437
const satelliteId = await consolePage.copySatelliteID();
3538

36-
cliPage = await CliPage.initWithEmulatorLogin({satelliteId});
39+
cliPage = await CliPage.initWithEmulatorLogin({satelliteId, ...cli});
3740
});
3841

3942
test.afterAll(async () => {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const JUNO_CLI = {command: 'juno', args: []};
2+
3+
const JUNO_TEST_ARGS = ['--mode', 'development', '--headless'];
4+
5+
export interface CliContextPageParams {
6+
command?: {command: string; args: string[]};
7+
}
8+
9+
export abstract class CliContextPage {
10+
protected readonly command: string;
11+
protected readonly commandArgs: string[];
12+
13+
protected constructor({command}: CliContextPageParams) {
14+
const {command: cmd, args} = command ?? JUNO_CLI;
15+
16+
this.command = cmd;
17+
this.commandArgs = args;
18+
}
19+
20+
protected buildArgs(args: string[]): string[] {
21+
return [...this.commandArgs, ...args, ...JUNO_TEST_ARGS];
22+
}
23+
}

src/page-objects/cli.page.ts

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,20 @@ import {execute, spawn} from '@junobuild/cli-tools';
44
import {statSync} from 'node:fs';
55
import {readdir, readFile, writeFile} from 'node:fs/promises';
66
import {join} from 'node:path';
7-
8-
const DEV = (process.env.NODE_ENV ?? 'production') === 'development';
7+
import { type CliContextPageParams,CliContextPage} from './_cli-context.page';
98

109
const JUNO_CONFIG = join(process.cwd(), 'juno.config.ts');
1110

12-
const JUNO_TEST_ARGS = ['--mode', 'development', '--headless'];
13-
14-
const {command: JUNO_CMD, args: JUNO_CDM_ARGS} = DEV
15-
? {command: 'node', args: ['dist/index.js']}
16-
: {command: 'juno', args: []};
17-
18-
const buildArgs = (args: string[]): string[] => [...JUNO_CDM_ARGS, ...args, ...JUNO_TEST_ARGS];
19-
20-
export interface CliPageParams {
11+
export interface CliPageParams extends CliContextPageParams {
2112
satelliteId: PrincipalText;
2213
}
2314

24-
export class CliPage {
15+
export class CliPage extends CliContextPage {
2516
#satelliteId: PrincipalText;
2617

27-
private constructor({satelliteId}: CliPageParams) {
18+
private constructor({satelliteId, command}: CliPageParams) {
19+
super({command});
20+
2821
this.#satelliteId = satelliteId;
2922
}
3023

@@ -64,36 +57,36 @@ export class CliPage {
6457

6558
protected async loginWithEmulator(): Promise<void> {
6659
await execute({
67-
command: JUNO_CMD,
68-
args: buildArgs(['login', '--emulator'])
60+
command: this.command,
61+
args: this.buildArgs(['login', '--emulator'])
6962
});
7063
}
7164

7265
async applyConfig(): Promise<void> {
7366
await execute({
74-
command: JUNO_CMD,
75-
args: buildArgs(['config', 'apply', '--force'])
67+
command: this.command,
68+
args: this.buildArgs(['config', 'apply', '--force'])
7669
});
7770
}
7871

7972
private async logout(): Promise<void> {
8073
await execute({
81-
command: JUNO_CMD,
82-
args: buildArgs(['logout'])
74+
command: this.command,
75+
args: this.buildArgs(['logout'])
8376
});
8477
}
8578

8679
async clearHosting(): Promise<void> {
8780
await execute({
88-
command: JUNO_CMD,
89-
args: buildArgs(['hosting', 'clear'])
81+
command: this.command,
82+
args: this.buildArgs(['hosting', 'clear'])
9083
});
9184
}
9285

9386
async deployHosting({clear}: {clear: boolean}): Promise<void> {
9487
await execute({
95-
command: JUNO_CMD,
96-
args: buildArgs(['hosting', 'deploy', ...(clear ? ['--clear'] : [])])
88+
command: this.command,
89+
args: this.buildArgs(['hosting', 'deploy', ...(clear ? ['--clear'] : [])])
9790
});
9891
}
9992

@@ -103,8 +96,8 @@ export class CliPage {
10396
target: 'satellite' | 'orbiter' | 'mission-control';
10497
}): Promise<void> {
10598
await execute({
106-
command: JUNO_CMD,
107-
args: buildArgs(['snapshot', 'create', '--target', target])
99+
command: this.command,
100+
args: this.buildArgs(['snapshot', 'create', '--target', target])
108101
});
109102
}
110103

@@ -114,8 +107,8 @@ export class CliPage {
114107
target: 'satellite' | 'orbiter' | 'mission-control';
115108
}): Promise<void> {
116109
await execute({
117-
command: JUNO_CMD,
118-
args: buildArgs(['snapshot', 'restore', '--target', target])
110+
command: this.command,
111+
args: this.buildArgs(['snapshot', 'restore', '--target', target])
119112
});
120113
}
121114

@@ -125,8 +118,8 @@ export class CliPage {
125118
target: 'satellite' | 'orbiter' | 'mission-control';
126119
}): Promise<void> {
127120
await execute({
128-
command: JUNO_CMD,
129-
args: buildArgs(['snapshot', 'delete', '--target', target])
121+
command: this.command,
122+
args: this.buildArgs(['snapshot', 'delete', '--target', target])
130123
});
131124
}
132125

@@ -136,8 +129,8 @@ export class CliPage {
136129
target: 'satellite' | 'orbiter' | 'mission-control';
137130
}): Promise<{snapshotFolder: string}> {
138131
await execute({
139-
command: JUNO_CMD,
140-
args: buildArgs(['snapshot', 'download', '--target', target])
132+
command: this.command,
133+
args: this.buildArgs(['snapshot', 'download', '--target', target])
141134
});
142135

143136
return await this.getSnapshotFsFolder();
@@ -171,8 +164,8 @@ export class CliPage {
171164
folder: string;
172165
}): Promise<void> {
173166
await execute({
174-
command: JUNO_CMD,
175-
args: buildArgs(['snapshot', 'upload', '--target', target, '--dir', folder])
167+
command: this.command,
168+
args: this.buildArgs(['snapshot', 'upload', '--target', target, '--dir', folder])
176169
});
177170
}
178171

@@ -184,8 +177,8 @@ export class CliPage {
184177
let output = '';
185178

186179
await spawn({
187-
command: JUNO_CMD,
188-
args: buildArgs(['snapshot', 'list', '--target', target]),
180+
command: this.command,
181+
args: this.buildArgs(['snapshot', 'list', '--target', target]),
189182
stdout: (o) => (output += o),
190183
silentErrors: true
191184
});
@@ -198,8 +191,8 @@ export class CliPage {
198191
let output = '';
199192

200193
await spawn({
201-
command: JUNO_CMD,
202-
args: buildArgs(['whoami']),
194+
command: this.command,
195+
args: this.buildArgs(['whoami']),
203196
stdout: (o) => (output += o),
204197
silentErrors: true
205198
});

0 commit comments

Comments
 (0)