Skip to content

Commit 40322ac

Browse files
committed
add more config/cli options
1 parent da35147 commit 40322ac

File tree

7 files changed

+118
-9
lines changed

7 files changed

+118
-9
lines changed

src/commands/run.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import io from 'socket.io-client';
1212
interface Arguments {
1313
[x: string]: unknown;
1414
cf: string | boolean;
15+
group?: string;
16+
headless?: boolean;
17+
parallel?: number;
18+
e?: string;
19+
s?: string;
1520
}
1621

1722
interface ISocketData {
@@ -27,11 +32,13 @@ export default class RunProject {
2732
private configFilePath: string | undefined = undefined;
2833
private config: IConfig | undefined = undefined;
2934
private projectId: number | undefined = undefined;
35+
private argv: Arguments;
3036

3137
constructor(argv: Arguments) {
3238
if (typeof argv.cf === 'string') {
3339
this.configFilePath = argv.cf;
3440
}
41+
this.argv = argv;
3542
}
3643

3744
public exitHandler(): void {
@@ -140,6 +147,26 @@ export default class RunProject {
140147
return testCases;
141148
}
142149

150+
private applyArgsToConfig(): void {
151+
if (this.config) {
152+
if (this.argv.group) {
153+
this.config.run_settings.build_name = this.argv.group;
154+
}
155+
if (this.argv.headless) {
156+
this.config.run_settings.headless = this.argv.headless;
157+
}
158+
if (this.argv.parallel) {
159+
this.config.run_settings.parallel = this.argv.parallel;
160+
}
161+
if (this.argv.e) {
162+
this.config.run_settings.cypressEnv = this.argv.e.split(',');
163+
}
164+
if (this.argv.s) {
165+
this.config.run_settings.cypressSpecs = this.argv.s;
166+
}
167+
}
168+
}
169+
143170
public async start(): Promise<void> {
144171
let config: IConfig;
145172
try {
@@ -168,10 +195,12 @@ export default class RunProject {
168195

169196
this.config = config;
170197

171-
this.archiver = new Archiver(config);
172-
this.uploader = new Uploader(config);
173-
this.poller = new Poller(config, this);
174-
this.tunnel = new Tunnel(config);
198+
this.applyArgsToConfig();
199+
200+
this.archiver = new Archiver(this.config);
201+
this.uploader = new Uploader(this.config);
202+
this.poller = new Poller(this.config, this);
203+
this.tunnel = new Tunnel(this.config);
175204

176205
let zipFile: string;
177206

@@ -180,7 +209,7 @@ export default class RunProject {
180209
return;
181210
}
182211

183-
if (config.run_settings.start_tunnel) {
212+
if (this.config.run_settings.start_tunnel) {
184213
const tunnelSpinner = ora('Starting TestingBot Tunnel').start();
185214
await this.tunnel.start();
186215
tunnelSpinner.succeed('TestingBot Tunnel Ready');

src/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,35 @@ yargs
3838
type: 'string',
3939
demand: true,
4040
},
41+
group: {
42+
default: undefined,
43+
description: 'Group the specs under this name',
44+
type: 'string',
45+
nargs: 1,
46+
},
47+
headless: {
48+
default: false,
49+
description: 'Run tests in headless mode on TestingBot (no UI)',
50+
type: 'boolean',
51+
},
52+
parallel: {
53+
default: 1,
54+
description: 'Run tests in parallel on TestingBot',
55+
type: 'number',
56+
},
57+
s: {
58+
alias: ['specs', 'spec'],
59+
default: undefined,
60+
description: 'Runs specific spec file(s). defaults to "all"',
61+
type: 'string',
62+
},
63+
e: {
64+
alias: 'env',
65+
describe:
66+
'Sets environment variables. separate multiple values with a comma',
67+
type: 'string',
68+
default: undefined,
69+
},
4170
})
4271
.help('help')
4372
.wrap(null).argv;

src/templates/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export default (): string => {
2020
start_tunnel: true,
2121
local_ports: [],
2222
realTimeLogs: true,
23+
headless: false,
24+
parallel: 1,
2325
},
2426
tunnel_settings: {
2527
verbose: false,

src/utils/archiver.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,22 @@ export default class Archiver {
6969
) {
7070
ignoredPaths = ignoredPaths.concat(this.config.run_settings.exclude);
7171
}
72-
allowedFileTypes.forEach((fileType) => {
73-
archive.glob(`**/*.${fileType}`, {
72+
73+
if (!this.config.run_settings.cypressSpecs) {
74+
allowedFileTypes.forEach((fileType) => {
75+
archive.glob(`**/*.${fileType}`, {
76+
cwd: this.config.run_settings.cypress_project_dir,
77+
matchBase: true,
78+
ignore: ignoredPaths,
79+
});
80+
});
81+
} else {
82+
archive.glob(this.config.run_settings.cypressSpecs, {
7483
cwd: this.config.run_settings.cypress_project_dir,
7584
matchBase: true,
7685
ignore: ignoredPaths,
7786
});
78-
});
87+
}
7988

8089
const packageJSON = {};
8190

src/utils/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export interface ICapability {
1313
version: string | number;
1414
localHttpPorts?: number[];
1515
build?: string;
16+
headless?: boolean;
17+
cypressEnv?: string[];
18+
cypressVersion?: string;
1619
}
1720

1821
interface IRunSettings {
@@ -24,6 +27,11 @@ interface IRunSettings {
2427
local_ports: number[];
2528
exclude: string[];
2629
realTimeLogs: boolean;
30+
parallel: number;
31+
headless: boolean;
32+
cypressEnv: string[];
33+
cypressSpecs: string;
34+
cypressVersion: string;
2735
}
2836

2937
export interface IConfig {

src/utils/poller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ View live stream https://testingbot.com/members/tests/${testCase.sessionId}`);
113113
}
114114
}
115115

116-
this.runner.onReady()
116+
this.runner.onReady();
117117
}
118118

119119
this.retryNumber += 1;

src/utils/uploader.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'fs';
22
import request from 'request';
3+
import os from 'os';
34
import { IConfig, ICapability } from './config';
45

56
interface IResponse {
@@ -31,6 +32,33 @@ export default class Uploader {
3132
capability.build = this.config.run_settings.build_name;
3233
});
3334
}
35+
36+
if (this.config.run_settings.headless) {
37+
capabilities.map((capability: ICapability) => {
38+
capability.headless = this.config.run_settings.headless;
39+
});
40+
}
41+
42+
if (this.config.run_settings.cypressEnv) {
43+
capabilities.map((capability: ICapability) => {
44+
capability.cypressEnv = this.config.run_settings.cypressEnv;
45+
});
46+
}
47+
48+
if (this.config.run_settings.cypressVersion) {
49+
capabilities.map((capability: ICapability) => {
50+
capability.cypressVersion = this.config.run_settings.cypressVersion;
51+
});
52+
}
53+
54+
const runSettings = {
55+
parallel: 1,
56+
};
57+
58+
if (this.config.run_settings.parallel) {
59+
runSettings.parallel = this.config.run_settings.parallel;
60+
}
61+
3462
const requestOptions = {
3563
method: 'POST',
3664
uri: `https://api.testingbot.com/v1/cypress`,
@@ -42,6 +70,10 @@ export default class Uploader {
4270
formData: {
4371
file: fs.createReadStream(zipFile),
4472
capabilities: JSON.stringify(capabilities),
73+
settings: JSON.stringify(runSettings),
74+
},
75+
headers: {
76+
'User-Agent': `TB-Cypress-CLI (${os.arch()}/${os.platform()}/${os.release()})`,
4577
},
4678
};
4779

0 commit comments

Comments
 (0)