Skip to content
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

Async iterables don't work #471

Closed
slikts opened this issue Mar 20, 2018 · 8 comments
Closed

Async iterables don't work #471

slikts opened this issue Mar 20, 2018 · 8 comments

Comments

@slikts
Copy link

slikts commented Mar 20, 2018

  • Issue

I have the following async generator in my code:

const a = {
  async *b() {
    yield 1;
  }
};

This causes an "Unexpected token" when trying to run from a .ts file, but not a .js file, since I'm running node with the --harmony-async-iteration flag so async iteration works in .js files.

  • Expected behavior

Async iteration should also work with ts-jest since TS itself supports it.

  • Output from your debug log

https://gist.github.com/slikts/edf805370c43f97988c872dfa7ca5d48

Versions:
"jest": "^22.4.2",
"ts-jest": "^22.4.2",
"ts-node": "^5.0.1",
"typescript": "^2.8.0-rc"

@kulshekhar
Copy link
Owner

@slikts Can you please create a minimal repo that reproduces this issue?

@slikts
Copy link
Author

slikts commented Mar 20, 2018

Repo: https://github.com/slikts/ts-jest-issue

npm i
npm run test
...
/mnt/e/work/ts-jest-issue/Foo.spec.ts: Unexpected token (3:10)

Edit: it might be relevant that when installing the deps, I get this notice:

npm WARN ts-jest@22.4.2 requires a peer of typescript@2.x but none is installed. You must install peer dependencies yourself.

However, typescript is clearly in the dependencies and gets installed.

@slikts
Copy link
Author

slikts commented Mar 20, 2018

Using ts-node with no flags produces the same Unexpected token error, while running it with node --harmony-async-iteration --require ts-node/register Foo.spec.ts works.

@slikts
Copy link
Author

slikts commented Mar 20, 2018

I've also added a .js file to show that async generators there work fine.

@kulshekhar
Copy link
Owner

@slikts the target in tsconfig should be set to es5 for tests. The reason is that the output of ts-jest is processed by jest.

By default, jest uses babel to process js files (which is why there's no error in the js file) but it expects the other transformers to return code in a form that it understands without any further processing which can be es5 (or es6 depending on your version of node)

@shaunc
Copy link

shaunc commented Oct 21, 2018

Hmm... perhaps ts-jest should optionally allow compiled ts code to run through babel? I would guess that the underlying problem is jestjs/jest#6492 . However, it would seem that misalignment between javascript and jest is always possible going forward, which is precisely why the jest uses babel.

@huafu
Copy link
Collaborator

huafu commented Oct 22, 2018

@shaunc it does, it's just an option to activate, see babelConfig option there https://kulshekhar.github.io/ts-jest/user/config/#options

@shaunc
Copy link

shaunc commented Oct 22, 2018

Ah - nice :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants