1+ import { vi } from 'vitest' ;
12import type {
23 RecoverResult ,
34 Recoverable ,
@@ -8,45 +9,47 @@ export class MockSink implements Sink<string, string> {
89 private writtenItems : string [ ] = [ ] ;
910 private closed = false ;
1011
11- open ( ) : void {
12+ open = vi . fn ( ( ) : void => {
1213 this . closed = false ;
13- }
14+ } ) ;
1415
15- write ( input : string ) : void {
16+ write = vi . fn ( ( input : string ) : void => {
1617 this . writtenItems . push ( input ) ;
17- }
18+ } ) ;
1819
19- close ( ) : void {
20+ close = vi . fn ( ( ) : void => {
2021 this . closed = true ;
21- }
22+ } ) ;
2223
23- isClosed ( ) : boolean {
24+ isClosed = vi . fn ( ( ) : boolean => {
2425 return this . closed ;
25- }
26+ } ) ;
2627
27- encode ( input : string ) : string {
28+ encode = vi . fn ( ( input : string ) : string => {
2829 return `${ input } -${ this . constructor . name } -encoded` ;
29- }
30+ } ) ;
3031
31- getWrittenItems ( ) : string [ ] {
32+ getWrittenItems = vi . fn ( ( ) : string [ ] => {
3233 return [ ...this . writtenItems ] ;
33- }
34+ } ) ;
3435}
3536
36- export class MockRecoverableSink < T > extends MockSink implements Recoverable < T > {
37- recover ( ) : RecoverResult < T > {
38- return {
39- records : this . getWrittenItems ( ) as T [ ] ,
40- errors : [ ] ,
41- partialTail : null ,
42- } ;
43- }
44-
45- repack ( ) : void {
46- this . getWrittenItems ( ) . forEach ( item => this . write ( item ) ) ;
47- }
48-
49- finalize ( ) : void {
50- this . close ( ) ;
51- }
37+ export class MockTraceEventFileSink extends MockSink implements Recoverable {
38+ recover = vi . fn (
39+ ( ) : {
40+ records : unknown [ ] ;
41+ errors : { lineNo : number ; line : string ; error : Error } [ ] ;
42+ partialTail : string | null ;
43+ } => {
44+ return {
45+ records : this . getWrittenItems ( ) ,
46+ errors : [ ] ,
47+ partialTail : null ,
48+ } ;
49+ } ,
50+ ) ;
51+
52+ repack = vi . fn ( ( ) : void => { } ) ;
53+
54+ finalize = vi . fn ( ( ) : void => { } ) ;
5255}
0 commit comments