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

not working out of the box with jest #38

Closed
roger-gl opened this issue Aug 30, 2019 · 10 comments

Comments

@roger-gl
Copy link

@roger-gl roger-gl commented Aug 30, 2019

I get the following error when I run a test that uses the store with jest:

SyntaxError: Unexpected token export

  1 | import {Injectable, OnDestroy} from '@angular/core';
> 2 | import {ObservableStore} from '@codewithdan/observable-store';

I tried to add transformIgnorePatterns like:

"transformIgnorePatterns": [
"node_modules/(?!@@codewithdan|observable-store)"
]

But it did not help.

@DanWahlin

This comment has been minimized.

Copy link
Owner

@DanWahlin DanWahlin commented Aug 30, 2019

Thanks for the information. I don't use Jest so I'd need to see a project that has all of the required pieces in place. If you're able to create and share a simple project I'll be happy to take a look.

@roger-gl

This comment has been minimized.

Copy link
Author

@roger-gl roger-gl commented Aug 30, 2019

The easiest thing would be to just create a simple project with nx. I'll try to do that on Sunday.

@DanWahlin

This comment has been minimized.

Copy link
Owner

@DanWahlin DanWahlin commented Aug 30, 2019

Sounds good. I'm out on vacation this next week but I'll look at it once I get a chance.

@rogergl

This comment has been minimized.

Copy link

@rogergl rogergl commented Sep 1, 2019

Thanks. You can find the project here: https://github.com/rogergl/os-test

@DanWahlin

This comment has been minimized.

Copy link
Owner

@DanWahlin DanWahlin commented Sep 10, 2019

Thanks for the project. I looked into this and it's due to how Jest handles ES2015 modules (or rather doesn't handle them) from what I can tell. Observable Store compiles using ES2015 for the module setting since it's designed for apps using ES2015 modules. However, Jest has some challenges with that from what I've seen in the various repository issues. Here's a specific post related to ts-jest:

kulshekhar/ts-jest#970

It implies that the transformIgnorePatterns you tried should work but I couldn't get that to work either. It may be a matter of updating the value to something different potentially but I'm not sure having never used Jest or that setting before.

I tried compiling Observable Store using commonjs instead of es2015 in my tsconfig and that does work with Jest and your project, but I'd have to research implications of making that type of change before actually implementing and releasing a new version with it.

It's not something I'm going to have time to look into right away since this isn't technically an Observable Store problem and more of a problem with how Jest handles ES2015 modules. If I end up changing the module setting and releasing a new version with that I'll let you know.

@roger-gl

This comment has been minimized.

Copy link
Author

@roger-gl roger-gl commented Sep 30, 2019

Ok, thanks for the help. Right now I added the sources of this project just as a lib and with that change Jest works.

@DanWahlin

This comment has been minimized.

Copy link
Owner

@DanWahlin DanWahlin commented Sep 30, 2019

Glad that works for the short-term. I'm hoping to look at switching it to commonjs once I get back from a trip I have this month. Just need more than 24 hours in a day. :-)

@DanWahlin

This comment has been minimized.

Copy link
Owner

@DanWahlin DanWahlin commented Oct 6, 2019

As an update, version 2 of the project is going to use CommomJS so it should work out of the box with Jest. I’m hoping to release it soon.

@roger-gl

This comment has been minimized.

Copy link
Author

@roger-gl roger-gl commented Oct 7, 2019

Great news. Thanks

@DanWahlin

This comment has been minimized.

Copy link
Owner

@DanWahlin DanWahlin commented Oct 13, 2019

v2 is now out and it uses CommonJS. Give it a try when you get a chance.

@DanWahlin DanWahlin closed this Oct 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.