Skip to content

Commit 97689b2

Browse files
enabled smartui sdk to use custom ports
1 parent 0022acb commit 97689b2

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

src/commander/exec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ command
1616
.name('exec')
1717
.description('Run test commands around SmartUI')
1818
.argument('<command...>', 'Command supplied for running tests')
19+
.option('-P, --port <number>', 'Port number for the server')
1920
.action(async function(execCommand, _, command) {
2021
let ctx: Context = ctxInit(command.optsWithGlobals());
22+
ctx.log.debug(ctx.options.port)
2123

2224
if (!which.sync(execCommand[0], { nothrow: true })) {
2325
ctx.log.error(`Error: Command not found "${execCommand[0]}"`);

src/lib/ctx.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default (options: Record<string, string>): Context => {
1212
let webConfig: WebConfig;
1313
let mobileConfig: MobileConfig;
1414
let config = constants.DEFAULT_CONFIG;
15+
let port: number;
1516

1617
try {
1718
if (options.config) {
@@ -28,6 +29,10 @@ export default (options: Record<string, string>): Context => {
2829
throw new Error(validateConfig.errors[0].message);
2930
}
3031
}
32+
port = parseInt(options.port || '49152', 10);
33+
if (isNaN(port) || port < 1 || port > 65535) {
34+
throw new Error('Invalid port number. Port number must be an integer between 1 and 65535.');
35+
}
3136
} catch (error: any) {
3237
console.log(`[smartui] Error: ${error.message}`);
3338
process.exit();
@@ -75,7 +80,8 @@ export default (options: Record<string, string>): Context => {
7580
options: {
7681
parallel: options.parallel ? true : false,
7782
markBaseline: options.markBaseline ? true : false,
78-
buildName: options.buildName || ''
83+
buildName: options.buildName || '',
84+
port: port
7985
},
8086
cliVersion: version,
8187
totalSnapshots: -1

src/lib/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export default async (ctx: Context): Promise<FastifyInstance<Server, IncomingMes
5757
return reply.code(replyCode).send(replyBody);
5858
});
5959

60-
61-
await server.listen({ port: 49152 });
60+
let portNumber = ctx.options.port
61+
await server.listen({ port: portNumber });
6262
// store server's address for SDK
6363
let { port } = server.addresses()[0];
6464
process.env.SMARTUI_SERVER_ADDRESS = `http://localhost:${port}`;

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface Context {
3030
parallel?: boolean,
3131
markBaseline?: boolean,
3232
buildName?: string,
33+
port?: number,
3334
}
3435
cliVersion: string;
3536
totalSnapshots: number;

0 commit comments

Comments
 (0)