@@ -7,7 +7,6 @@ import Replicate, {
77 parseProgressFromLogs ,
88} from "replicate" ;
99import nock from "nock" ;
10- import fetch from "cross-fetch" ;
1110import { createReadableStream } from "./lib/stream" ;
1211import { PassThrough } from "node:stream" ;
1312
@@ -23,7 +22,6 @@ describe("Replicate client", () => {
2322
2423 beforeEach ( ( ) => {
2524 client = new Replicate ( { auth : "test-token" } ) ;
26- client . fetch = fetch ;
2725
2826 unmatched = [ ] ;
2927 nock . emitter . on ( "no match" , handleNoMatch ) ;
@@ -1189,23 +1187,21 @@ describe("Replicate client", () => {
11891187 // Continue with tests for other methods
11901188
11911189 describe ( "createReadableStream" , ( ) => {
1192- async function createStream (
1193- body : string | NodeJS . ReadableStream ,
1194- status = 200
1195- ) {
1190+ function createStream ( body : string | NodeJS . ReadableStream , status = 200 ) {
11961191 const streamEndpoint = "https://stream.replicate.com" ;
11971192 nock ( streamEndpoint )
11981193 . get ( "/fake_stream" )
11991194 . matchHeader ( "Accept" , "text/event-stream" )
12001195 . reply ( status , body ) ;
12011196
1202- return await createReadableStream ( {
1197+ return createReadableStream ( {
12031198 url : `${ streamEndpoint } /fake_stream` ,
1199+ fetch : fetch ,
12041200 } ) ;
12051201 }
12061202
12071203 test ( "consumes a server sent event stream" , async ( ) => {
1208- const stream = await createStream (
1204+ const stream = createStream (
12091205 `
12101206 event: output
12111207 id: EVENT_1
@@ -1232,7 +1228,7 @@ describe("Replicate client", () => {
12321228 } ) ;
12331229
12341230 test ( "consumes multiple events" , async ( ) => {
1235- const stream = await createStream (
1231+ const stream = createStream (
12361232 `
12371233 event: output
12381234 id: EVENT_1
@@ -1268,7 +1264,7 @@ describe("Replicate client", () => {
12681264 } ) ;
12691265
12701266 test ( "ignores unexpected characters" , async ( ) => {
1271- const stream = await createStream (
1267+ const stream = createStream (
12721268 `
12731269 : hi
12741270
@@ -1298,7 +1294,7 @@ describe("Replicate client", () => {
12981294 } ) ;
12991295
13001296 test ( "supports multiple lines of output in a single event" , async ( ) => {
1301- const stream = await createStream (
1297+ const stream = createStream (
13021298 `
13031299 : hi
13041300
@@ -1335,7 +1331,7 @@ describe("Replicate client", () => {
13351331
13361332 test ( "supports the server writing data lines in multiple chunks" , async ( ) => {
13371333 const body = new PassThrough ( ) ;
1338- const stream = await createStream ( body ) ;
1334+ const stream = createStream ( body ) ;
13391335
13401336 // Create a stream of data chunks split on the pipe character for readability.
13411337 const data = `
@@ -1391,7 +1387,7 @@ describe("Replicate client", () => {
13911387
13921388 test ( "supports the server writing data in a complete mess" , async ( ) => {
13931389 const body = new PassThrough ( ) ;
1394- const stream = await createStream ( body ) ;
1390+ const stream = createStream ( body ) ;
13951391
13961392 // Create a stream of data chunks split on the pipe character for readability.
13971393 const data = `
@@ -1448,7 +1444,7 @@ describe("Replicate client", () => {
14481444 } ) ;
14491445
14501446 test ( "supports ending without a done" , async ( ) => {
1451- const stream = await createStream (
1447+ const stream = createStream (
14521448 `
14531449 event: output
14541450 id: EVENT_1
@@ -1466,7 +1462,7 @@ describe("Replicate client", () => {
14661462 } ) ;
14671463
14681464 test ( "an error event in the stream raises an exception" , async ( ) => {
1469- const stream = await createStream (
1465+ const stream = createStream (
14701466 `
14711467 event: output
14721468 id: EVENT_1
@@ -1484,12 +1480,14 @@ describe("Replicate client", () => {
14841480 done : false ,
14851481 value : { event : "output" , id : "EVENT_1" , data : "hello world" } ,
14861482 } ) ;
1487- await expect ( iterator . next ( ) ) . rejects . toThrowError ( "Unexpected Error" ) ;
1483+ await expect ( iterator . next ( ) ) . rejects . toThrowError (
1484+ "An unexpected error occurred"
1485+ ) ;
14881486 expect ( await iterator . next ( ) ) . toEqual ( { done : true } ) ;
14891487 } ) ;
14901488
14911489 test ( "an error when fetching the stream raises an exception" , async ( ) => {
1492- const stream = await createStream ( "{}" , 500 ) ;
1490+ const stream = createStream ( "{}" , 500 ) ;
14931491 const iterator = stream [ Symbol . asyncIterator ] ( ) ;
14941492 await expect ( iterator . next ( ) ) . rejects . toThrowError (
14951493 "Request to https://stream.replicate.com/fake_stream failed with status 500"
0 commit comments