Skip to content

Commit 290447f

Browse files
Merge pull request #98 from LambdaTest/stage
Release v3.0.11
2 parents 0022acb + 188122c commit 290447f

File tree

6 files changed

+12
-5
lines changed

6 files changed

+12
-5
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/smartui-cli",
3-
"version": "3.0.10",
3+
"version": "3.0.11",
44
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
55
"files": [
66
"dist/**/*"

src/commander/exec.ts

+1
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

+7-1
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/processSnapshot.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default async (snapshot: Snapshot, ctx: Context): Promise<Record<string,
1717
javaScriptEnabled: ctx.config.enableJavaScript,
1818
userAgent: constants.CHROME_USER_AGENT,
1919
}
20-
if (!ctx.browser) {
20+
if (!ctx.browser?.isConnected()) {
2121
if (ctx.env.HTTP_PROXY || ctx.env.HTTPS_PROXY) launchOptions.proxy = { server: ctx.env.HTTP_PROXY || ctx.env.HTTPS_PROXY };
2222
ctx.browser = await chromium.launch(launchOptions);
2323
ctx.log.debug(`Chromium launched with options ${JSON.stringify(launchOptions)}`);

src/lib/server.ts

+1-2
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

+1
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)