question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do you want to request a feature or report a bug?

Feature.

What is the current behavior?

Transforms are synchronous, basically process returns a string of the transformed source.

What is the expected behavior?

It would be useful to also support Promises, for asynchronous transformation.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
jpvincentcommented, Mar 22, 2018

Hi I understand the rationales for the “No”, but let me add that here we would really need the transform to support asynchronous methods, like Webpack does with its loader. We made a custom loader (for translations files in resx format) that works for Webpack and that we could reuse almost as-is if the jest transform option was asynchronous. Currently the workaround has been to pre-compile all our translation files before running Jest, but it’s not optimized at all.

Thanks anyway for the transform option to exist at all 😃

6reactions
ksjogocommented, Oct 11, 2018

@jpvincent I ran into the same thing with a resx transformer. This seems to work:

const xml2js = require('xml2js');
const util = require('./util');
const deasync = require('deasync');

/** @type { jest.Transformer } */
const transformer = {
  process(src) {
    let result = null;
    xml2js.parseString(src, (err, parsedXml) => {
      if (err) throw err;
      result = util.transformResx(parsedXml);
    });
    while (result === undefined) {
      deasync.runLoopOnce();
    }
    return result;
  }
};

module.exports = transformer;
Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/plugin-transform-async-to-generator
Since Babel cannot automatically handle this runtime error, you should manually transform it to a promise. async function foo() { - await 42;...
Read more >
babel-plugin-transform-async-to-promises - npm
Transform async /await to promise chains. Latest version: 0.8.18, last published: a year ago.
Read more >
rpetrich/babel-plugin-transform-async-to-promises - GitHub
Babel plugin to transform async functions containing await expressions to the equivalent chain of Promise calls with use of minimal helper functions.
Read more >
babel-plugin-transform-async-to-promises - npm package | Snyk
Babel plugin to transform async functions containing await expressions to the equivalent chain of Promise calls with use of minimal helper functions. Input:....
Read more >
babel-plugin-transform-async-await | Yarn - Package Manager
Babel plugin to transform async functions containing await expressions to the equivalent chain of Promise calls with use of minimal helper functions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found