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

Script Error while running Karma start #1268

Open
Giriraj24 opened this issue Dec 17, 2014 · 23 comments
Open

Script Error while running Karma start #1268

Giriraj24 opened this issue Dec 17, 2014 · 23 comments

Comments

@Giriraj24
Copy link

Hi All,

Let me give the back ground.

Almost around one month back, I used to run 1600 Unit test cases with out any problem. Every thing was working fine.

One fine day, We started getting "Disconnected" error message and at times just place "script error" with unknown reasons so it stopped running the UTC's. So we decided to upgrade the karma from "0.12.16" to the latest one(0.12.28) but that also did not fix the issue. then as next option we upgraded our jasmine from 1.3.0 version to jasmine-2.0* version and that also did not solve the problem.

To drill down the problem, we decided to put less number of test cases, like just to 50 to find out the problem.

so when I run the unit test cases today, out of running 10 times, 8 times I am getting following error about "script error":

[jenkins@xcclx0000 workspace]$ karma start
INFO [karma]: Karma v0.12.28 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Linux)]: Connected on socket aEsvNiTaam8VX0g4HllC with id 4602773
PhantomJS 1.9.8 (Linux) ERROR
Script error.
PhantomJS 1.9.8 (Linux): Executed 47 of 50 ERROR (0 secs / 3.533 secs)

PhantomJS 1.9.8 (Linux) ERROR
PhantomJS 1.9.8 (Linux): Executed 47 of 50 ERROR (3.549 secs / 3.533 secs)
PhantomJS 1.9.8 (Linux): Executed 47 of 50 ERROR (3.549 secs / 3.533 secs)

Following versions of karma,node and phantomJS I am using:

  1. Karma : 0.12.28
  2. node : v0.10.28
  3. phantomJS: 1.9.8

so I got no idea why this suddenly started failing. It was all good one month back where I was able to run 1600 test cases, now I am unable to run 50 as well.

If you also want to see karma.conf.js content then let me know , I can paste it here.

But please help. Any help will be really great.

Thanks,
Giriraj

@maksimr
Copy link
Contributor

maksimr commented Dec 17, 2014

@Giriraj24
Do you use external script?
If yes then you may look at issue #543.
May be it will help you.

It reproduced only in PhantomJS?
You can open debug page and try cache error.

@ehacke
Copy link

ehacke commented Jan 18, 2015

I have the same issue. After spending a couple hours debugging it I have found that it somehow seems to be related to the number of tests. However, that's not purely the problem because running thousands of near-blank tests in a new project works fine.

For me, if I go over 103 tests, about 70% of the time it fails at test 77 with:

PhantomJS 1.9.8 (Linux) ERROR
  Script error.

It doesn't seem to matter where I add the tests in my current project, or what is in the tests (even if they are blank).

However, as mentioned, if I start up a fresh project, randomly add a few thousand near-blank tests, it works fine.

Weird. Not sure how to continue debugging it at this point. Though it feels like it might be a memory leak somewhere.

@Giriraj24 did you find any resolution?

I'm running the following:
Node 0.10.33
PhantomJS 1.9.8
Karma 0.12.31 (although it also happens with 0.12.24)

@maksimr
Copy link
Contributor

maksimr commented Jan 18, 2015

@ehacke do you use external script in your project?

@ehacke
Copy link

ehacke commented Jan 18, 2015

@maksimr I pull one thing in from Stripe using JSONP, but I don't directly call a cross-domain script.

It also looks like there is no problem running the full suite of tests in Firefox, the issue only happens in PhantomJS.

@ehacke
Copy link

ehacke commented Jan 18, 2015

@maksimr to be more specific, I have this in my index.html

<script type="text/javascript" src="https://js.stripe.com/v2/" crossorigin data-remove="false"></script>

But it seems that if it were a cross-site scripting issue, I would expect it to fail 100% of the time with any number of tests, not pass with 103 tests, and then fail 80% of the time when I add 1 more blank test.

And I'd expect it to fail in Firefox, which it does not.

@maksimr
Copy link
Contributor

maksimr commented Jan 18, 2015

@ehacke

But it seems that if it were a cross-site scripting issue, I would expect it to fail 100% of the time with any number of tests, not pass with 103 tests, and then fail 80% of the time when I add 1 more blank test.

And I'd expect it to fail in Firefox, which it does not.

Maybe, but will be cool if you try remove/mock this script and reproduce error.

Thanks

@ehacke
Copy link

ehacke commented Jan 18, 2015

@maksimr Yeah I'll give it a shot and update once I've eliminated all the possible same-origin issues.

