teambit / envs

Component development environments for the Bit community
https://bit.dev/bit/envs
Other
63 stars 9 forks source link

Can't use async/await with Babel compiler and Jest tester #88

Open btaskew opened 4 years ago

btaskew commented 4 years ago

Have some code in a plain JavaScript component that uses async/await. Test works fine when running Jest locally, but when running "bit test" on the code as a component am getting a "ReferenceError: regeneratorRuntime is not defined" error message.

Code:

function timeout(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

async function work() {
    await timeout(5000);
    return true;
}

export default work;

Test:

import work from './index';

describe('foo', () => {

    it('should work', async () => {
        const result = await work();
        expect(result).toEqual(true);
    });

});

Adding import 'regenerator-runtime/runtime' to the code makes the test work, but this have to be a requirement just to make the bit tests work

Expected Behaviour

Code using async/await should compile correctly and the appropriate plugins/imports included in the compiler/tester to recognise the regeneratorRuntime function

Specifications

Compiler: bit.envs/compilers/babel@7.0.4 Tester: bit.envs/testers/jest@22.4.3 Bit version: 14.7.2

GiladShoham commented 4 years ago

moved to the correct repo