Skip to content

Commit 8a8517c

Browse files
committed
applyTransfrom now returns a promise
1 parent 8dc4e6f commit 8a8517c

File tree

7 files changed

+26
-21
lines changed

7 files changed

+26
-21
lines changed

.changeset/large-tools-fly.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+
applyTransfrom now returns a promise to support async transforms

community/@atlaskit__avatar/18.0.0/__tests__/transform.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import * as transformer from '../transform';
66
const defineInlineTest = require('jscodeshift/dist/testUtils').defineInlineTest;
77

88
describe('Update Avatar props', () => {
9-
it('should wrap avatar in a tooltip if name is defined', () => {
10-
const result = applyTransform(
9+
it('should wrap avatar in a tooltip if name is defined', async () => {
10+
const result = await applyTransform(
1111
transformer,
1212
`
1313
import Avatar from '@atlaskit/avatar';

community/@emotion__monorepo/11.0.0/transform.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { applyTransform } from '@codeshift/test-utils';
22
import * as transformer from './transform';
33

44
describe('@emotion@11.0.0 transform', () => {
5-
it('should transform imports correctly', () => {
6-
const result = applyTransform(
5+
it('should transform imports correctly', async () => {
6+
const result = await applyTransform(
77
transformer,
88
`
99
import * as core from '@emotion/core';

community/memoize-one/5.0.0/transform.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ function format(source: string): string {
1717
}
1818

1919
describe('memoize-one@5.0.0 transform', () => {
20-
it('should not touch usages that do not use a custom equality function', () => {
21-
const result = applyTransform(
20+
it('should not touch usages that do not use a custom equality function', async () => {
21+
const result = await applyTransform(
2222
transformer,
2323
format(`
2424
import memoize from 'memoize-one';
@@ -45,8 +45,8 @@ describe('memoize-one@5.0.0 transform', () => {
4545
);
4646
});
4747

48-
it('should wrap inline equality arrow functions', () => {
49-
const result = applyTransform(
48+
it('should wrap inline equality arrow functions', async () => {
49+
const result = await applyTransform(
5050
transformer,
5151
format(`
5252
import memoize from 'memoize-one';
@@ -85,8 +85,8 @@ describe('memoize-one@5.0.0 transform', () => {
8585
);
8686
});
8787

88-
it('should wrap inline equality function declarations', () => {
89-
const result = applyTransform(
88+
it('should wrap inline equality function declarations', async () => {
89+
const result = await applyTransform(
9090
transformer,
9191
format(`
9292
import memoize from 'memoize-one';
@@ -125,8 +125,8 @@ describe('memoize-one@5.0.0 transform', () => {
125125
);
126126
});
127127

128-
it('should wrap function identifiers', () => {
129-
const result = applyTransform(
128+
it('should wrap function identifiers', async () => {
129+
const result = await applyTransform(
130130
transformer,
131131
format(`
132132
import memoize from 'memoize-one';
@@ -162,8 +162,8 @@ describe('memoize-one@5.0.0 transform', () => {
162162
);
163163
});
164164

165-
it('should add a comment when an unsupported equality fn is encountered', () => {
166-
const result = applyTransform(
165+
it('should add a comment when an unsupported equality fn is encountered', async () => {
166+
const result = await applyTransform(
167167
transformer,
168168
format(`
169169
import memoize from 'memoize-one';

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface Options {
66
parser?: Parser;
77
}
88

9-
export default function applyTransform(
9+
export default async function applyTransform(
1010
transform: any,
1111
input: string,
1212
options: Options = {
@@ -15,7 +15,7 @@ export default function applyTransform(
1515
) {
1616
// Handle ES6 modules using default export for the transform
1717
const transformer = transform.default ? transform.default : transform;
18-
const output = transformer(
18+
const output = await transformer(
1919
{ source: input },
2020
{
2121
jscodeshift: jscodeshift.withParser(options.parser as string),

website/docs/api/codeshift-test-utils.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ We provide this method as opposed to [jscodeshift's test utils](https://github.c
2525

2626
**Returns**
2727

28-
`string`: Resulting file after transform has been applied
28+
`Promise<string>`: Resulting file after transform has been applied
2929

3030
**Example**
3131

3232
```jsx
3333
import * as transformer from '../transform';
3434
import { applyTransform } from '@codeshift/test-utils';
3535

36-
it('should wrap avatar in a tooltip if name is defined', () => {
37-
const result = applyTransform(
36+
it('should wrap avatar in a tooltip if name is defined', async () => {
37+
const result = await applyTransform(
3838
transformer,
3939
`
4040
import Avatar from 'avatar';

website/docs/testing.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ In this case, you would be able to write a simple test using `jest` & `@codeshif
3636
import * as transformer from '../transform';
3737
import { applyTransform } from '@codeshift/test-utils';
3838

39-
it('should remove all deleted props', () => {
40-
const result = applyTransform(
39+
it('should remove all deleted props', async () => {
40+
const result = await applyTransform(
4141
transformer,
4242
`
4343
import Foo from '@mylib/foo';

0 commit comments

Comments
 (0)