Skip to content

Commit f8318f3

Browse files
chore: update test mocks for improved isolation and reliability
1 parent 0b0fc9a commit f8318f3

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

src/tools/get-failure-logs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export async function getFailureLogs(
9191
text: `No valid log types found for ${args.sessionType} session.\nErrors encountered:\n${errors.join("\n")}`,
9292
},
9393
],
94+
isError: true,
9495
};
9596
}
9697
let response;

tests/tools/getFailureLogs.test.ts

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ describe('BrowserStack Failure Logs', () => {
9090
sessionType: 'automate'
9191
}, mockServer);
9292

93-
expect(result.content?.[0]?.isError).toBe(true);
94-
expect(result.content?.[0]?.text).toContain('Invalid log type');
93+
expect(result.isError).toBe(true);
94+
expect(result.content?.[0]?.type).toBe('text');
95+
if (result.content?.[0]?.type === 'text') {
96+
expect(result.content[0].text).toContain('Invalid log type');
97+
}
9598
});
9699

97100
it('should return error when mixing session types', async () => {
@@ -109,8 +112,8 @@ describe('BrowserStack Failure Logs', () => {
109112
sessionType: 'app-automate'
110113
}, mockServer);
111114

112-
expect(automateResult.content?.[0]?.isError).toBe(true);
113-
expect(appAutomateResult.content?.[0]?.isError).toBe(true);
115+
expect(automateResult.isError).toBe(true);
116+
expect(appAutomateResult.isError).toBe(true);
114117
});
115118
});
116119

@@ -150,7 +153,9 @@ describe('BrowserStack Failure Logs', () => {
150153

151154
expect(automate.retrieveNetworkFailures).toHaveBeenCalledWith(mockSessionId, expect.anything());
152155
expect(result.content?.[0]?.type).toBe('text');
153-
expect(result.content?.[0]?.text).toContain('Network Failures (1 found)');
156+
if (result.content?.[0]?.type === 'text') {
157+
expect(result.content[0].text).toContain('Network Failures (1 found)');
158+
}
154159
});
155160

156161
it('should fetch session logs successfully', async () => {
@@ -162,8 +167,10 @@ describe('BrowserStack Failure Logs', () => {
162167
}, mockServer);
163168

164169
expect(automate.retrieveSessionFailures).toHaveBeenCalledWith(mockSessionId, expect.anything());
165-
expect(result.content?.[0]?.text).toContain('Session Failures (1 found)');
166-
expect(result.content?.[0]?.text).toContain('[ERROR] Test failed');
170+
if (result.content?.[0]?.type === 'text') {
171+
expect(result.content[0].text).toContain('Session Failures (1 found)');
172+
expect(result.content[0].text).toContain('[ERROR] Test failed');
173+
}
167174
});
168175

169176
it('should fetch console logs successfully', async () => {
@@ -175,8 +182,10 @@ describe('BrowserStack Failure Logs', () => {
175182
}, mockServer);
176183

177184
expect(automate.retrieveConsoleFailures).toHaveBeenCalledWith(mockSessionId, expect.anything());
178-
expect(result.content?.[0]?.text).toContain('Console Failures (1 found)');
179-
expect(result.content?.[0]?.text).toContain('Uncaught TypeError');
185+
if (result.content?.[0]?.type === 'text') {
186+
expect(result.content[0].text).toContain('Console Failures (1 found)');
187+
expect(result.content[0].text).toContain('Uncaught TypeError');
188+
}
180189
});
181190
});
182191

@@ -203,8 +212,10 @@ describe('BrowserStack Failure Logs', () => {
203212
}, mockServer);
204213

205214
expect(appAutomate.retrieveDeviceLogs).toHaveBeenCalledWith(mockSessionId, mockBuildId, expect.anything());
206-
expect(result.content?.[0]?.text).toContain('Device Failures (1 found)');
207-
expect(result.content?.[0]?.text).toContain('Fatal Exception');
215+
if (result.content?.[0]?.type === 'text') {
216+
expect(result.content[0].text).toContain('Device Failures (1 found)');
217+
expect(result.content[0].text).toContain('Fatal Exception');
218+
}
208219
});
209220

210221
it('should fetch appium logs successfully', async () => {
@@ -217,8 +228,10 @@ describe('BrowserStack Failure Logs', () => {
217228
}, mockServer);
218229

219230
expect(appAutomate.retrieveAppiumLogs).toHaveBeenCalledWith(mockSessionId, mockBuildId, expect.anything());
220-
expect(result.content?.[0]?.text).toContain('Appium Failures (1 found)');
221-
expect(result.content?.[0]?.text).toContain('Element not found');
231+
if (result.content?.[0]?.type === 'text') {
232+
expect(result.content[0].text).toContain('Appium Failures (1 found)');
233+
expect(result.content[0].text).toContain('Element not found');
234+
}
222235
});
223236

224237
it('should fetch crash logs successfully', async () => {
@@ -231,8 +244,10 @@ describe('BrowserStack Failure Logs', () => {
231244
}, mockServer);
232245

233246
expect(appAutomate.retrieveCrashLogs).toHaveBeenCalledWith(mockSessionId, mockBuildId, expect.anything());
234-
expect(result.content?.[0]?.text).toContain('Crash Failures (1 found)');
235-
expect(result.content?.[0]?.text).toContain('signal 11');
247+
if (result.content?.[0]?.type === 'text') {
248+
expect(result.content[0].text).toContain('Crash Failures (1 found)');
249+
expect(result.content[0].text).toContain('signal 11');
250+
}
236251
});
237252
});
238253

@@ -247,7 +262,9 @@ describe('BrowserStack Failure Logs', () => {
247262
sessionType: 'automate'
248263
}, mockServer);
249264

250-
expect(result.content?.[0]?.text).toBe('No network failures found');
265+
if (result.content?.[0]?.type === 'text') {
266+
expect(result.content[0].text).toBe('No network failures found');
267+
}
251268
});
252269
});
253270

tests/tools/testmanagement.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ vi.mock('../../src/tools/testmanagement-utils/testcase-from-file', () => ({
4747
createTestCasesFromFile: vi.fn(),
4848
}));
4949

50+
vi.mock('../../src/tools/testmanagement-utils/TCG-utils/types', () => ({
51+
CreateTestCasesFromFileSchema: {
52+
parse: (args: any) => args,
53+
shape: {},
54+
},
55+
}));
56+
5057
vi.mock('../../src/tools/testmanagement-utils/create-lca-steps', () => ({
5158
createLCASteps: vi.fn(),
5259
CreateLCAStepsSchema: {

0 commit comments

Comments
 (0)