@@ -24,9 +24,7 @@ import {protobuf} from 'google-gax';
24
24
import * as fs from 'fs' ;
25
25
import * as path from 'path' ;
26
26
import { Instance } from '../src/instance' ;
27
- import { Bigtable } from '../src' ;
28
- // eslint-disable-next-line @typescript-eslint/no-var-requires
29
- const streamEvents = require ( 'stream-events' ) ;
27
+ import { Bigtable , AbortableDuplex } from '../src' ;
30
28
31
29
const protosJson = path . resolve ( __dirname , '../protos/protos.json' ) ;
32
30
const root = protobuf . Root . fromJSON (
@@ -71,29 +69,31 @@ describe('Read Row Acceptance tests', () => {
71
69
table . bigtable = { } as Bigtable ;
72
70
// eslint-disable-next-line @typescript-eslint/no-explicit-any
73
71
( table . bigtable . request as any ) = ( ) => {
74
- const stream = streamEvents ( new PassThrough ( { objectMode : true } ) ) ;
75
- stream . abort = ( ) => { } ;
72
+ const stream = new PassThrough ( {
73
+ objectMode : true ,
74
+ } ) ;
76
75
77
- const mocked_stream = function ( size : number ) {
78
- test . chunks_base64 . forEach ( ( value , index , array ) => {
79
- const chunk = value ;
80
- const cellChunk = CellChunk . decode (
81
- Buffer . from ( chunk as string , 'base64' )
82
- ) ;
83
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
- let readRowsResponse : any = { chunks : [ cellChunk ] } ;
85
- readRowsResponse = ReadRowsResponse . create ( readRowsResponse ) ;
86
- readRowsResponse = ReadRowsResponse . toObject ( readRowsResponse , {
87
- defaults : true ,
88
- longs : String ,
89
- oneofs : true ,
90
- } ) ;
91
- stream . emit ( 'data' , readRowsResponse ) ;
92
- } ) ;
93
- stream . emit ( 'end' ) ;
94
- } ;
76
+ ( ( stream as { } ) as AbortableDuplex ) . abort = ( ) => { } ;
95
77
96
- stream . once ( 'reading' , mocked_stream ) ;
78
+ setImmediate ( ( ) => {
79
+ test . chunks_base64
80
+ . map ( chunk => {
81
+ const cellChunk = CellChunk . decode (
82
+ Buffer . from ( chunk as string , 'base64' )
83
+ ) ; //.decode64(chunk);
84
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
+ let readRowsResponse : any = { chunks : [ cellChunk ] } ;
86
+ readRowsResponse = ReadRowsResponse . create ( readRowsResponse ) ;
87
+ readRowsResponse = ReadRowsResponse . toObject ( readRowsResponse , {
88
+ defaults : true ,
89
+ longs : String ,
90
+ oneofs : true ,
91
+ } ) ;
92
+ return readRowsResponse ;
93
+ } )
94
+ . forEach ( readRowsResponse => stream . push ( readRowsResponse ) ) ;
95
+ stream . push ( null ) ;
96
+ } ) ;
97
97
98
98
return stream ;
99
99
} ;
0 commit comments