Skip to content

Commit 88e8f59

Browse files
committed
minor code cleanup
1 parent f96fe16 commit 88e8f59

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

src/commands/run.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ export default class RunProject {
9191
this.exitHandler();
9292
}
9393

94+
public onReady(): void {
95+
if (this.config && this.config.run_settings.realTimeLogs) {
96+
const realTime = io.connect('https://hub.testingbot.com:3031');
97+
realTime.emit('join', `cypress_${this.projectId}`);
98+
realTime.on('cypress_data', this.realTimeMessage.bind(this));
99+
realTime.on('cypress_error', this.realTimeError.bind(this));
100+
}
101+
}
102+
94103
private registerCloseHandlers(): void {
95104
//do something when app is closing
96105
process.on('exit', this.exitHandler.bind(this, { cleanup: true }));
@@ -161,7 +170,7 @@ export default class RunProject {
161170

162171
this.archiver = new Archiver(config);
163172
this.uploader = new Uploader(config);
164-
this.poller = new Poller(config);
173+
this.poller = new Poller(config, this);
165174
this.tunnel = new Tunnel(config);
166175

167176
let zipFile: string;
@@ -192,13 +201,6 @@ export default class RunProject {
192201
this.projectId = response.id;
193202
uploadSpinner.succeed('Cypress Project is now running on TestingBot');
194203

195-
if (config.run_settings.realTimeLogs) {
196-
const realTime = io.connect('https://hub.testingbot.com:3031');
197-
realTime.emit('join', `cypress_${response.id}`);
198-
realTime.on('cypress_data', this.realTimeMessage.bind(this));
199-
realTime.on('cypress_error', this.realTimeError.bind(this));
200-
}
201-
202204
const poller = await this.poller.check(response.id, uploadSpinner);
203205
const testCases = this.parseTestCases(poller.runs);
204206
const success = this.parseSuccess(poller.runs);

src/utils/archiver.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ export default class Archiver {
1414

1515
public async start(): Promise<string> {
1616
return new Promise((resolve, reject) => {
17-
let tempZipFile: string | undefined;
18-
1917
try {
20-
tempZipFile = path.join(os.tmpdir(), 'upload.zip');
18+
const tempZipFile = path.join(os.tmpdir(), 'upload.zip');
2119
const output = fs.createWriteStream(tempZipFile);
2220
const archive = archiver('zip', {
2321
zlib: { level: 9 },

src/utils/poller.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import request from 'request';
22
import { IConfig } from './config';
33
import log from '../log';
44
import ora from 'ora';
5+
import RunProject from '../commands/run';
56

67
interface IEnvironment {
78
name: string;
@@ -42,9 +43,11 @@ export default class Poller {
4243
private static readonly MAX_RETRIES_WAITING = 60;
4344
private static readonly MAX_RETRIES_READY = 900;
4445
private initSuccess = false;
46+
private runner: RunProject;
4547

46-
constructor(config: IConfig) {
48+
constructor(config: IConfig, runner: RunProject) {
4749
this.config = config;
50+
this.runner = runner;
4851
}
4952

5053
public async check(id: number, spinner: ora.Ora): Promise<IPollResponse> {
@@ -109,6 +112,8 @@ OS: ${testCase.environment.os}
109112
View live stream https://testingbot.com/members/tests/${testCase.sessionId}`);
110113
}
111114
}
115+
116+
this.runner.onReady()
112117
}
113118

114119
this.retryNumber += 1;

0 commit comments

Comments
 (0)