Skip to content

Commit ed7dfea

Browse files
authored
Merge pull request #96 from parthlambdatest/Dot-3434
[Dot-3434] Enable usage of custom port for smartui
2 parents 3507392 + 17ba581 commit ed7dfea

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

src/commander/exec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ 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());
2122

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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ 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+
await server.listen({ port: ctx.options.port });
6261
// store server's address for SDK
6362
let { port } = server.addresses()[0];
6463
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)