Skip to content

Commit 56e432c

Browse files
committed
test: add more tests for android livesync tool and lint
1 parent 8b7795f commit 56e432c

File tree

3 files changed

+256
-98
lines changed

3 files changed

+256
-98
lines changed

lib/services/livesync/android-livesync-tool.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ import * as crypto from "crypto";
44
const PROTOCOL_VERSION_LENGTH_SIZE = 1;
55
const PROTOCOL_OPERATION_LENGTH_SIZE = 1;
66
const SIZE_BYTE_LENGTH = 1;
7-
const ERROR_REPORT = 1;
8-
const OPERATION_END_REPORT = 2;
9-
const OPERATION_END_NO_REFRESH_REPORT_CODE = 3;
107
const REPORT_LENGTH = 1;
118
const DO_REFRESH_LENGTH = 1;
12-
const DO_REFRESH = 1;
13-
const SKIP_REFRESH = 0;
149
const SYNC_OPERATION_TIMEOUT = 60000;
1510
const TRY_CONNECT_TIMEOUT = 30000;
1611
const DEFAULT_LOCAL_HOST_ADDRESS = "127.0.0.1";
@@ -19,6 +14,11 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
1914
public static DELETE_FILE_OPERATION = 7;
2015
public static CREATE_FILE_OPERATION = 8;
2116
public static DO_SYNC_OPERATION = 9;
17+
public static ERROR_REPORT = 1;
18+
public static OPERATION_END_REPORT = 2;
19+
public static OPERATION_END_NO_REFRESH_REPORT_CODE = 3;
20+
public static DO_REFRESH = 1;
21+
public static SKIP_REFRESH = 0;
2222
public protocolVersion: string;
2323
private operationPromises: IDictionary<any>;
2424
private socketError: string | Error;
@@ -50,7 +50,7 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
5050
}
5151

5252
if (!configuration.appPlatformsPath) {
53-
this.$errors.fail(`You need to provide "baseDir" as a configuration property!`);
53+
this.$errors.fail(`You need to provide "appPlatformsPath" as a configuration property!`);
5454
}
5555

5656
if (this.socketConnection) {
@@ -140,7 +140,7 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
140140
const message = `${AndroidLivesyncTool.DO_SYNC_OPERATION}${id}`;
141141
const headerBuffer = Buffer.alloc(Buffer.byteLength(message) + DO_REFRESH_LENGTH);
142142
const socketId = this.socketConnection.uid;
143-
const doRefreshCode = doRefresh ? DO_REFRESH : SKIP_REFRESH;
143+
const doRefreshCode = doRefresh ? AndroidLivesyncTool.DO_REFRESH : AndroidLivesyncTool.SKIP_REFRESH;
144144
const offset = headerBuffer.write(message);
145145

146146
headerBuffer.writeUInt8(doRefreshCode, offset);
@@ -374,13 +374,13 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool {
374374
const reportType = data.readUInt8();
375375
const infoBuffer = data.slice(REPORT_LENGTH, data.length);
376376

377-
if (reportType === ERROR_REPORT) {
377+
if (reportType === AndroidLivesyncTool.ERROR_REPORT) {
378378
const errorMessage = infoBuffer.toString();
379379
this.handleSocketError(socketId, errorMessage);
380-
} else if (reportType === OPERATION_END_REPORT) {
381-
this.handleSyncEnd({data:infoBuffer, didRefresh: true});
382-
} else if (reportType === OPERATION_END_NO_REFRESH_REPORT_CODE) {
383-
this.handleSyncEnd({data:infoBuffer, didRefresh: false});
380+
} else if (reportType === AndroidLivesyncTool.OPERATION_END_REPORT) {
381+
this.handleSyncEnd({data: infoBuffer, didRefresh: true});
382+
} else if (reportType === AndroidLivesyncTool.OPERATION_END_NO_REFRESH_REPORT_CODE) {
383+
this.handleSyncEnd({data: infoBuffer, didRefresh: false});
384384
}
385385
}
386386

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as net from "net";
22

33
class LiveSyncSocket extends net.Socket {
4-
public uid: string
4+
public uid: string;
55
}
66

7-
$injector.register("LiveSyncSocket", LiveSyncSocket, false);
7+
$injector.register("LiveSyncSocket", LiveSyncSocket, false);

0 commit comments

Comments
 (0)