Karma Istanbul fix to work with new version of Chrome - angularjs

In my AngularJs application I'm using Jasmine and Karma for my unit tests.
Recently, after a chrome update (now on 72.0.3626.81) my unit tests starting failing locally (with no change to code). I believe the error is a result of my coverage tool Instanbul.
Sometimes the error appears like this:
An error was thrown in afterAll Uncaught ReferenceError: __cov_iuQO6FdumXRPLjSMopb0JQ is not defined thrown
Other times it will appear within a specific unit test (not sure why).
I searched my application and the only file this __cov_ variable could come from is the return of a function within the Instanbul package, generateTrackerVar() within instrumenter.js.
As no code changes were made I assume that the issue is with the new version of Chrome, perhaps the security settings.
My question what permissions would karama-coverage/istanbul require? OR if anyone suspects the issue isn't security based, then what could be causing this error?
Thanks
EDIT:
I have tried to disable web security in my gulpfile like so:
browsers: [ 'Chrome_without_security' ],
customLaunchers: {
Chrome_without_security: {
base: 'Chrome',
flags: ['--disable-web-security']
}
},
But this didn't solve the issue. Is there a way to set the chrome version in this config?

I managed to solve this by figuring out the hashcode after __cov_ was related to a test file that was throwing an error. I don't know why the error didn't just appear as it normally would, that will be another problem to solve.
For now I managed to figure out the file by logging in instrumenter.js within the instanbul package. Then by removing my coverage tool I figured out the source of the issue. Simply removing the coverage tool would give me a different error but not tell me which file so I needed to do both.

Related

'Uncaught TypeError: angular.module(...).run(...) is not a function' in Grunt minified js-file

My code works on development mode, uncompressed. But when I use grunt's minify functionality and run the app in production mode, I get that error: Uncaught TypeError: angular.module(...).run(...) is not a function.
When I look into the error in Google Chrome Developer Tools, I get what you see in the screenshot. Does anybody understand where the problem is?
I am using Angular 1.4+ in Angular-Fullstack. The error occurs in vendor.{{randomstring}}.js.
Thanks for any support!
You have 2 issues here.
Dependency injection. You can edit manually the archives or use https://github.com/mgol/grunt-ng-annotate this will do this automagically for you.
Concatenation. Check this grunt plugin https://github.com/gruntjs/grunt-contrib-concat the issue here is javascript dont understand when a function end/start because dont have a separation mark, check where the error is.
})(function(a,b) {
It should be:
});(function(a,b) {
Check the "Concatenating with a custom separator" example of grunt-contrib-concat

What kind of output does the "protractor-ng-hint-plugin" generates?

I'm currently researching on "protractor-ng-hint-plugin" on how its used and what output it generates to see if it would be beneficial for my project. But, there is very little to none documentation on this plugin.
Only meaningful doc out there is https://github.com/angular/protractor-ng-hint-plugin .
I've added
plugins: [
{
package: 'protractor-ng-hint-plugin'
}
and I've verified that the plugin is loaded during the test by using --troubleshoot flag.
Has anyone used this plugin? If yes, what output does it generates?
If your app has the angular-hint.js loaded and ng-hint activated, the protractor-ng-hint-plugin would report Angular best practices violations on the command-line. Try to run tests against these sample applications and see warnings on the console:
https://github.com/angular/protractor-ng-hint-plugin/tree/master/testapp
https://github.com/angular/angular-hint/tree/master/examples

Running more than 10 tests on karma using jasmine causes: "ERROR: Some of your tests did a full page reload!"

So, this is my first project where I'm using Karma and Jasmine to unit test my angularJS code. Used Yeoman angular generator for the setup.
As soon as I reached 11 tests, I got an error saying "Some of your tests did a full page reload". I'm not doing any tests that would trigger a reload.
Digging deeper I saw the same issue being referenced on Github.
https://github.com/jasmine/jasmine/issues/366 -- (FuzzySockets comments)
The problem seems to stem from a line of code in jasmine-core
https://github.com/jasmine/jasmine/blob/master/lib/jasmine-core/jasmine.js
To avoid overflow of stack, the maximumSpecCallbackDepth is set to 20. And every time currentSpecCallbackDepth exceeds that, further tests are executed on a new stack by using the setTimout function.
This is the line that seems to cause problems and makes karma throw the error. (I've verified this by invoking the setTimeout method in my own unit test, and it threw the same error).
If change the maximumSpecCallbackDepth to 100, my tests run fine, and no errors are thrown at the end
Has anyone seen this issue and know a fix? I'm using the latest versions of karma(0.13.15) and jasmine(2.4.1).
I haven't really messed around too much with the default grunt or karma config that came with yeoman generated ones, except that I'm using the chrome launcher instead of the default phantomJS, so I don't understand how everyone else is not facing the same issue here.
+1 for this issue. As u said, it caused by maximumSpecCallbackDepth limitation, but I didn't find no fix for this issue so far. You probably could track issue here https://github.com/karma-runner/karma/issues/1101 .
One temporary solution is to reduce nested 'describe' block in your project.
I got a similar issue where the angular injections in the global beforeEach stopped working and all tests failed after the 20 limit of maximumSpecCallbackDepth.
During my investigations, I found out that angular-mock doesn't play well with the setTimeout done in jasmine when that limit is reached.
The following code that is given as example everywhere will create a new injector on each test case:
var yourService;
beforeEach(module('app'));
beforeEach(inject(function(_yourService_) {
yourService = _yourService_;
}));
Instead, you could do the following, which will use a single injector and register your modules only once.
var yourService;
module.sharedInjector();
beforeAll(module('app'));
beforeEach(inject(function(_yourService_) {
yourService = _yourService_;
}));
Hope this might help others as it took me almost a week to find out that this was the root cause of the issue and not Jasmine itself like some people think on github.

Chrome gives different results in karma than alone

I have a small app that I have been working on the UI with the client. I am using TypeScript and Angular write the client code. I created a bar bones controller to deliver hard-coded data to the UI for layout purposes and it has been working fine in Chrome and Firefox.
Now that I am ready to start adding business logic I want to implement testing, so I installed karma (which has been challenging to say the least). When I run the code with karma using the Chrome browser I get a "function is undefined" error on a function exported from a TypeScript module that still works just fine when I use Chrome outside of karma (in WebStorm). The property is there, but the defined function is not.
The js generated code seems classic and conventional to me.
Can someone tell me why the code behaves differently under karma?
When I run the code with karma using the Chrome browser I get a "function is undefined" error on a function exported from a TypeScript module that still works just fine when I use Chrome outside of karma (in WebStorm). The property is there, but the defined function is not
Mainly just ensure correct order of file (script) loading.

TypeError in qx.ui.mobile.core.EventHandler after update to qooxdoo 1.5

After updating to qooxdoo 1.5 I am seeing this error:
Uncaught TypeError: Expecting a function in instanceof check, but got #<HTMLDocument>
:8080/qooxdoo-1.5-sdk/framework/source/class/qx/ui/mobile/core/EventHandler.js?nocache=0.38786523090675473:245
Strange thing is, that I am not using the qx.ui.mobile.* classes at all. This is with a source-all build and "qx.debug" set.
As for including the qx.ui.mobile.* classes, this comes from using the source-all job, which includes, well, all known classes, also the qx.ui.mobile.* ones. Try using the normal source job, which only includes the classes necessary for your app.
As for the error, please open a bug report at http://bugzilla.qooxdoo.org. Please specify the OS and browser you are using when you get the error. If possible, supply a minimal Application.js (or a Playground link) that reproduces the error. Cheers.

Resources