| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
const fs = require("fs"); |
| 5 |
const { join } = require("path"); |
| 6 |
|
| 7 |
const testsFrom = join( |
| 8 |
__dirname, |
| 9 |
"../../babel-parser/test/fixtures/typescript" |
| 10 |
); |
| 11 |
const testsTo = join(__dirname, "../test/fixtures/typescript"); |
| 12 |
|
| 13 |
fs.rmdirSync(testsTo, { recursive: true }); |
| 14 |
fs.mkdirSync(testsTo); |
| 15 |
|
| 16 |
fs.copyFileSync(join(testsFrom, "options.json"), join(testsTo, "options.json")); |
| 17 |
|
| 18 |
for (const groupName of fs.readdirSync(testsFrom)) { |
| 19 |
if (groupName === "options.json") continue; |
| 20 |
|
| 21 |
const groupFromDir = join(testsFrom, groupName); |
| 22 |
const testNames = fs.readdirSync(groupFromDir); |
| 23 |
const groupHasOptions = testNames.includes("options.json"); |
| 24 |
|
| 25 |
for (const testName of testNames) { |
| 26 |
if (testName === "options.json") { |
| 27 |
continue; |
| 28 |
} |
| 29 |
|
| 30 |
const testFromDir = join(groupFromDir, testName); |
| 31 |
const testToDir = join(testsTo, `${groupName}-${testName}`); |
| 32 |
|
| 33 |
let optionsJsonFrom; |
| 34 |
const ownOptions = join(testFromDir, "options.json"); |
| 35 |
if (fs.existsSync(ownOptions)) { |
| 36 |
const options = JSON.parse(fs.readFileSync(ownOptions)); |
| 37 |
|
| 38 |
if ( |
| 39 |
options.throws || |
| 40 |
!options.plugins || |
| 41 |
options.plugins.indexOf("estree") >= 0 |
| 42 |
) { |
| 43 |
continue; |
| 44 |
} |
| 45 |
optionsJsonFrom = ownOptions; |
| 46 |
} else if (groupHasOptions) { |
| 47 |
|
| 48 |
optionsJsonFrom = join(groupFromDir, "options.json"); |
| 49 |
} |
| 50 |
|
| 51 |
fs.rmdirSync(testToDir, { recursive: true }); |
| 52 |
fs.mkdirSync(testToDir); |
| 53 |
if (optionsJsonFrom) { |
| 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 |
); |
| 76 |
} |
| 77 |
} |
| 78 |
} |