11import * as fs from 'fs' ;
22import * as path from 'path' ;
33import * as assert from 'assert' ;
4+ import { getDistinctTestFileNames , readFileContents } from './systemTestFileReader' ;
5+ import SystemTestsConfig from './systemTestsConfig' ;
46import { CliPrettify } from '../../cli/cliPrettify' ;
57
68fs . readdir ( path . resolve ( __dirname , "resources/" ) , function ( err , files ) {
79 suite ( "CLI Prettyfier system tests - prettyfied input files match prepared expected files" , ( ) => {
8- const distinctTests : string [ ] = getTestFileNames ( files ) ;
10+ const distinctTests : string [ ] = getAllowedAndDistinctTestFileNames ( files ) ;
911 for ( let fileNameRoot of distinctTests ) {
1012 test ( `[${ fileNameRoot } ]` , ( ) => {
11- const input = fs . readFileSync ( pathFor ( `${ fileNameRoot } -input.md` ) , "utf8" ) ;
12- const expected = fs . readFileSync ( pathFor ( `${ fileNameRoot } -expected.md` ) , "utf8" ) ;
13+ const input = readFileContents ( `${ fileNameRoot } -input.md` ) ;
14+ const expected = readFileContents ( `${ fileNameRoot } -expected.md` ) ;
15+ const cliOptions = SystemTestsConfig . getCliOptionsFor ( fileNameRoot ) ;
1316
14- const actual = CliPrettify . prettify ( input ) ;
17+ const actual = CliPrettify . prettify ( input , cliOptions ) ;
1518
1619 assert . strictEqual ( actual , expected ) ;
1720 } ) ;
@@ -21,42 +24,30 @@ fs.readdir(path.resolve(__dirname, "resources/"), function(err, files) {
2124
2225fs . readdir ( path . resolve ( __dirname , "resources/" ) , function ( err , files ) {
2326 suite ( "CLI Prettyfier system tests - check() for non pretty files throws error" , ( ) => {
24- const distinctTests : string [ ] = getTestFileNames ( files ) ;
27+ const distinctTests : string [ ] = getAllowedAndDistinctTestFileNames ( files ) ;
2528 for ( let fileNameRoot of distinctTests ) {
2629 test ( `[${ fileNameRoot } ]` , ( ) => {
27- const input = fs . readFileSync ( pathFor ( `${ fileNameRoot } -input.md` ) , "utf8" ) ;
30+ const input = readFileContents ( `${ fileNameRoot } -input.md` ) ;
2831 assert . throws ( ( ) => CliPrettify . check ( input ) ) ;
2932 } ) ;
3033 }
3134 } ) ;
3235} ) ;
3336
34-
3537fs . readdir ( path . resolve ( __dirname , "resources/" ) , function ( err , files ) {
3638 suite ( "CLI Prettyfier system tests - check() for pretty files does not throw" , ( ) => {
37- const distinctTests : string [ ] = getTestFileNames ( files ) ;
39+ const distinctTests : string [ ] = getAllowedAndDistinctTestFileNames ( files ) ;
3840 for ( let fileNameRoot of distinctTests ) {
3941 test ( `[${ fileNameRoot } ]` , ( ) => {
40- const expected = fs . readFileSync ( pathFor ( `${ fileNameRoot } -expected.md` ) , "utf8" ) ;
41- assert . doesNotThrow ( ( ) => CliPrettify . check ( expected ) ) ;
42+ const expected = readFileContents ( `${ fileNameRoot } -expected.md` ) ;
43+ const cliOptions = SystemTestsConfig . getCliOptionsFor ( fileNameRoot ) ;
44+
45+ assert . doesNotThrow ( ( ) => CliPrettify . check ( expected , cliOptions ) ) ;
4246 } ) ;
4347 }
4448 } ) ;
4549} ) ;
4650
47- function getTestFileNames ( files : string [ ] ) : string [ ] {
48- const blockListFileName = "_cli-blocklist.config" ;
49- const blockedFiles : string [ ] = files . find ( f => f === blockListFileName )
50- ? fs . readFileSync ( pathFor ( blockListFileName ) , "utf8" ) . split ( / \r \n | \r | \n / )
51- : [ ] ;
52-
53- const distinctTests : string [ ] = files
54- . filter ( f => path . extname ( f ) . toLowerCase ( ) === ".md" )
55- . filter ( f => blockedFiles . indexOf ( f ) < 0 )
56- . map ( f => f . split ( "-" ) [ 0 ] ) . filter ( ( item , i , s ) => s . lastIndexOf ( item ) == i ) ;
57- return distinctTests ;
51+ function getAllowedAndDistinctTestFileNames ( files : string [ ] ) : string [ ] {
52+ return getDistinctTestFileNames ( files , SystemTestsConfig . isAllowedForCliTests ) ;
5853}
59-
60- function pathFor ( fileName : string ) : string {
61- return path . resolve ( __dirname , `resources/${ fileName } ` ) ;
62- }
0 commit comments