@@ -22,33 +22,83 @@ async function testFixture(fixture) {
2222 describe ( title , ( ) => {
2323 const testCases = parsers . map ( ( parser ) => getTestCase ( fixture , parser ) ) ;
2424
25- for ( const testCase of testCases ) {
26- const testTitle =
27- testCase . expectFail || testCase . formatOptions . parser !== testCase . parser
28- ? `[${ testCase . parser } ] format`
29- : "format" ;
25+ const testCaseForSnapshot = testCases . find (
26+ ( testCase ) =>
27+ ! testCase . expectFail && typeof testCase . expectedOutput !== "string" ,
28+ ) ;
3029
31- test ( testTitle , async ( ) => {
32- await testFormat . run ( testCase ) ;
30+ const hasMultipleParsers = testCases . length > 1 ;
3331
34- if ( ! FULL_TEST ) {
35- return ;
32+ for ( const functionality of [
33+ {
34+ name ( testCase ) {
35+ let name = "format" ;
36+ // Avoid parser display in snapshot
37+ if ( testCaseForSnapshot !== testCase && hasMultipleParsers ) {
38+ name += `[${ testCase . parser } ]` ;
39+ }
40+ return name ;
41+ } ,
42+ test : {
43+ run : ( testCase ) => testFormat . run ( testCase , testCaseForSnapshot ) ,
44+ } ,
45+ } ,
46+ {
47+ name : "ast compare" ,
48+ test : { run : testAstCompare . run } ,
49+ skip : ( ) => ! FULL_TEST ,
50+ } ,
51+ // The following cases only need run on main parser
52+ {
53+ name : "second format" ,
54+ test : { run : testSecondFormat . run } ,
55+ skip : ( testCase ) => ! FULL_TEST || testCase !== testCaseForSnapshot ,
56+ } ,
57+ {
58+ name : "end of line (CRLF)" ,
59+ test : { run : ( testCase ) => testEndOfLine . run ( testCase , "\r\n" ) } ,
60+ skip : ( testCase ) => ! FULL_TEST || testCase !== testCaseForSnapshot ,
61+ } ,
62+ {
63+ name : "end of line (CR)" ,
64+ test : { run : ( testCase ) => testEndOfLine . run ( testCase , "\r" ) } ,
65+ skip : ( testCase ) => ! FULL_TEST || testCase !== testCaseForSnapshot ,
66+ } ,
67+ {
68+ name : "BOM" ,
69+ test : { run : testBom . run } ,
70+ skip : ( testCase ) => ! FULL_TEST || testCase !== testCaseForSnapshot ,
71+ } ,
72+ {
73+ name : "ANTLR format" ,
74+ test : { run : testAntlrFormat . run } ,
75+ skip : ( testCase ) => ! FULL_TEST || testCase !== testCaseForSnapshot ,
76+ } ,
77+ {
78+ name : "bytecode comparison" ,
79+ test : { run : testBytecodeCompare . run } ,
80+ skip : ( testCase ) => ! FULL_TEST || testCase !== testCaseForSnapshot ,
81+ } ,
82+ {
83+ name : "variant coverage" ,
84+ test : { run : testVariantCoverage . run } ,
85+ skip : ( testCase ) => ! FULL_TEST || testCase !== testCaseForSnapshot ,
86+ } ,
87+ ] ) {
88+ for ( const testCase of testCases ) {
89+ if ( functionality . skip ?. ( testCase ) ) {
90+ continue ;
3691 }
37- await Promise . all (
38- [
39- testAntlrFormat . run ,
40- testVariantCoverage . run ,
41- testSecondFormat . run ,
42- testAstCompare . run ,
43- testBom . run ,
44- testBytecodeCompare . run ,
45- ]
46- . map ( ( test ) => test ( testCase ) )
47- . join (
48- [ "\r\n" , "\r" ] . map ( ( eol ) => testEndOfLine . run ( testCase , eol ) ) ,
49- ) ,
50- ) ;
51- } ) ;
92+ let { name } = functionality ;
93+ if ( typeof name === "function" ) {
94+ name = name ( testCase ) ;
95+ } else if ( hasMultipleParsers ) {
96+ name += ` [${ testCase . parser } ]` ;
97+ }
98+ test ( name , async ( ) => {
99+ await functionality . test . run ( testCase ) ;
100+ } ) ;
101+ }
52102 }
53103 } ) ;
54104}
0 commit comments