-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
defineInlineTest doesn't support async transforms #454
Labels
Comments
I have the same problem :( |
Hey all, in case anyone finds it useful here's an alternate testing util that supports async transforms. Feel free to either copy-paste or pull the library as a dep. The API is different to applyTransformExample: import * as transformer from '../transform';
import { applyTransform } from '@codeshift/test-utils';
it('should wrap avatar in a tooltip if name is defined', async () => {
const result = await applyTransform(transformer, `const foo = 'foo';`);
expect(result).toMatchInlineSnapshot(`"const oof = 'oof';"`);
}); here's the implementation in case you would rather copy-paste: import jscodeshift from 'jscodeshift';
type Parser = 'babel' | 'babylon' | 'flow' | 'ts' | 'tsx';
interface Options {
parser?: Parser;
}
export default async function applyTransform(
transform: any,
input: string,
options: Options = {
parser: 'babel',
},
) {
// Handle ES6 modules using default export for the transform
const transformer = transform.default ? transform.default : transform;
const output = await transformer(
{ source: input },
{
jscodeshift: jscodeshift.withParser(options.parser as string),
stats: () => {},
},
options || {},
);
return (output || '').trim();
} |
trivikr
added a commit
to aws/aws-sdk-js-codemod
that referenced
this issue
Dec 29, 2022
Refs: facebook/jscodeshift#454 TypeError: Cannot read properties of undefined (reading 'endsWith') 1 | export const isTypeScriptFile = (filePath: string): boolean => > 2 | filePath.endsWith(".ts") || filePath.endsWith(".tsx");
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since #237, transformers can be async.
However testing such transformers using
defineInlineTest
doesn't appear to be supported, and from the code also looks like it won't be suppored by any type of unit test.Error:
TypeError: (output || "").trim is not a function
The text was updated successfully, but these errors were encountered: