Skip to content

Commit af0f0e3

Browse files
committed
refactor: split stackTrace test and fix mock to store constructor params
Split '0-based line' test into separate location and stackTrace tests. Fix FakeTestMessageStackFrame to store label, uri, position so stackTrace assertions can verify 0-based line numbers.
1 parent a37c8af commit af0f0e3

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

packages/extension/__mocks__/vscode.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,16 @@ class FakeEventEmitter<T = void> {
462462
}
463463
const EventEmitter = FakeEventEmitter;
464464

465-
class FakeTestMessageStackFrame {}
465+
class FakeTestMessageStackFrame {
466+
label: string;
467+
uri?: any;
468+
position?: any;
469+
constructor(label: string, uri?: any, position?: any) {
470+
this.label = label;
471+
this.uri = uri;
472+
this.position = position;
473+
}
474+
}
466475
const TestMessageStackFrame = FakeTestMessageStackFrame;
467476

468477
const extensions = {

packages/extension/src/Observers/TestResultObserver.test.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe('TestResultObserver', () => {
141141
expect(testRun.passed).toHaveBeenCalledWith(testItem, 42);
142142
});
143143

144-
it('should use 0-based line in stackTrace position', () => {
144+
it('should use 0-based line in message location', () => {
145145
observer.testFailed(
146146
createTestFailed({
147147
details: [
@@ -154,11 +154,24 @@ describe('TestResultObserver', () => {
154154
const failedCall = (testRun.failed as ReturnType<typeof vi.fn>).mock.calls[0];
155155
const message = failedCall[1];
156156

157-
// message.location line should be 0-based (10 - 1 = 9)
158157
expect(message.location.range.start.line).toBe(9);
158+
});
159159

160-
// stackTrace line should also be 0-based (20 - 1 = 19)
161-
expect(testRun.failed).toHaveBeenCalled();
160+
it('should use 0-based line in stackTrace position', () => {
161+
observer.testFailed(
162+
createTestFailed({
163+
details: [
164+
{ file: '/project/tests/ExampleTest.php', line: 10 },
165+
{ file: '/project/tests/ExampleTest.php', line: 20 },
166+
],
167+
}),
168+
);
169+
170+
const failedCall = (testRun.failed as ReturnType<typeof vi.fn>).mock.calls[0];
171+
const message = failedCall[1];
172+
173+
expect(message.stackTrace).toHaveLength(1);
174+
expect(message.stackTrace[0].position.line).toBe(19);
162175
});
163176

164177
it('should not set location when result.file is undefined', () => {

0 commit comments

Comments
 (0)