diff --git a/.changeset/strange-yaks-rescue.md b/.changeset/strange-yaks-rescue.md new file mode 100644 index 000000000..c40ba5776 --- /dev/null +++ b/.changeset/strange-yaks-rescue.md @@ -0,0 +1,5 @@ +--- +'@codeshift/test-utils': minor +--- + +Allows to use an FileInfo in the applyTransform test util diff --git a/packages/test-utils/src/apply-transform.ts b/packages/test-utils/src/apply-transform.ts index 91c351bd9..2a300c152 100644 --- a/packages/test-utils/src/apply-transform.ts +++ b/packages/test-utils/src/apply-transform.ts @@ -1,4 +1,4 @@ -import jscodeshift from 'jscodeshift'; +import jscodeshift, { FileInfo } from 'jscodeshift'; type Parser = 'babel' | 'babylon' | 'flow' | 'ts' | 'tsx'; @@ -8,15 +8,18 @@ interface Options { export default async function applyTransform( transform: any, - input: string, + input: string | FileInfo, options: Options = { parser: 'babel', }, ) { // Handle ES6 modules using default export for the transform const transformer = transform.default ? transform.default : transform; + + const file = typeof input === 'string' ? { source: input } : input; + const output = await transformer( - { source: input }, + file, { jscodeshift: jscodeshift.withParser(options.parser as string), // eslint-disable-next-line @typescript-eslint/no-empty-function