jscodeshift icon indicating copy to clipboard operation
jscodeshift copied to clipboard

defineTest can not resolve async transform

Open shiyangzhaoa opened this issue 2 years ago • 3 comments

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

shiyangzhaoa avatar Jul 27 '22 02:07 shiyangzhaoa

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

ElonVolo avatar Jul 27 '22 03:07 ElonVolo

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

shiyangzhaoa avatar Jul 27 '22 07:07 shiyangzhaoa

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

michaelfaith avatar Apr 17 '24 23:04 michaelfaith