@@ -15,7 +15,6 @@ import {
15
15
} from '@ai-sdk/provider-utils/test' ;
16
16
import assert from 'node:assert' ;
17
17
import { z } from 'zod' ;
18
- import { StreamData } from '../../streams/stream-data' ;
19
18
import { createDataStream } from '../data-stream/create-data-stream' ;
20
19
import { MockLanguageModelV2 } from '../test/mock-language-model-v2' ;
21
20
import { createMockServerResponse } from '../test/mock-server-response' ;
@@ -873,34 +872,6 @@ describe('streamText', () => {
873
872
expect ( mockResponse . getDecodedChunks ( ) ) . toMatchSnapshot ( ) ;
874
873
} ) ;
875
874
876
- it ( 'should support merging with existing stream data' , async ( ) => {
877
- const mockResponse = createMockServerResponse ( ) ;
878
-
879
- const result = streamText ( {
880
- model : createTestModel ( ) ,
881
- prompt : 'test-input' ,
882
- experimental_generateMessageId : mockId ( { prefix : 'msg' } ) ,
883
- } ) ;
884
-
885
- const streamData = new StreamData ( ) ;
886
- streamData . append ( 'stream-data-value' ) ;
887
- streamData . close ( ) ;
888
-
889
- result . pipeDataStreamToResponse ( mockResponse , {
890
- data : streamData ,
891
- } ) ;
892
-
893
- await mockResponse . waitForEnd ( ) ;
894
-
895
- expect ( mockResponse . statusCode ) . toBe ( 200 ) ;
896
- expect ( mockResponse . headers ) . toEqual ( {
897
- 'Content-Type' : 'text/plain; charset=utf-8' ,
898
- 'X-Vercel-AI-Data-Stream' : 'v1' ,
899
- } ) ;
900
-
901
- expect ( mockResponse . getDecodedChunks ( ) ) . toMatchSnapshot ( ) ;
902
- } ) ;
903
-
904
875
it ( 'should mask error messages by default' , async ( ) => {
905
876
const mockResponse = createMockServerResponse ( ) ;
906
877
@@ -1099,30 +1070,7 @@ describe('streamText', () => {
1099
1070
1100
1071
const dataStream = result . toDataStream ( ) ;
1101
1072
1102
- expect (
1103
- await convertReadableStreamToArray (
1104
- dataStream . pipeThrough ( new TextDecoderStream ( ) ) ,
1105
- ) ,
1106
- ) . toMatchSnapshot ( ) ;
1107
- } ) ;
1108
-
1109
- it ( 'should support merging with existing stream data' , async ( ) => {
1110
- const result = streamText ( {
1111
- model : createTestModel ( ) ,
1112
- ...defaultSettings ( ) ,
1113
- } ) ;
1114
-
1115
- const streamData = new StreamData ( ) ;
1116
- streamData . append ( 'stream-data-value' ) ;
1117
- streamData . close ( ) ;
1118
-
1119
- const dataStream = result . toDataStream ( { data : streamData } ) ;
1120
-
1121
- expect (
1122
- await convertReadableStreamToArray (
1123
- dataStream . pipeThrough ( new TextDecoderStream ( ) ) ,
1124
- ) ,
1125
- ) . toMatchSnapshot ( ) ;
1073
+ expect ( await convertReadableStreamToArray ( dataStream ) ) . toMatchSnapshot ( ) ;
1126
1074
} ) ;
1127
1075
1128
1076
it ( 'should send tool call and tool result stream parts' , async ( ) => {
@@ -1167,9 +1115,7 @@ describe('streamText', () => {
1167
1115
} ) ;
1168
1116
1169
1117
expect (
1170
- await convertReadableStreamToArray (
1171
- result . toDataStream ( ) . pipeThrough ( new TextDecoderStream ( ) ) ,
1172
- ) ,
1118
+ await convertReadableStreamToArray ( result . toDataStream ( ) ) ,
1173
1119
) . toMatchSnapshot ( ) ;
1174
1120
} ) ;
1175
1121
@@ -1216,9 +1162,7 @@ describe('streamText', () => {
1216
1162
} ) ;
1217
1163
1218
1164
expect (
1219
- await convertReadableStreamToArray (
1220
- result . toDataStream ( ) . pipeThrough ( new TextDecoderStream ( ) ) ,
1221
- ) ,
1165
+ await convertReadableStreamToArray ( result . toDataStream ( ) ) ,
1222
1166
) . toMatchSnapshot ( ) ;
1223
1167
} ) ;
1224
1168
@@ -1234,11 +1178,7 @@ describe('streamText', () => {
1234
1178
1235
1179
const dataStream = result . toDataStream ( ) ;
1236
1180
1237
- expect (
1238
- await convertReadableStreamToArray (
1239
- dataStream . pipeThrough ( new TextDecoderStream ( ) ) ,
1240
- ) ,
1241
- ) . toMatchSnapshot ( ) ;
1181
+ expect ( await convertReadableStreamToArray ( dataStream ) ) . toMatchSnapshot ( ) ;
1242
1182
} ) ;
1243
1183
1244
1184
it ( 'should support custom error messages' , async ( ) => {
@@ -1255,11 +1195,7 @@ describe('streamText', () => {
1255
1195
getErrorMessage : error => `custom error message: ${ error } ` ,
1256
1196
} ) ;
1257
1197
1258
- expect (
1259
- await convertReadableStreamToArray (
1260
- dataStream . pipeThrough ( new TextDecoderStream ( ) ) ,
1261
- ) ,
1262
- ) . toMatchSnapshot ( ) ;
1198
+ expect ( await convertReadableStreamToArray ( dataStream ) ) . toMatchSnapshot ( ) ;
1263
1199
} ) ;
1264
1200
1265
1201
it ( 'should suppress usage information when sendUsage is false' , async ( ) => {
@@ -1279,11 +1215,7 @@ describe('streamText', () => {
1279
1215
1280
1216
const dataStream = result . toDataStream ( { sendUsage : false } ) ;
1281
1217
1282
- expect (
1283
- await convertReadableStreamToArray (
1284
- dataStream . pipeThrough ( new TextDecoderStream ( ) ) ,
1285
- ) ,
1286
- ) . toMatchSnapshot ( ) ;
1218
+ expect ( await convertReadableStreamToArray ( dataStream ) ) . toMatchSnapshot ( ) ;
1287
1219
} ) ;
1288
1220
1289
1221
it ( 'should omit message finish event (d:) when sendFinish is false' , async ( ) => {
@@ -1305,11 +1237,7 @@ describe('streamText', () => {
1305
1237
experimental_sendFinish : false ,
1306
1238
} ) ;
1307
1239
1308
- expect (
1309
- await convertReadableStreamToArray (
1310
- dataStream . pipeThrough ( new TextDecoderStream ( ) ) ,
1311
- ) ,
1312
- ) . toMatchSnapshot ( ) ;
1240
+ expect ( await convertReadableStreamToArray ( dataStream ) ) . toMatchSnapshot ( ) ;
1313
1241
} ) ;
1314
1242
1315
1243
it ( 'should send reasoning content when sendReasoning is true' , async ( ) => {
@@ -1320,11 +1248,7 @@ describe('streamText', () => {
1320
1248
1321
1249
const dataStream = result . toDataStream ( { sendReasoning : true } ) ;
1322
1250
1323
- expect (
1324
- await convertReadableStreamToArray (
1325
- dataStream . pipeThrough ( new TextDecoderStream ( ) ) ,
1326
- ) ,
1327
- ) . toMatchSnapshot ( ) ;
1251
+ expect ( await convertReadableStreamToArray ( dataStream ) ) . toMatchSnapshot ( ) ;
1328
1252
} ) ;
1329
1253
1330
1254
it ( 'should send source content when sendSources is true' , async ( ) => {
@@ -1335,11 +1259,7 @@ describe('streamText', () => {
1335
1259
1336
1260
const dataStream = result . toDataStream ( { sendSources : true } ) ;
1337
1261
1338
- expect (
1339
- await convertReadableStreamToArray (
1340
- dataStream . pipeThrough ( new TextDecoderStream ( ) ) ,
1341
- ) ,
1342
- ) . toMatchSnapshot ( ) ;
1262
+ expect ( await convertReadableStreamToArray ( dataStream ) ) . toMatchSnapshot ( ) ;
1343
1263
} ) ;
1344
1264
1345
1265
it ( 'should send file content' , async ( ) => {
@@ -1350,11 +1270,7 @@ describe('streamText', () => {
1350
1270
1351
1271
const dataStream = result . toDataStream ( ) ;
1352
1272
1353
- expect (
1354
- await convertReadableStreamToArray (
1355
- dataStream . pipeThrough ( new TextDecoderStream ( ) ) ,
1356
- ) ,
1357
- ) . toMatchSnapshot ( ) ;
1273
+ expect ( await convertReadableStreamToArray ( dataStream ) ) . toMatchSnapshot ( ) ;
1358
1274
} ) ;
1359
1275
} ) ;
1360
1276
@@ -1404,26 +1320,6 @@ describe('streamText', () => {
1404
1320
expect ( await convertResponseStreamToArray ( response ) ) . toMatchSnapshot ( ) ;
1405
1321
} ) ;
1406
1322
1407
- it ( 'should support merging with existing stream data' , async ( ) => {
1408
- const result = streamText ( {
1409
- model : createTestModel ( ) ,
1410
- prompt : 'test-input' ,
1411
- experimental_generateMessageId : mockId ( { prefix : 'msg' } ) ,
1412
- } ) ;
1413
-
1414
- const streamData = new StreamData ( ) ;
1415
- streamData . append ( 'stream-data-value' ) ;
1416
- streamData . close ( ) ;
1417
-
1418
- const response = result . toDataStreamResponse ( { data : streamData } ) ;
1419
-
1420
- expect ( response . status ) . toStrictEqual ( 200 ) ;
1421
- expect ( response . headers . get ( 'Content-Type' ) ) . toStrictEqual (
1422
- 'text/plain; charset=utf-8' ,
1423
- ) ;
1424
- expect ( await convertResponseStreamToArray ( response ) ) . toMatchSnapshot ( ) ;
1425
- } ) ;
1426
-
1427
1323
it ( 'should mask error messages by default' , async ( ) => {
1428
1324
const result = streamText ( {
1429
1325
model : createTestModel ( {
@@ -1654,9 +1550,7 @@ describe('streamText', () => {
1654
1550
expect ( {
1655
1551
textStream : await convertAsyncIterableToArray ( result . textStream ) ,
1656
1552
fullStream : await convertAsyncIterableToArray ( result . fullStream ) ,
1657
- dataStream : await convertReadableStreamToArray (
1658
- result . toDataStream ( ) . pipeThrough ( new TextDecoderStream ( ) ) ,
1659
- ) ,
1553
+ dataStream : await convertReadableStreamToArray ( result . toDataStream ( ) ) ,
1660
1554
} ) . toMatchSnapshot ( ) ;
1661
1555
} ) ;
1662
1556
} ) ;
@@ -2905,9 +2799,7 @@ describe('streamText', () => {
2905
2799
const dataStream = result . toDataStream ( ) ;
2906
2800
2907
2801
expect (
2908
- await convertReadableStreamToArray (
2909
- dataStream . pipeThrough ( new TextDecoderStream ( ) ) ,
2910
- ) ,
2802
+ await convertReadableStreamToArray ( dataStream ) ,
2911
2803
) . toMatchSnapshot ( ) ;
2912
2804
} ) ;
2913
2805
0 commit comments