Skip to content

Commit 4911d40

Browse files
Roshan NikamRoshan Nikam
authored andcommitted
added spec for raw logs
1 parent 9c2b2f4 commit 4911d40

File tree

5 files changed

+85
-32
lines changed

5 files changed

+85
-32
lines changed

test/unit/bin/commands/info.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ logger.transports["console.info"].silent = true;
1414

1515
describe("buildInfo", () => {
1616
let args = testObjects.buildInfoSampleArgs;
17+
let rawArgs = testObjects.buildInfoSampleRawArgs;
1718
let body = testObjects.buildInfoSampleBody;
1819
let bsConfig = testObjects.sampleBsConfig;
1920

@@ -66,12 +67,12 @@ describe("buildInfo", () => {
6667

6768
validateBstackJsonStub.returns(Promise.resolve(bsConfig));
6869

69-
return info(args)
70+
return info(args, rawArgs)
7071
.then(function (_bsConfig) {
7172
sinon.assert.calledOnce(requestStub);
7273
sinon.assert.calledOnce(getConfigPathStub);
7374
sinon.assert.calledOnce(getUserAgentStub);
74-
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
75+
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs);
7576
}).catch((error) => {
7677
chai.assert.isNotOk(error,'Promise error');
7778
});
@@ -104,12 +105,12 @@ describe("buildInfo", () => {
104105

105106
validateBstackJsonStub.returns(Promise.resolve(bsConfig));
106107

107-
return info(args)
108+
return info(args, rawArgs)
108109
.then(function (_bsConfig) {
109110
sinon.assert.calledOnce(requestStub);
110111
sinon.assert.calledOnce(getUserAgentStub);
111112
sinon.assert.calledOnce(getConfigPathStub);
112-
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
113+
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs);
113114
})
114115
.catch((error) => {
115116
chai.assert.isNotOk(error, "Promise error");
@@ -166,12 +167,12 @@ describe("buildInfo", () => {
166167

167168
validateBstackJsonStub.returns(Promise.resolve(bsConfig));
168169

169-
return info(args)
170+
return info(args, rawArgs)
170171
.then(function (_bsConfig) {
171172
sinon.assert.calledOnce(requestStub);
172173
sinon.assert.calledOnce(getUserAgentStub);
173174
sinon.assert.calledOnce(getConfigPathStub);
174-
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
175+
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs);
175176
})
176177
.catch((error) => {
177178
chai.assert.isNotOk(error, "Promise error");
@@ -210,12 +211,12 @@ describe("buildInfo", () => {
210211

211212
validateBstackJsonStub.returns(Promise.resolve(bsConfig));
212213

213-
return info(args)
214+
return info(args, rawArgs)
214215
.then(function (_bsConfig) {
215216
sinon.assert.calledOnce(requestStub);
216217
sinon.assert.calledOnce(getUserAgentStub);
217218
sinon.assert.calledOnce(getConfigPathStub);
218-
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
219+
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs);
219220
})
220221
.catch((error) => {
221222
chai.assert.isNotOk(error, "Promise error");
@@ -249,12 +250,12 @@ describe("buildInfo", () => {
249250

250251
validateBstackJsonStub.returns(Promise.resolve(bsConfig));
251252

252-
return info(args)
253+
return info(args, rawArgs)
253254
.then(function (_bsConfig) {
254255
sinon.assert.calledOnce(requestStub);
255256
sinon.assert.calledOnce(getUserAgentStub);
256257
sinon.assert.calledOnce(getConfigPathStub);
257-
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
258+
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs);
258259
})
259260
.catch((error) => {
260261
chai.assert.isNotOk(error, "Promise error");
@@ -311,12 +312,12 @@ describe("buildInfo", () => {
311312

312313
validateBstackJsonStub.returns(Promise.resolve(bsConfig));
313314

314-
return info(args)
315+
return info(args, rawArgs)
315316
.then(function (_bsConfig) {
316317
sinon.assert.calledOnce(requestStub);
317318
sinon.assert.calledOnce(getUserAgentStub);
318319
sinon.assert.calledOnce(getConfigPathStub);
319-
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
320+
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs);
320321
}).catch((error) => {
321322
chai.assert.isNotOk(error,'Promise error');
322323
});
@@ -363,11 +364,11 @@ describe("buildInfo", () => {
363364

364365
validateBstackJsonStub.returns(Promise.reject({ message: "reject error" }));
365366

366-
return info(args)
367+
return info(args, rawArgs)
367368
.then(function (_bsConfig) {
368369
chai.assert.fail("Promise error");
369370
}).catch((error) => {
370-
sinon.assert.calledOnceWithExactly(sendUsageReportStub, null, args, "reject error", Constants.messageTypes.ERROR, "random-error");
371+
sinon.assert.calledOnceWithExactly(sendUsageReportStub, null, args, "reject error", Constants.messageTypes.ERROR, "random-error", null, rawArgs);
371372
});
372373
});
373374
});

test/unit/bin/commands/init.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ logger.transports["console.info"].silent = true;
2121

2222
describe("init", () => {
2323
let args = testObjects.initSampleArgs;
24+
let rawArgs = testObjects.initSampleRawArgs;
2425
var sandbox;
2526

2627
beforeEach(() => {
@@ -132,10 +133,10 @@ describe("init", () => {
132133
}
133134
});
134135

135-
init(args);
136+
init(args, rawArgs);
136137
sinon.assert.calledOnce(dirExistsStub);
137138
sinon.assert.notCalled(writeStub);
138-
sinon.assert.calledOnceWithExactly(sendUsageReportStub, null, args, Constants.userMessages.DIR_NOT_FOUND, Constants.messageTypes.ERROR, 'path_to_init_not_found');
139+
sinon.assert.calledOnceWithExactly(sendUsageReportStub, null, args, Constants.userMessages.DIR_NOT_FOUND, Constants.messageTypes.ERROR, 'path_to_init_not_found', null, rawArgs);
139140
});
140141

141142
it("fail if browserstack.json is already present", () => {
@@ -154,11 +155,11 @@ describe("init", () => {
154155
},
155156
});
156157

157-
init(args);
158+
init(args, rawArgs);
158159
sinon.assert.calledOnce(dirExistsStub);
159160
sinon.assert.calledOnce(fileExistsStub);
160161
sinon.assert.notCalled(writeStub);
161-
sinon.assert.calledOnceWithExactly(sendUsageReportStub, null, args, Constants.userMessages.CONFIG_FILE_EXISTS, Constants.messageTypes.ERROR, 'bstack_json_already_exists');
162+
sinon.assert.calledOnceWithExactly(sendUsageReportStub, null, args, Constants.userMessages.CONFIG_FILE_EXISTS, Constants.messageTypes.ERROR, 'bstack_json_already_exists', null, rawArgs);
162163
});
163164

164165
it("create browserstack.json if not already present", () => {
@@ -178,7 +179,7 @@ describe("init", () => {
178179
},
179180
});
180181

181-
init(args);
182+
init(args, rawArgs);
182183
sinon.assert.calledOnce(dirExistsStub);
183184
sinon.assert.calledOnce(fileExistsStub);
184185
sinon.assert.calledOnce(writeStub);

test/unit/bin/commands/runs.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ logger.transports["console.info"].silent = true;
1313

1414
describe("runs", () => {
1515
let args = testObjects.runSampleArgs;
16+
let rawArgs = testObjects.runSampleRawArgs;
1617
let bsConfig = testObjects.sampleBsConfig;
1718

1819
describe("handle browserstack.json not valid", () => {
@@ -160,7 +161,7 @@ describe("runs", () => {
160161
setupLocalTestingStub.returns(Promise.resolve("return nothing"));
161162
capabilityValidatorStub.returns(Promise.reject("random-error"));
162163

163-
return runs(args)
164+
return runs(args, rawArgs)
164165
.then(function (_bsConfig) {
165166
chai.assert.fail("Promise error");
166167
})
@@ -195,7 +196,9 @@ describe("runs", () => {
195196
args,
196197
message,
197198
messageType,
198-
errorCode
199+
errorCode,
200+
null,
201+
rawArgs
199202
);
200203
});
201204
});
@@ -310,7 +313,7 @@ describe("runs", () => {
310313
packageInstallerStub.returns(Promise.resolve({ packageArchieveCreated: false }));
311314
archiverStub.returns(Promise.reject("random-error"));
312315

313-
return runs(args)
316+
return runs(args, rawArgs)
314317
.then(function (_bsConfig) {
315318
chai.assert.fail("Promise error");
316319
})
@@ -347,7 +350,9 @@ describe("runs", () => {
347350
args,
348351
message,
349352
messageType,
350-
errorCode
353+
errorCode,
354+
null,
355+
rawArgs
351356
);
352357
});
353358
});
@@ -467,7 +472,7 @@ describe("runs", () => {
467472
archiverStub.returns(Promise.resolve("Zipping completed"));
468473
zipUploadStub.returns(Promise.reject("random-error"));
469474

470-
return runs(args)
475+
return runs(args, rawArgs)
471476
.then(function (_bsConfig) {
472477
chai.assert.fail("Promise error");
473478
})
@@ -500,7 +505,9 @@ describe("runs", () => {
500505
args,
501506
message,
502507
messageType,
503-
errorCode
508+
errorCode,
509+
null,
510+
rawArgs
504511
);
505512
})
506513
.finally(function () {
@@ -633,7 +640,7 @@ describe("runs", () => {
633640
stopLocalBinaryStub.returns(Promise.resolve("nothing"));
634641
createBuildStub.returns(Promise.reject("random-error"));
635642

636-
return runs(args)
643+
return runs(args, rawArgs)
637644
.then(function (_bsConfig) {
638645
chai.assert.fail("Promise error");
639646
})
@@ -671,7 +678,9 @@ describe("runs", () => {
671678
args,
672679
message,
673680
messageType,
674-
errorCode
681+
errorCode,
682+
null,
683+
rawArgs
675684
);
676685
});
677686
});
@@ -835,7 +844,7 @@ describe("runs", () => {
835844
getParallelsStub.returns(10);
836845
createBuildStub.returns(Promise.resolve({ message: 'Success', build_id: 'random_build_id', dashboard_url: dashboardUrl, user_id: 1234 }));
837846

838-
return runs(args)
847+
return runs(args, rawArgs)
839848
.then(function (_bsConfig) {
840849
chai.assert.fail("Promise error");
841850
})
@@ -875,7 +884,8 @@ describe("runs", () => {
875884
`${message}\n${dashboardLink}`,
876885
messageType,
877886
errorCode,
878-
data
887+
data,
888+
rawArgs
879889
]
880890
);
881891
});

test/unit/bin/commands/stop.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ logger.transports["console.info"].silent = true;
1414

1515
describe("buildStop", () => {
1616
let args = testObjects.buildStopSampleArgs;
17+
let rawArgs = testObjects.buildStopSampleRawArgs;
1718
let body = testObjects.buildStopSampleBody;
1819
let bsConfig = testObjects.sampleBsConfig;
1920

@@ -60,7 +61,7 @@ describe("buildStop", () => {
6061

6162
validateBstackJsonStub.returns(Promise.resolve(bsConfig));
6263

63-
return stop(args)
64+
return stop(args, rawArgs)
6465
.then(function (_bsConfig) {
6566
sinon.assert.calledOnce(stopBrowserStackBuildStub);
6667
})
@@ -109,7 +110,7 @@ describe("buildStop", () => {
109110
Promise.reject({ message: "reject error" })
110111
);
111112

112-
return stop(args)
113+
return stop(args, rawArgs)
113114
.then(function (_bsConfig) {
114115
chai.assert.fail("Promise error");
115116
})
@@ -120,7 +121,9 @@ describe("buildStop", () => {
120121
args,
121122
"reject error",
122123
Constants.messageTypes.ERROR,
123-
"random-error"
124+
"random-error",
125+
null,
126+
rawArgs
124127
);
125128
});
126129
});

test/unit/support/fixtures/testObjects.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ const initSampleArgs = {
3232
$0: "browserstack-cypress",
3333
};
3434

35+
const initSampleRawArgs = {
36+
_: ["init"],
37+
p: false,
38+
$0: "browserstack-cypress",
39+
}
40+
3541
const buildInfoSampleArgs = {
3642
_: ["build-info", "f3c94f7203792d03a75be3912d19354fe0961e53"],
3743
cf: "browserstack.json",
@@ -42,6 +48,11 @@ const buildInfoSampleArgs = {
4248
$0: "browserstack-cypress",
4349
};
4450

51+
const buildInfoSampleRawArgs = {
52+
_: ["build-info", "f3c94f7203792d03a75be3912d19354fe0961e53"],
53+
$0: "browserstack-cypress",
54+
};
55+
4556
const generateReportInputArgs = {
4657
_: ["generate-report", "f3c94f7203792d03a75be3912d19354fe0961e53"],
4758
cf: "browserstack.json",
@@ -52,6 +63,11 @@ const generateReportInputArgs = {
5263
$0: "browserstack-cypress",
5364
};
5465

66+
const generateReportInputRawArgs = {
67+
_: ["generate-report", "f3c94f7203792d03a75be3912d19354fe0961e53"],
68+
$0: "browserstack-cypress",
69+
};
70+
5571
const generateDownloadsInputArgs = {
5672
_: ["generate-downloads", "f3c94f7203792d03a75be3912d19354fe0961e53"],
5773
cf: "browserstack.json",
@@ -62,6 +78,11 @@ const generateDownloadsInputArgs = {
6278
$0: "browserstack-cypress",
6379
};
6480

81+
const generateDownloadsInputRawArgs = {
82+
_: ["generate-downloads", "f3c94f7203792d03a75be3912d19354fe0961e53"],
83+
$0: "browserstack-cypress",
84+
};
85+
6586
const buildInfoSampleBody = {
6687
build_id: "random_hashed_id",
6788
framework: "cypress",
@@ -124,6 +145,11 @@ const buildStopSampleArgs = {
124145
$0: "browserstack-cypress",
125146
};
126147

148+
const buildStopSampleRawArgs = {
149+
_: ["build-stop", "f3c94f7203792d03a75be3912d19354fe0961e53"],
150+
$0: "browserstack-cypress",
151+
};
152+
127153
const buildStopSampleBody = {
128154
message: "stopped 1 sessions",
129155
stopped_session_count: 1,
@@ -145,16 +171,28 @@ const runSampleArgs = {
145171
$0: "browserstack-cypress",
146172
};
147173

174+
const runSampleRawArgs = {
175+
_: ["run"],
176+
p: undefined,
177+
$0: "browserstack-cypress",
178+
};
179+
148180
module.exports = Object.freeze({
149181
sampleBsConfig,
150182
sampleBsConfigWithParallels,
151183
initSampleArgs,
184+
initSampleRawArgs,
152185
buildInfoSampleArgs,
186+
buildInfoSampleRawArgs,
153187
buildInfoSampleBody,
154188
buildStopSampleArgs,
189+
buildStopSampleRawArgs,
155190
buildStopSampleBody,
156191
sampleCapsData,
157192
runSampleArgs,
193+
runSampleRawArgs,
158194
generateReportInputArgs,
195+
generateReportInputRawArgs,
159196
generateDownloadsInputArgs,
197+
generateDownloadsInputRawArgs
160198
});

0 commit comments

Comments
 (0)