Karma and Jasmine weird behavior when using the word "base"

I am here to ask for help because I can’t find a solution, and I spent so much time on this.

The problem is the strange behavior in karma + jasmine tests, initially I thought that the problem was related to AngularJs code, but, scraping, shrinking, I reached the point where nothing else needs to be removed, and the problem is 100% in angular.

The actual code I'm using is the following:

test.js:

'use strict'; describe('Unit tests suite', function () { it('test', function () { expect('base').toEqual(''); }); }); 

karma.conf.js:

 module.exports = function (config) { config.set({ basePath: '', frameworks: ['jasmine'], files: ['*.js'], exclude: [], preprocessors: {}, reporters: ['progress'], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['PhantomJS'], singleRun: false, }) } 

Absolutely nothing. The result of this test is:

 13 02 2016 04:32:39.559:WARN [karma]: No captured browser, open http://localhost:9876/ 13 02 2016 04:32:39.571:INFO [karma]: Karma v0.13.15 server started at http://localhost:9876/ 13 02 2016 04:32:39.578:INFO [launcher]: Starting browser PhantomJS 13 02 2016 04:32:41.248:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket HiC4WW_4235Nlf0rAAAA with id 54292207 PhantomJS 2.1.1 (Mac OS X 0.0.0) Unit tests suite test FAILED Expected '/Users/Gianmarco/Desktop/test' to equal ''. /Users/Gianmarco/Desktop/test/test.js:5:31 PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.003 secs / 0.003 secs) 

As you can see, it seems that the word "base" is being changed using the folder path. It makes me go crazy. I can’t understand why this is done.

I tried with both MacOSX and Ubuntu 14.04, and the result is the same.

To prepare the folder, I did the following:

 mkdir test cd test npm install jasmine-core karma-cli karma-jasmine karma-phantomjs-launcher phantomjs-prebuilt --save karma init karma start 

and of course my system had npm install karma-cli -g some time ago.

Versions:

 jasmine-core@2.4.1 karma@0.13.21 karma-cli@0.1.2 karma-jasmine@0.3.7 karma-phantomjs-launcher@1.0.0 phantomjs-prebuilt@2.1.4 

The same behavior is obtained using the word absolute, which is replaced by an empty string.

+5
source share
1 answer

I believe that the problem with the default reporter in karma (progress) seems that URL_REGEX matches both basic and absolute, since all other regular expressions are optional.

 var URL_REGEXP = new RegExp('(?:https?:\\/\\/[^\\/]*)?\\/?' + '(base|absolute)' + // prefix '((?:[Az]\\:)?[^\\?\\s\\:]*)' + // path '(\\?\\w*)?' + // sha '(\\:(\\d+))?' + // line '(\\:(\\d+))?' + // column '', 'g') 

https://github.com/karma-runner/karma/blob/684ab1838c6ad7127df2f1785c1f56520298cd6b/lib/reporter.js#L25

+2
source

Source: https://habr.com/ru/post/1242933/


All Articles