Skip to content

Commit 9dbad6c

Browse files
prettify code
1 parent cb8bd90 commit 9dbad6c

File tree

8 files changed

+135
-80
lines changed

8 files changed

+135
-80
lines changed

src/commands/run.ts

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ interface Arguments {
1515
}
1616

1717
interface ISocketData {
18-
id: number
19-
payload: string
18+
id: number;
19+
payload: string;
2020
}
2121

2222
export default class RunProject {
@@ -29,7 +29,7 @@ export default class RunProject {
2929
private projectId: number | undefined = undefined;
3030

3131
constructor(argv: Arguments) {
32-
if (typeof(argv.cf) === 'string') {
32+
if (typeof argv.cf === 'string') {
3333
this.configFilePath = argv.cf;
3434
}
3535
}
@@ -38,13 +38,16 @@ export default class RunProject {
3838
this.stopJob();
3939
if (this.config && this.config.run_settings.start_tunnel) {
4040
if (this.tunnel) {
41-
this.tunnel.stop().then(() => {
42-
process.exit();
43-
}).catch(log.error);
41+
this.tunnel
42+
.stop()
43+
.then(() => {
44+
process.exit();
45+
})
46+
.catch(log.error);
4447
this.tunnel = undefined;
4548
}
4649
} else {
47-
process.exit()
50+
process.exit();
4851
}
4952
}
5053

@@ -63,9 +66,9 @@ export default class RunProject {
6366
uri: `https://api.testingbot.com/v1/cypress/${this.projectId}/stop_project`,
6467
auth: {
6568
user: this.config ? this.config.auth.key : '',
66-
pass: this.config ? this.config.auth.secret : '',
69+
pass: this.config ? this.config.auth.secret : '',
6770
sendImmediately: true,
68-
}
71+
},
6972
};
7073

7174
request(requestOptions, (error) => {
@@ -79,17 +82,21 @@ export default class RunProject {
7982
}
8083

8184
public errorHandler(err: Error): void {
82-
log.error(chalk.white.bgRed.bold(`A fatal error occurred, please report this to testingbot.com`));
85+
log.error(
86+
chalk.white.bgRed.bold(
87+
`A fatal error occurred, please report this to testingbot.com`,
88+
),
89+
);
8390
log.error(err);
8491
this.exitHandler();
8592
}
8693

8794
private registerCloseHandlers(): void {
8895
//do something when app is closing
89-
process.on('exit', this.exitHandler.bind(this,{cleanup:true}));
90-
process.on('SIGINT', this.exitHandler.bind(this, {exit:true}));
91-
process.on('SIGUSR1', this.exitHandler.bind(this, {exit:true}));
92-
process.on('SIGUSR2', this.exitHandler.bind(this, {exit:true}));
96+
process.on('exit', this.exitHandler.bind(this, { cleanup: true }));
97+
process.on('SIGINT', this.exitHandler.bind(this, { exit: true }));
98+
process.on('SIGUSR1', this.exitHandler.bind(this, { exit: true }));
99+
process.on('SIGUSR2', this.exitHandler.bind(this, { exit: true }));
93100
process.on('uncaughtException', this.errorHandler.bind(this));
94101
}
95102

@@ -113,11 +120,11 @@ export default class RunProject {
113120
}
114121

115122
private parseTestCases(runs: IRun[]): ITest[] {
116-
const testCases: ITest[] = []
123+
const testCases: ITest[] = [];
117124
for (let i = 0; i < runs.length; i++) {
118125
const testCase = runs[i].test;
119126
if (testCase) {
120-
testCases.push(testCase)
127+
testCases.push(testCase);
121128
}
122129
}
123130

@@ -129,14 +136,24 @@ export default class RunProject {
129136
try {
130137
config = await Config.getConfig(this.configFilePath || `testingbot.json`);
131138
} catch (e) {
132-
log.error(chalk.white.bgRed.bold(`Configuration file problem: ${e.message} for Config File: ${this.configFilePath || `testingbot.json`}`));
139+
log.error(
140+
chalk.white.bgRed.bold(
141+
`Configuration file problem: ${e.message} for Config File: ${
142+
this.configFilePath || `testingbot.json`
143+
}`,
144+
),
145+
);
133146
return;
134147
}
135-
148+
136149
const configValidationErrors = Config.validate(config);
137150

138151
if (configValidationErrors.length > 0) {
139-
log.error(chalk.white.bgRed.bold(`Configuration errors: ${configValidationErrors.join('\n')}`));
152+
log.error(
153+
chalk.white.bgRed.bold(
154+
`Configuration errors: ${configValidationErrors.join('\n')}`,
155+
),
156+
);
140157
return;
141158
}
142159

@@ -177,7 +194,7 @@ export default class RunProject {
177194

178195
if (config.run_settings.realTimeLogs) {
179196
const realTime = io.connect('https://hub.testingbot.com:3031');
180-
realTime.emit('join', `cypress_${response.id}`)
197+
realTime.emit('join', `cypress_${response.id}`);
181198
realTime.on('cypress_data', this.realTimeMessage.bind(this));
182199
realTime.on('cypress_error', this.realTimeError.bind(this));
183200
}
@@ -194,7 +211,6 @@ export default class RunProject {
194211
}
195212

196213
process.exit(success === true ? 0 : 1);
197-
198214
} catch (err) {
199215
log.error(chalk.white.bgRed.bold(err));
200216
if (config.run_settings.start_tunnel) {

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ yargs
2525
.help('help')
2626
.wrap(null).argv;
2727

28-
return new InitProject(initArgv);
28+
return new InitProject(initArgv);
2929
})
3030
.command('run', 'more info', function (yargs) {
3131
const initArgv = yargs
@@ -41,9 +41,9 @@ yargs
4141
})
4242
.help('help')
4343
.wrap(null).argv;
44-
const runProject = new RunProject(initArgv);
45-
46-
runProject.start();
44+
const runProject = new RunProject(initArgv);
45+
46+
runProject.start();
4747
})
4848
.alias('h', 'help')
4949
.help('help')

src/templates/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default (): string => {
88
{
99
browserName: 'chrome',
1010
platform: 'MOJAVE',
11-
version: 83
11+
version: 83,
1212
},
1313
],
1414
run_settings: {
@@ -19,11 +19,11 @@ export default (): string => {
1919
package_config_options: {},
2020
start_tunnel: true,
2121
local_ports: [],
22-
realTimeLogs: true
22+
realTimeLogs: true,
2323
},
2424
tunnel_settings: {
25-
verbose: false
26-
}
25+
verbose: false,
26+
},
2727
};
2828

2929
return JSON.stringify(config, null, 4);

src/utils/archiver.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default class Archiver {
5454
'jpg',
5555
'jpeg',
5656
'png',
57-
'zip'
57+
'zip',
5858
];
5959

6060
let ignoredPaths = [
@@ -65,8 +65,11 @@ export default class Archiver {
6565
'testingbot-package.json',
6666
];
6767

68-
if (this.config.run_settings.exclude && this.config.run_settings.exclude.length > 0) {
69-
ignoredPaths = ignoredPaths.concat(this.config.run_settings.exclude)
68+
if (
69+
this.config.run_settings.exclude &&
70+
this.config.run_settings.exclude.length > 0
71+
) {
72+
ignoredPaths = ignoredPaths.concat(this.config.run_settings.exclude);
7073
}
7174
allowedFileTypes.forEach((fileType) => {
7275
archive.glob(`**/*.${fileType}`, {
@@ -78,17 +81,26 @@ export default class Archiver {
7881

7982
const packageJSON = {};
8083

81-
if (typeof this.config.run_settings.package_config_options === 'object') {
82-
Object.assign(packageJSON, this.config.run_settings.package_config_options);
84+
if (
85+
typeof this.config.run_settings.package_config_options === 'object'
86+
) {
87+
Object.assign(
88+
packageJSON,
89+
this.config.run_settings.package_config_options,
90+
);
8391
}
8492

8593
if (typeof this.config.run_settings.npm_dependencies === 'object') {
86-
Object.assign(packageJSON, {devDependencies: this.config.run_settings.npm_dependencies});
94+
Object.assign(packageJSON, {
95+
devDependencies: this.config.run_settings.npm_dependencies,
96+
});
8797
}
8898

8999
if (Object.keys(packageJSON).length > 0) {
90100
const packageJSONString = JSON.stringify(packageJSON, null, 4);
91-
archive.append(packageJSONString, { name: 'testingbot-package.json' });
101+
archive.append(packageJSONString, {
102+
name: 'testingbot-package.json',
103+
});
92104
}
93105

94106
archive.finalize();

src/utils/config.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export interface ICapability {
1616
}
1717

1818
interface IRunSettings {
19-
cypress_project_dir: string
20-
build_name: string
21-
npm_dependencies: any
22-
package_config_options: any
23-
start_tunnel: boolean
24-
local_ports: number[]
25-
exclude: string[]
26-
realTimeLogs: boolean
19+
cypress_project_dir: string;
20+
build_name: string;
21+
npm_dependencies: any;
22+
package_config_options: any;
23+
start_tunnel: boolean;
24+
local_ports: number[];
25+
exclude: string[];
26+
realTimeLogs: boolean;
2727
}
2828

2929
export interface IConfig {
@@ -38,17 +38,23 @@ export default {
3838
const configString = await fsPromises.readFile(configFilePath);
3939
const configObject: IConfig = JSON.parse(configString.toString());
4040

41-
if (configObject.auth.key === '' || configObject.auth.key === '<Your TestingBot key>') {
41+
if (
42+
configObject.auth.key === '' ||
43+
configObject.auth.key === '<Your TestingBot key>'
44+
) {
4245
if (process.env.TESTINGBOT_KEY) {
4346
configObject.auth.key = process.env.TESTINGBOT_KEY;
4447
}
4548
}
46-
if (configObject.auth.secret === '' || configObject.auth.secret === '<Your TestingBot secret>') {
49+
if (
50+
configObject.auth.secret === '' ||
51+
configObject.auth.secret === '<Your TestingBot secret>'
52+
) {
4753
if (process.env.TESTINGBOT_SECRET) {
4854
configObject.auth.secret = process.env.TESTINGBOT_SECRET;
4955
}
5056
}
51-
57+
5258
return configObject;
5359
},
5460

0 commit comments

Comments
 (0)