-
Notifications
You must be signed in to change notification settings - Fork 306
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
Can not run unit tests through jest framework because of SyntaxError: Unexpected token export #66
Comments
This issue must be related to #64 |
Do you have a tsconfig for specs? Because you need TS to transpile ES6 modules to commonjs: like here:
|
Yes I have. Here is it. I have generated Angular app (generated via @angular/cli@1.3.0). So I think I have everything what you have in your Angular example Also, as we can see from output with
May be |
Look at my spec ts config. Note this section. I mean files and include sections. I thought it can be because of it. There are no *.js files there. But your example have same code there. Are you sure this tsconfig influence transpiling of files? Should I provide something else so you can understand the problem better? By the way you can easy repro this problem in a few steps. |
I'm going to close this, as it looks like the same issue as #64. Let's discuss it there. |
Hm, just checked out the repo and it seems a little different here. |
So do you suggest to compare all configs? I checked and everything was same... On first look. I also tried to add
And I added option to my config to use What else I can compare? We have |
The preprocessor used is I've investigated a bit and it's not a problem with Jest. The jest-preset-angular/preprocessor.js Line 13 in f3970dc
That's all I can help with. |
By the way. How you suggest to use process.stoud.write in your file:
You define process and it is not that global nodejs process anymore, isn`t it? |
Looks like there is some problem with transformIgnorePatterns opt. I tried:
And I don't see anything from node_modules at all. I also tried:
And now I see:
in the output. But result is still same :)
|
Any thoughts? PS: console.log works from time to time. |
just try
Then you can check the output of |
@thymikee ts-jest does use babel internally for some things, such as synthetic default modules. |
@GeeWee wasn't aware of that, thanks! |
If the distributed package contains ES2015+ code, you have to preprocess it via Here is an example how to set this up properly...
(Preset can be installed via |
@thymikee I tried this:
I have no throws :) I am trying with:
|
After @DorianGrey comment I have this jest config:
and this .babelrc:
And I stopped getting error about angularfire2. Looks like now everything is ok with it. I got another error:
I don't get this in runtime. |
Probably I get my last error not because of problems with jest-preset-angular. But why I didn't get that error in jasmine? You can see last result there: https://circleci.com/gh/sharikovvladislav/ng2-diary-book/98. By the way: I don't know why but result on CI and on my Mac differs. I have another error. Argh! Perhaps I should debug this problem too. I need to understand why in Chrome I don't get error, but jest shows this error. Lets pause this issue for some time. @thymikee |
Not sure why you get this - it's not a If I try to execute your tests with the setup above, it raises an error like this, which is related to
See the related discussion: #52 |
@DorianGrey hm, I have same on CI: I got another error:
I will check again. |
it seems that
(API docs: https://developer.mozilla.org/en-US/docs/Web/API/CSS) Test execution afterwards:
|
@DorianGrey can you please pull changes and try again? I pushed last changes to the repo. I pushed global mocks and your mock too. All of that changes are available there in the PR sharikovvladislav/ng2-diary-book#41 I still get same error O_O:
But look at the CI build: https://circleci.com/gh/sharikovvladislav/ng2-diary-book/99 . It works!!! Eeeehm. Any ideas why I get different result relative CI and you? I removed node_modules and run |
Can you also show |
Here you are:
However, this error is not related to Have you tried to wipe out you local jest cache? (See https://facebook.github.io/jest/docs/troubleshooting.html#caching-issues) |
Did you get green tests after pulling my changes? I still have same. Ye firebase is same. Why you think that the problem is not related to firebase? I think so because of callstack: I didn't not know about jest cache. Thank you. Here is execution with
I checked firebase code. I don't see usage of KeyIndex exported function. By callstack: error was produced from this instruction: |
Yes, same as in your CI build.
Because the referenced line points to an
The referenced line is: The only issue I've found with a similar problem was this: I'm not sure what causes the error in your case, I can only tell that it works fine on both CI and my machine, which both performed a clean checkout, build and test. |
Ok. Lets stop debugging this. Actually I realised that service which causes the problem is not needed in that case. I removed service connected to the firebase and everything is ok now. I don't know why me, you and my CI have different result. Thats very strange. We solved initial problem long time ago. @thymikee perhaps this section should be extended after this issue? https://github.com/thymikee/jest-preset-angular#unexpected-token-importexportother what do you think? I mean we can add here information about |
I'd love to accept a PR with this! |
@DorianGrey Thank you very much for your suggestion. You fully solved my problem. Also thank you for next troubleshooting. You helped a lot! @thymikee thank you for your work with jest-preset-angular. I want to try snapshot testing. Since I solved all problems at the moment I will do it in the near future. |
Closing this one for now. |
Yes this seems be similar to my issue #64, so I will have a look over your suggested fixes and see if any of them work for me also. Thanks |
@kidd3 did you solve your problem? |
@sharikovvladislav unfortunately I haven't had time today to look at this, my project is ongoing. I will aim to try it tomorrow and feed back. Is your repo that you created updated with your fix? |
@kidd3 I have changes which solve the problem in this PR: sharikovvladislav/ng2-diary-book#41 |
So I've installed babel-preset-env via npm and adding a .babelrc file containing The same error 'SyntaxError: Unexpected token import' is still occurring for me, but now with additional warning: My original issue is here #64 if we can continue there I would appreciate any help, thanks. |
lets go to #64 |
Hi!
I have this problem:
You can see what how I set up jest here: https://github.com/sharikovvladislav/ng2-diary-book/tree/feature/try-add-jest
Also, I debugged a bit and realised that angularfire2 deploy their lib without transpiling, so I have to do it by myself. Thats why I added this to the initial config you suggest:
Repro:
I also described everything there https://stackoverflow.com/questions/45786951/why-i-got-syntax-error-on-jest-run-when-transpiling-is-on and there angular/angularfire#1118
I also tried to set empty array to
transformIgnorePatterns
and I still get same error. Tests are running for centuries so jest (babel) is trying to transpile whole project (including node_modules), but I still get same problem.Can you please help me?
The text was updated successfully, but these errors were encountered: