( fixtureBaseName: string, ext: 'ts' | 'tsx', )
| 15 | } |
| 16 | |
| 17 | function runTransform( |
| 18 | fixtureBaseName: string, |
| 19 | ext: 'ts' | 'tsx', |
| 20 | ): { output: string; reports: Array<string> } { |
| 21 | const source = read(`${fixtureBaseName}.input.${ext}`) |
| 22 | const reports: Array<string> = [] |
| 23 | const j = jscodeshift.withParser('tsx') |
| 24 | const result = transform( |
| 25 | { path: `${fixtureBaseName}.input.${ext}`, source }, |
| 26 | { |
| 27 | jscodeshift: j, |
| 28 | j, |
| 29 | stats: () => {}, |
| 30 | report: (msg: string) => { |
| 31 | reports.push(msg) |
| 32 | }, |
| 33 | }, |
| 34 | {}, |
| 35 | ) |
| 36 | if (typeof result !== 'string') { |
| 37 | throw new Error( |
| 38 | `transform returned ${typeof result} for ${fixtureBaseName}.input.${ext}; expected a string`, |
| 39 | ) |
| 40 | } |
| 41 | return { output: result, reports } |
| 42 | } |
| 43 | |
| 44 | // Run both sides through Prettier before comparing. recast (jscodeshift's |
| 45 | // printer) emits semicolons and drops trailing commas, while the fixtures are |
no test coverage detected