11/*
22Copies tests from the @babel/parser's TypeScript test suite to @babel/generator.
33*/
4- const {
5- copySync,
6- emptyDirSync,
7- existsSync,
8- readdirSync,
9- readFileSync,
10- } = require ( "fs-extra" ) ;
4+ const fs = require ( "fs" ) ;
115const { join } = require ( "path" ) ;
126
137const testsFrom = join (
@@ -16,15 +10,16 @@ const testsFrom = join(
1610) ;
1711const testsTo = join ( __dirname , "../test/fixtures/typescript" ) ;
1812
19- emptyDirSync ( testsTo ) ;
13+ fs . rmdirSync ( testsTo , { recursive : true } ) ;
14+ fs . mkdirSync ( testsTo ) ;
2015
21- copySync ( join ( testsFrom , "options.json" ) , join ( testsTo , "options.json" ) ) ;
16+ fs . copyFileSync ( join ( testsFrom , "options.json" ) , join ( testsTo , "options.json" ) ) ;
2217
23- for ( const groupName of readdirSync ( testsFrom ) ) {
18+ for ( const groupName of fs . readdirSync ( testsFrom ) ) {
2419 if ( groupName === "options.json" ) continue ;
2520
2621 const groupFromDir = join ( testsFrom , groupName ) ;
27- const testNames = readdirSync ( groupFromDir ) ;
22+ const testNames = fs . readdirSync ( groupFromDir ) ;
2823 const groupHasOptions = testNames . includes ( "options.json" ) ;
2924
3025 for ( const testName of testNames ) {
@@ -37,10 +32,14 @@ for (const groupName of readdirSync(testsFrom)) {
3732
3833 let optionsJsonFrom ;
3934 const ownOptions = join ( testFromDir , "options.json" ) ;
40- if ( existsSync ( ownOptions ) ) {
41- const options = JSON . parse ( readFileSync ( ownOptions ) ) ;
35+ if ( fs . existsSync ( ownOptions ) ) {
36+ const options = JSON . parse ( fs . readFileSync ( ownOptions ) ) ;
4237 // Don't include a test that doesn't parse or does not provide babel AST
43- if ( options . throws || options . plugins . indexOf ( "estree" ) >= 0 ) {
38+ if (
39+ options . throws ||
40+ ! options . plugins ||
41+ options . plugins . indexOf ( "estree" ) >= 0
42+ ) {
4443 continue ;
4544 }
4645 optionsJsonFrom = ownOptions ;
@@ -49,10 +48,31 @@ for (const groupName of readdirSync(testsFrom)) {
4948 optionsJsonFrom = join ( groupFromDir , "options.json" ) ;
5049 }
5150
52- emptyDirSync ( testToDir ) ;
51+ fs . rmdirSync ( testToDir , { recursive : true } ) ;
52+ fs . mkdirSync ( testToDir ) ;
5353 if ( optionsJsonFrom ) {
54- copySync ( optionsJsonFrom , join ( testToDir , "options.json" ) ) ;
54+ fs . copyFileSync ( optionsJsonFrom , join ( testToDir , "options.json" ) ) ;
55+ }
56+ if ( fs . existsSync ( join ( testFromDir , "input.js" ) ) ) {
57+ fs . copyFileSync (
58+ join ( testFromDir , "input.js" ) ,
59+ join ( testToDir , "input.js" )
60+ ) ;
61+ } else if ( fs . existsSync ( join ( testFromDir , "input.tsx" ) ) ) {
62+ fs . copyFileSync (
63+ join ( testFromDir , "input.tsx" ) ,
64+ join ( testToDir , "input.tsx" )
65+ ) ;
66+ } else if ( fs . existsSync ( join ( testFromDir , "input.jsx" ) ) ) {
67+ fs . copyFileSync (
68+ join ( testFromDir , "input.jsx" ) ,
69+ join ( testToDir , "input.jsx" )
70+ ) ;
71+ } else if ( fs . existsSync ( join ( testFromDir , "input.ts" ) ) ) {
72+ fs . copyFileSync (
73+ join ( testFromDir , "input.ts" ) ,
74+ join ( testToDir , "input.ts" )
75+ ) ;
5576 }
56- copySync ( join ( testFromDir , "actual.js" ) , join ( testToDir , "actual.js" ) ) ;
5777 }
5878}
0 commit comments