Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasmine Runs Test Three Times

I am running Karma/Jasmine/Angular 2.0 tests on my development box. Just recently, Jasmine on my development box decided to start running my tests three times. Yes, exactly three times, every time.

On the first run, everything passes as expected. However, on the second and third pass, all of the same things fail. It always acknowledges that there are 7 tests, but runs 21, and 10 fails (first-grade math out the window)????

This also fails on Travis with SauceLabs. (Note: That links to an older build with 3 tests, but ran 9, and 5 fail???)

I have a screenshot, karma.conf.js file, and one suite which started this whole thing. Any help with be greatly appreciated.


Culprit [TypeScript] (Remove this and problem solved on my dev box):

Full source

describe('From the Conductor Service', () => {     let arr: Array<ComponentStatusModel> = null;     let svc: ConductorService = null;          beforeEach(() => {           arr = [/* Inits the array*/];         svc = new ConductorService();     });      describe('when it is handed a container to hold objects which need to be loaded', () => {         // More passing tests...              /// vvvvv The culprit !!!!!         describe('then when you need to access the container', () => {             beforeEach(() => {                 svc.loadedContainer = arr;             });                      it('it should always be available', () => {                 assertIsLocalDataInTheService(arr, svc.loadedContainer);             });         });         /// ^^^^^ End of culprit !!!!!     });      // More passing tests... }); 

Failing Tests:

Tests are ran three times

Browser Screenshots:

Not sure if this is related, but before all of the errors happen, the Jasmine call stack is smaller (left, observe scrollbar). After the errors start, the stack just gets bigger with repeating calls to the same functions (right, observe scrollbar).

Jasmine Call Stack

Suite Stack is Wrong:

In my test, the Nanobar and Conductor spec files are totally separate. However, you can see the suites array includes stuff from the Nanobar and Conductor specs. Somehow Jasmine mashed these two spec files together (after everything started failing), and resulted in my describe() statements not making any sense when published to the console.

Jasmine Suite Stack

Simplified karma.conf.js:

Full source

module.exports = function (config) {     config.set({         autoWatch: false,         basePath: '.',         browsers: ['Chrome'],         colors: true,         frameworks: ['jasmine'],         logLevel: config.LOG_INFO,         port: 9876,         reporters: ['coverage', 'progress'],         singleRun: true,                  coverageReporter: {             // Code coverage config         },          files: [             // Loads everything I need to work         ],          plugins: [             'karma-chrome-launcher',             'karma-coverage',             'karma-jasmine'         ],          preprocessors: {             'app/**/*.js': ['coverage']         },          proxies: {             // Adjust the paths         }     }) } 
like image 451
Oliver Spryn Avatar asked Feb 29 '16 22:02

Oliver Spryn


1 Answers

Can you try refreshing your browser in your first assertion in each of your test files? Try this:

browser.restart(); 

I had the same problem and this fixed it for me.

like image 149
Zion Avatar answered Oct 05 '22 19:10

Zion