Skip to content

Commit f9f48bf

Browse files
Merge pull request #151 from paul-vd/file-input-test-utils
feat: allow file input in `applyTransform` test util
2 parents 2b94c04 + 6e5fa3d commit f9f48bf

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.changeset/strange-yaks-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codeshift/test-utils': minor
3+
---
4+
5+
Allows to use an FileInfo in the applyTransform test util

packages/test-utils/src/apply-transform.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import jscodeshift from 'jscodeshift';
1+
import jscodeshift, { FileInfo } from 'jscodeshift';
22

33
type Parser = 'babel' | 'babylon' | 'flow' | 'ts' | 'tsx';
44

@@ -8,15 +8,18 @@ interface Options {
88

99
export default async function applyTransform(
1010
transform: any,
11-
input: string,
11+
input: string | FileInfo,
1212
options: Options = {
1313
parser: 'babel',
1414
},
1515
) {
1616
// Handle ES6 modules using default export for the transform
1717
const transformer = transform.default ? transform.default : transform;
18+
19+
const file = typeof input === 'string' ? { source: input } : input;
20+
1821
const output = await transformer(
19-
{ source: input },
22+
file,
2023
{
2124
jscodeshift: jscodeshift.withParser(options.parser as string),
2225
// eslint-disable-next-line @typescript-eslint/no-empty-function

0 commit comments

Comments
 (0)