facebook / jscodeshift

A JavaScript codemod toolkit.
https://jscodeshift.com
MIT License
9.22k stars 477 forks source link

defineTest can not resolve async transform #516

Open shiyangzhaoa opened 2 years ago

shiyangzhaoa commented 2 years ago

If the transform is async, defineTest run error, because the defineTest only support sync, output is promise

image
ElonVolo commented 2 years ago

Would you be able to up to github a temporary repository that reproduces the error?

shiyangzhaoa commented 2 years ago

git clone jscodeshift

// sample/reverse-identifiers.js
function transformer(file, api) {
  const j = api.jscodeshift;

  return j(file.source)
    .find(j.Identifier)
    .replaceWith(
      p => j.identifier(p.node.name.split('').reverse().join(''))
    )
    .toSource();
}
// replace with async
function transformer(file, api) {
  const j = api.jscodeshift;

  const source = j(file.source)
    .find(j.Identifier)
    .replaceWith(
      p => j.identifier(p.node.name.split('').reverse().join(''))
    )
    .toSource();

   return Promise.resolve(source);
}

run yarn test

image
michaelfaith commented 4 months ago

Hitting up against this myself. It looks like the PR was closed out without a resolution?