11import { matcherTypes } from '../matcherTypes' ;
22import { matcherFactory } from '..' ;
3- import fs from 'fs' ;
4- import rl from 'readline' ;
53import { IMatcher , IMatcherDto } from '../../types' ;
64import { loggerMock } from '../../../logger/__tests__/sdkLogger.mock' ;
5+ import { readCSV } from '../../../__tests__/testUtils/csv' ;
76
8- test ( 'MATCHER REGEX (STRING) / should match the attribute value only with the string starts with hello' , function ( ) {
7+ test ( 'MATCHER REGEX (STRING) / should match the attribute value only with the string starts with hello' , ( ) => {
98 // @ts -ignore
109 const matcher = matcherFactory ( loggerMock , {
1110 type : matcherTypes . MATCHES_STRING ,
@@ -16,7 +15,7 @@ test('MATCHER REGEX (STRING) / should match the attribute value only with the st
1615 expect ( matcher ( 'hello dude!' ) ) . toBe ( true ) ;
1716} ) ;
1817
19- test ( 'MATCHER REGEX (STRING) / incorrectly matches unicode characters' , function ( ) {
18+ test ( 'MATCHER REGEX (STRING) / incorrectly matches unicode characters' , ( ) => {
2019 // @ts -ignore
2120 const matcher = matcherFactory ( loggerMock , {
2221 type : matcherTypes . MATCHES_STRING ,
@@ -31,31 +30,20 @@ test('MATCHER REGEX (STRING) / incorrectly matches unicode characters', function
3130 'regex.txt'
3231] . forEach ( filename => {
3332
34- test ( 'MATCHER REGEX (STRING) / validate regex behavior using sample data' , ( done ) => {
35- const parser = rl . createInterface ( {
36- terminal : false ,
37- input : fs . createReadStream ( require . resolve ( `./mocks/${ filename } ` ) )
38- } ) ;
33+ test ( 'MATCHER REGEX (STRING) / validate regex behavior using sample data' , async ( ) => {
34+ const lines = await readCSV ( require . resolve ( `./mocks/${ filename } ` ) , '#' ) ;
3935
40- parser
41- . on ( 'line' , line => {
42- const parts = line . toString ( ) . split ( '#' ) ;
36+ for ( const [ regex , input , test ] of lines ) {
37+ const isTestTrue = test === 'true' ;
4338
44- if ( parts . length === 3 ) {
45- let [ regex , input , test ] = parts ;
39+ // @ts -ignore
40+ const matcher = matcherFactory ( loggerMock , {
41+ type : matcherTypes . MATCHES_STRING ,
42+ value : regex
43+ } as IMatcherDto ) as IMatcher ;
4644
47- const isTestTrue = test === 'true' ;
48-
49- // @ts -ignore
50- const matcher = matcherFactory ( loggerMock , {
51- type : matcherTypes . MATCHES_STRING ,
52- value : regex
53- } as IMatcherDto ) as IMatcher ;
54-
55- expect ( matcher ( input ) === isTestTrue ) . toBe ( true ) ;
56- }
57- } )
58- . on ( 'close' , done ) ;
45+ expect ( matcher ( input ) === isTestTrue ) . toBe ( true ) ;
46+ }
5947 } ) ;
6048
6149} ) ;
0 commit comments