@ehacke
Copy link

ehacke commented Jan 18, 2015

@maksimr After some searching it looks like one of the dependencies I pulled in with bower was doing some sneaky creation of html and directly including a script tag which called a remote google .js file. Removing just that dependency and references to it fixed the issue. Thanks! That was most likely the problem. The Stripe JSONP calls don't seem to cause problems.

Still weird that it would only arise once I included a certain number of unrelated tests though. And weird that it would only trigger a failure 70-80% of the time.

But in any case, thanks a lot for your help, and to others with this issue, deeply search your dependencies.

@maksimr
Copy link
Contributor

maksimr commented Jan 18, 2015

@ehacke no problems

@Deepakdubey90
Copy link

Hi,
i' am writing unit Test-Case for UI by using PhantomJs with Karma(angularJs) . but got an error on console .
Error >>>>>>>>>>>>>>>>>
PhantomJS 1.9.8 (Linux): Executed 36 of 39 SUCCESS (0 secs / 0.104 secs)
PhantomJS 1.9.8 (Linux) ERROR
""Some of your tests did a full page reload!""
PhantomJS 1.9.8 (Linux): Executed 36 of 39 ERROR (0.141 secs / 0.104 secs)
npm ERR! Test failed. See above for more details.
Error>>>>>>>>>>>>>>>>>

i'm not able execute all of the test case because of this error(skip few of the test case while executing.) how to debug this error
""Some of your tests did a full page reload!"".
Please suggest me to fix this issue.

@krishna005-zz
Copy link

Hi all
am getting same issue can any one say why it happen
eventually all are getting success and getting error.

Running "clean:server" (clean) task

1 path cleaned.

Running "wiredep:app" (wiredep) task

Running "wiredep:test" (wiredep) task

Running "concurrent:test" (concurrent) task

Running "copy:styles" (copy) task
Copied 3 files

Done, without errors.

Running "autoprefixer:server" (autoprefixer) task
Autoprefixer's process() method is deprecated and will removed in next major release. Use postcss([autopre
File .tmp/styles/animate.css created.
Autoprefixer's process() method is deprecated and will removed in next major release. Use postcss([autopre
File .tmp/styles/styles.css created.
Autoprefixer's process() method is deprecated and will removed in next major release. Use postcss([autopre
File .tmp/styles/tinyeditor.css created.

Running "autoprefixer:dist" (autoprefixer) task
Autoprefixer's process() method is deprecated and will removed in next major release. Use postcss([autopre
File .tmp/styles/animate.css created.
Autoprefixer's process() method is deprecated and will removed in next major release. Use postcss([autopre
File .tmp/styles/styles.css created.
Autoprefixer's process() method is deprecated and will removed in next major release. Use postcss([autopre
File .tmp/styles/tinyeditor.css created.

Running "connect:test" (connect) task
Started connect web server on http://localhost:9001

Running "karma:unit" (karma) task
WARN [watcher]: Pattern "D:/EWS-FED/test/mock/*/.js" does not match any file.
INFO [karma]: Karma v0.12.37 server started at http://localhost:8090/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Connected on socket JIIDsWBVg7Sl7s4skFDt with id 77874236
PhantomJS 1.9.8 (Windows 7 0.0.0) ERROR
Script error.
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 75 of 75 ERROR (0.411 secs / 0.544 secs)
Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.

@Deepakdubey90
Copy link

@krishna005,
I have fixed that issue. somewhere in my test case i have used the 'SpyOn' on $watch function in beforeEach block, that was reloading the test case. so i just removed that and my test is running perfectly.
If u r putting "$watch , $location, $window" in any function or provider then use that very carefully, because that can reload your test case, and try to avoid putting 'Spyon'(mock a function) on function having "$watch, $location, $window" in BeforeEach block.

@krishna005-zz
Copy link

@Deepakdubey90
Thanks for reply
but if I reduce my test case count it is working 5n.And I didn't used "Spyon" in any of my test case.

@Deepakdubey90
Copy link

@krishna005,
have u set $watch on any function or implementing something like $window reload in your test case . U can simply debug your test case by commenting the test-case file one by one from karma.conf.js to get the test-case file having bug.

@krishna005-zz
Copy link

@Deepakdubey90
in my test case I've not used them but in my angularjs controller am using $window but am not testing that file

@Deepakdubey90
Copy link

@krishna005 ,
I think there might be some dependency issue., just comment the file path from karma.conf.js having $window as dependency and run the test cases..

@krishna005-zz
Copy link

