Skip to content

Commit a4e1e5a

Browse files
committed
fix: use optional chaining for tsgo type checker compatibility
1 parent 0e15c95 commit a4e1e5a

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

packages/server/test/server/streamableHttp.test.ts

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,9 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
811811

812812
expect(response.status).toBe(400);
813813
expect(errors.length).toBeGreaterThan(0);
814-
expect(errors[0]!.message).toContain('Parse error');
814+
const error = errors[0];
815+
expect(error).toBeDefined();
816+
expect(error?.message).toContain('Parse error');
815817
});
816818

817819
it('should call onerror for invalid JSON-RPC message', async () => {
@@ -828,7 +830,9 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
828830

829831
expect(response.status).toBe(400);
830832
expect(errors.length).toBeGreaterThan(0);
831-
expect(errors[0]!.message).toContain('Parse error');
833+
const error = errors[0];
834+
expect(error).toBeDefined();
835+
expect(error?.message).toContain('Parse error');
832836
});
833837

834838
it('should call onerror for missing Accept header on POST', async () => {
@@ -838,7 +842,9 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
838842

839843
expect(response.status).toBe(406);
840844
expect(errors.length).toBeGreaterThan(0);
841-
expect(errors[0]!.message).toContain('Not Acceptable');
845+
const error = errors[0];
846+
expect(error).toBeDefined();
847+
expect(error?.message).toContain('Not Acceptable');
842848
});
843849

844850
it('should call onerror for unsupported Content-Type', async () => {
@@ -855,7 +861,9 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
855861

856862
expect(response.status).toBe(415);
857863
expect(errors.length).toBeGreaterThan(0);
858-
expect(errors[0]!.message).toContain('Unsupported Media Type');
864+
const error = errors[0];
865+
expect(error).toBeDefined();
866+
expect(error?.message).toContain('Unsupported Media Type');
859867
});
860868

861869
it('should call onerror for server not initialized', async () => {
@@ -865,7 +873,9 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
865873

866874
expect(response.status).toBe(400);
867875
expect(errors.length).toBeGreaterThan(0);
868-
expect(errors[0]!.message).toContain('Server not initialized');
876+
const error = errors[0];
877+
expect(error).toBeDefined();
878+
expect(error?.message).toContain('Server not initialized');
869879
});
870880

871881
it('should call onerror for invalid session ID', async () => {
@@ -877,7 +887,9 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
877887

878888
expect(response.status).toBe(404);
879889
expect(errors.length).toBeGreaterThan(0);
880-
expect(errors[0]!.message).toContain('Session not found');
890+
const error = errors[0];
891+
expect(error).toBeDefined();
892+
expect(error?.message).toContain('Session not found');
881893
});
882894

883895
it('should call onerror for re-initialization attempt', async () => {
@@ -889,7 +901,9 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
889901

890902
expect(response.status).toBe(400);
891903
expect(errors.length).toBeGreaterThan(0);
892-
expect(errors[0]!.message).toContain('Server already initialized');
904+
const error = errors[0];
905+
expect(error).toBeDefined();
906+
expect(error?.message).toContain('Server already initialized');
893907
});
894908

895909
it('should call onerror for GET without Accept header', async () => {
@@ -901,7 +915,9 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
901915

902916
expect(response.status).toBe(406);
903917
expect(errors.length).toBeGreaterThan(0);
904-
expect(errors[0]!.message).toContain('Not Acceptable');
918+
const error = errors[0];
919+
expect(error).toBeDefined();
920+
expect(error?.message).toContain('Not Acceptable');
905921
});
906922

907923
it('should call onerror for concurrent SSE streams', async () => {
@@ -915,7 +931,9 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
915931

916932
expect(response2.status).toBe(409);
917933
expect(errors.length).toBeGreaterThan(0);
918-
expect(errors[0]!.message).toContain('Conflict');
934+
const error = errors[0];
935+
expect(error).toBeDefined();
936+
expect(error?.message).toContain('Conflict');
919937
});
920938

921939
it('should call onerror for unsupported protocol version', async () => {
@@ -936,7 +954,9 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
936954

937955
expect(response.status).toBe(400);
938956
expect(errors.length).toBeGreaterThan(0);
939-
expect(errors[0]!.message).toContain('Unsupported protocol version');
957+
const error = errors[0];
958+
expect(error).toBeDefined();
959+
expect(error?.message).toContain('Unsupported protocol version');
940960
});
941961
});
942962
});

0 commit comments

Comments
 (0)