@Deepakdubey90
it works in chrome but issue with phantomJS only.

Running "karma:unit" (karma) task
WARN [watcher]: Pattern "D:/EWS-FED/test/mock/*/.js" does not match any file.
INFO [karma]: Karma v0.12.37 server started at http://localhost:8090/
INFO [launcher]: Starting browser PhantomJS
INFO [launcher]: Starting browser Chrome
INFO [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Connected on socket GCCyql7wLpGmtWPp6DV7 with id 27478529
PhantomJS 1.9.8 (Windows 7 0.0.0) ERROR
Script error.
PhantomJS 1.9.8 (Windows 7 0.0.0) ERROR
Script error.
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 64 of 75 ERROR (0.35 secs / 0.431 secs)
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 64 of 75 ERROR (0.35 secs / 0.431 secs)
Chrome 44.0.2403 (Windows 7 0.0.0): Executed 75 of 75 SUCCESS (0.808 secs / 0.463 secs)
Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.

@msintaha
Copy link

msintaha commented Mar 8, 2017

Has anyone found any fix for this? I'm facing the same problem in my Jenkins CI server and the tests run perfectly in local env but fails in CI, UNLESS I decrease the number of tests. It seems like it can only run 139-140 tests successfully but after that it starts giving Script Error. This is a huge issue as it's not letting me add more tests. I've also removed the $window spies but it still doesn't solve my problem. Also replaced ALL external scripts that were loading from CDN with local file scripts

PLEASE issue a fix for this!

@olala7846
Copy link

+1 the same issue, fixed by simply adding 1 dummy test. Absolutely no idea why...

@GuyMograbi
Copy link

GuyMograbi commented Jan 10, 2018

@ehacke I don't think it's weird it is only after you added X amount of tests etc.
sounds like an async process is going on.
fast network would increases chances of failing, slow will decrease.
more tests will increase changes of failing due to the tests taking longer, less tests will decrease.

fits the profile.

@olala7846 what do you mean by 'dummy' ? what test did you add that solved this issue.

Also - is it possible to alert on external scripts loading which will help debugging the issue?

@olala7846
Copy link

olala7846 commented Jan 11, 2018

@GuyMograbi thanks for responding.
Well, it's been a long time, but as far as I can remember, I added something like

it('pass', () => {
   expect(true).toBe(true)
})

And I think It may have something to do with race condition, I haven't seen this type of error after I use jasmine clock instead of patching window.time myself

@neridonk
Copy link

im running into the same issue dummies didnt work for me

@trusktr
Copy link

trusktr commented Mar 3, 2020

I had this problem (the "Script error" message with no helpful information), and here's how I fixed it.

This might not work for you, and maybe there are more causes than what I fixed in my case, but the following might help debug.

In my case I am using karma-electron, but that may not matter much, as this error appears to happen with different browsers, as mentioned here and in #543.

It appears that when there are uncaught errors, the browser propagates the error to Karma somehow, but without all the details.

So what I did (and it is ugly) was I made karma wrap all my tests with try-catch blocks, and in the catch(err) block I call console.log(err) and then re-throw the error so that the error continues to propagate as usual.

This completely solved the issue for me, now any errors are logged to console.

One way that you can set this up is, at the top of your karma.config.js file,

  • use a tool like globby to get a list of all your test files.
  • for each test file
    • read the content
    • prepend the line try { at the beginning of the file (but after import statements if you're using those)
    • append a } catch (e) { console.log(e); throw e } line to the end of the file
    • Note, basically this try-catch wraps your describe calls.
    • Note, if you're using require, wrap the require() calls too (unlike with imports, which can't be wrapped) to catch more errors.
    • write the files to a new location, like ./tmp-karma-test-build
  • Now update your config file's files field to point to the new files, so Karma will load the modified test files instead of the original ones.
  • In your script where you run the karma command, make sure to erase the .tmp-karma-test-build folder, and add it to your .gitignore

Basically that's what I did, more or less. Now when I run Karma, I see helpful error messages logged to console instead of just Script error. at :0:0.

Note, a more robust way to do it is make new entry points in the .tmp-karma-test-build folder, where each entry point uses require() or import() to import your actual test files from their original locations. Then, just wrapt the require() or import() calls with try-catch to catch all possible errors, even with ES Modules. This is easy to set up if your tests use require() but if your tests use ES Module import then you'll need to use @babel/register in the entry points (faster?) or karma-webpack in your Karma config (slower?).

Your mileage may vary if it isn't the same issue.

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

No branches or pull requests

10 participants