jasmine,teamcity,karma-runner,karma-jasmine , Can one installation of karma be configured to run both jasmine 1.3 and 2.0 tests?

Can one installation of karma be configured to run both jasmine 1.3 and 2.0 tests?


Tag: jasmine,teamcity,karma-runner,karma-jasmine

We have a TeamCity CI server that needs to be able to execute Jasmine 1.3 and Jasmine 2.0 tests (at different times, on different jobs). It is using the TeamCity Karma integration. My research so far is inconclusive, but it seems like Karma can only have one version of the Jasmine plugin at a time, so it's an either-or proposition. Another way to attack it would be to have two separate installs of Karma on the TeamCity server, but I'm a newbie at both TeamCity and Node, and not sure how this would work out. Any suggestions?



Karma looks for the karma-jasmine plugin in the local node_modules folder. The quickest way to switch versions is to simply replace the karma-jasmine folder with the version you want (automated or otherwise) before running your tests, but this has the potential to get messy.

Different installs of Karma is likely the cleaner way. There isn't any issue with having 2 (or as many as you like) local installs of Karma, since they all live under a node_modules folder. In an example directory structure like this, the Karma installation under 1.3 won't know anything about the Karma installation under 2.0.


karma-cli, the module that lets you run karma in a command window from anywhere, however, is one that is installed globally and so has one installation.

If you ran karma start while in the 1.3 folder, karma-cli will execute the Karma under 1.3, which in turn will load the karma-jasmine under 1.3. The same applies when in the 2.0 folder. This gives you the option of maintaining versioned test dependencies.


Mocking Angular $window in unit test cases

I have been trying to unit test my angular custom service written in Typescript. The service reads a global variable defined on the Window object. I have made it promise, so that in future I can make a AJAX call to get this information. Here is my stripped down service:...

Testing Meteor packages with Velocity?

Velocity is an amazing testing framework for Meteor and I am currently using it to test my application code. Now I added a local package to the app, but I don't know how (or if) I can test the package with Velocity, too. I would like to drop tinyTest in...

Why does Jasmine toEqual return true when comparing empty array with empty object?

I get why the following returns false... expect({}).toBe({}); And I get why the following returns true... expect({}).toEqual({}); But why is the following true? expect([]).toEqual({}); ...

How to call browser.get only once in a script?

I am new to protractor, right now I am putting browser.get(URL) within the first 'it' statement and then for my afterEach statement I make the browser go back to the homepage. I am wondering if there's a better place to put the browser.get statement to make my tests more module?...

How to solve error about “invalid selector” when using “if statement” in Protractor JS?

I want to use an invisible element as a condition if it present do X and else do Y. I've already tried to use by the class of this element as the locator and the ng-model and binding of him but none of them is worked :/ Please your assistance...

Protractor, Done and Expect, why do we need wait?

I thought Done would make things run synchronously, meaning after I click a link, the click call back would happen after the click, apparently not as this doesn't work. browser.ignoreSynchronization = true; var firstURL = "https://www.google.com/?gws_rd=ssl"; describe("test", function () { browser.get("http://www.google.com"); it("Should be on google url", function () { expect(browser.getCurrentUrl()).toBe(firstURL);...

_foo is not a function, when called from init method in Jasmine

I am testing a controller which has a private method _init() called during its instantiation. It does some service calls (which are mocked out) and calls some private helper functions within the same controller. It all works great up until within a success block of a service call it tries...

Trying to spy (Jasmine) on Array.prototype methods causes stack overflow

This is pretty odd. Using the testem runner with jasmine2 and the following spec executes (though it correctly flags that there are no expectations): describe('Spying on array.prototype methods', function(){ it('should work this way', function(){ spyOn( Array.prototype, 'push' ).and.callThrough(); // expect(1).toBe(1); }); }); However, add an expect (any expect!) and it...

ReferenceError: module is not defined (angular js unit testing with Jasmine)

I found a lot of questions about this, but the answers didn't work for me. I have a small controller in angular js. It works fine, and I wanted to start testing. I downloaded Jasmine standalone from here. I put my controller in the "src" folder, and another js file...

how to mock $state.params in jasmine unit testing

I have the following controller EditMeetingCtrl.js (function() { 'use strict'; angular .module('myApp') .controller('EditMeetingCtrl', EditMeetingCtrl); EditMeetingCtrl.$inject = ['$rootScope', '$scope', '$state', '$http', '$translate', 'meetingService', 'companyService', 'notificationService', 'meeting']; function EditMeetingCtrl($rootScope, $scope, $state, $http, $translate, meetingService, companyService, notificationService, meeting) { $scope.meeting = meeting; $scope.companyId = $state.params.companyId; $scope.save = save; function...

Accessing scope.variables inside a function in jasmine

I am trying to get the assert the value of the $scope.buttonDisable variable which is inside the save(). here is the test case describe('EditMeetingCtrl.save()', function () { var $rootScope, scope, $controller , $q , state , controller ; var companyService , meetingService ; beforeEach(angular.mock.module('MyApp')); beforeEach(angular.mock.inject(function (_$httpBackend_, _companyService_ , _meetingService_ )...

Protractor in Node: How do I order my tests to run synchronously?

I'm wondering how to execute multiple "describe" blocks in synchronous order? describe('Go To Home Page', function () { browser.ignoreSynchronization = true; it("Url should be on Login Page", function () { browser.get(HomePageUrl).then(function () { browser.wait(urlChanged(loginPageUrl), 2000).then( function (newurl){ var url = browser.getCurrentUrl().then(function (url) { expect(url).tobe(loginPageUrl); //I know I'm at Login page...

Testing an Angular directive using Jasmine 2's spyOn

I have an AngularJS directive I'm trying to test with Jasmine 2. Here's a Mock service that I have defined at the beginning my test. var Note = { getNotes: function (type, id) { console.log('I have been called') }, save: function () {} }; And here's my test: beforeEach(function ()...

Installing Teamcity build agent as a user: failed to install the service. selected account does not have enough rights

I want to install a TeamCity BuildAgend as a user. When entering my user credentials here: I always get this error: NOTE: My account (user) is Administrator with full permission! How can I do this?...

“Test Finished” handler in Jasmine?

How to add a Test-Finished handler to a jasmine test? I need it to deallocate resources consumed by the test. I'm using the very latest version of jasmine 2.3.1 with Node JS....

Jasmine Unit Tests Unexpected this Reference

I am trying to test a fairly simple JavaScript function in Jasmine, however the first statement is throwing an error for being undefined. myClass.prototype.functiontoBeTested = function() { var x = this.method() ... } The above throws an error in Jasmine as method is not a function and is undefined. The...

Node.d.ts issues errors using typescript compiler, how do I fix?

I have a project that's a NODE console application project using Visual Studio 2013. When I compile the solution I'm getting typescript errors as follows: Typescript wants a semicolon after export interface ReadableStream extends EventEmitter { readable: boolean; read(size?: number): string|Buffer; //Like this ----> read(size?: number): string;|Buffer; Which means I...

How to invoke spyOn on a scope function

I have the following jasmine spec. describe('ViewMeetingCtrl', function () { var $rootScope, scope, $controller , $q ; beforeEach(angular.mock.module('MyApp')); beforeEach(inject(function ($rootScope, $controller ) { scope = $rootScope.$new(); createController = function() { return $controller('ViewMeetingCtrl', { $scope: scope, meeting : {} }); }; })); it('the meeting type should be equal to an object',...

How do I set up a TeamCity build job to execute a maven job with no pom

We have an in-house developed MOJO that generates content and doesn't require you to have an existing project or POM. Think of the maven archetype plugin, where you can just run mvn [mojo]:[goal] and have maven just execute that goal without a POM. This MOJO connects to a specific database...

Continuous deployment and running with TeamCiy

I have a project that is built into an executable. Some kind of server. And a Team City as CI. I configured Team City to automatically build my sources. I would like to achive the following steps: Sources are built by Team City when someone commits into repo. (done) Built...

Jasmine spyOn with multiple returns

I would like to test my angular application with Jasmine. So I created some tests, most of them work fine. But, one of my functions require the user to fill in an prompt. Tests can not fill this prompt, so I mocked them with spyOn(window,'prompt').and.returnValue('test'). This works, but only once....

How to fetch the Value of Teamcity Configuration in java?

I have a piece of java code where I have to display the Teamcity build configuration name. This piece of code will be executed in one of the steps configured for the configuration. can we read value of the env variable %env.TEAMCITY_BUILDCONF_NAME% set in Teamcity configuration settings and use or...

Jasmine beforeEach not called

Just starting with Jasmine and following the instructions on the Jasmine website for async testing I notice the beforeEach function is never called. Any idea why not? I don't find any hints relevant anywhere on the web. Thanks. Code The code is really simple: describe("Testing test.php", function() { it ("Gets...

Jasmine resolving promises after calls but before expects

For testing my controller I have some services mocked out using $q injection. These will reject or resolve the promises where appropriate. My tests rely on spies to monitor if functions have been called. I've found all over that I need to call $rootScope.$digest() which works if I include it...

Is it possible for jasmine to access the scope methods defined in an angular directive controller?

I'm trying to unit test a directive like the one below. I want to be able to call the functions defined in the directive's controller ($scope.save), but my tests can't seem to access that scope at all. I also tried isolateScope(), but that didn't return the inner $scope object like...

How to write jasmine test for following angular service which uses API and call backs

In my AngularJS application, I am having trouble figuring out how to unit test the following code: This is the service being used by my test controller: angular .module('web.template') .factory('testService', testService); testService.$inject = ['$http']; function testService($http) { return { getTestDatas: function (callback) { var data = { 'testParams': "test" };...

Spy on a service method call using jasmine Spies

I have the following controller ViewMeetingCtrl.js (function () { 'use strict'; angular.module('MyApp').controller('ViewMeetingCtrl', ViewMeetingCtrl); ViewMeetingCtrl.$inject = ['$scope', '$state', '$http', '$translate', 'notificationService', 'meetingService', '$modal', 'meeting', 'attachmentService']; function ViewMeetingCtrl($scope, $state, $http, $translate, notificationService, meetingService, $modal, meeting, attachmentService) { $scope.meeting = meeting; $scope.cancelMeeting = cancelMeeting; function cancelMeeting(meetingId,...

TeamCity checkout GitHub repo to specific absolute path

My TeamCity VCS Root step needs to checkout a specific GitHub repo to a specific absolute folder on the agent ( Windows server ) : c:\github\{organization}\{repo} I'm not understanding how to construct my checkout rule to do this. By default, checkout rules are relative to the checkout dir which is...

Mock the value of a service inside directive's unit test

Inside my directive's instantiation I have a call to a method that returns some data: data = myService.getData() and later in the code I am doing something = data[id] In karma I have an error, cannor read id of undefined, meaning that data is undefined. I tried to mock the...

How do I support jasmine and es6 syntax in Visual studio Code?

Question where can I find and how do I add support for jasmine and es6 syntax in Visual studio code? ...

Halt javascript execution until promise is resolved

I have a specific use case where in test code I want to fetch a tables headers (async) and then dynamically create getters on a javascript object. The syntax that I would like to use in my test is antenneTable.row(0).getAzimut();. The problem I am having is that antenneTable.row(0); returns a...

Jasmine SpyOn haveBeenCalled on function reference don't work (Angular)

In my Angular controller I have implemented a listener, that call a function by reference: $scope.$on('$destroy', vm.popoverChooseProfile.remove); I have implemented a test with Karma and Jasmine. it('should remove the popover the scope is destroy', function() { var vm = createController(); vm.popoverChooseProfile = MOCK_POPOVER; spyOn(vm.popoverChooseProfile, 'remove'); $scope.$destroy(); expect(vm.popoverChooseProfile.remove).toHaveBeenCalled(); }); The test...

How to test a meteor method that relies on Meteor.user()

I am trying to determine the best way to test my code and am running into complications from every direction I've tried. The basic code is this (though far more complex due to several layers of "triggers" that actually implement this): Client populates an object Client calls a meteor method...

spyOn listener watch function not working

When I try to spyOn the listener function of a $scope.$watch, is like never call the spyOn http://jsfiddle.net/b8LoLwLb/1/ My controller angular.module('angularApp') .controller('MainCtrl', function ($scope) { $scope.name = ''; this.changeName = function () { console.log('the name has change to ' + $scope.name); }; $scope.$watch('name', this.changeName); }); My test describe('Controller: MainCtrl', function...

Expect fails for verifying inner HTML

For some reason my assert in protractor fails, what i'm trying to do is get the innerHTML (text) from an element: var stuff = $('css').html(); expect(stuff).toBe("Inner HTML Text here"); I verified that the $().html() yields the text i desire on the console, what is wrong with my expect statement? TypeError:...

Using Teamcity to deploy css into git repository

I have a git repository set up for our angular project. The styling for the website is being worked on by a separate front end team who will be checking in their work to a TFVC repository in TFS. We are using Teamcity for CI. I would like to be...

Stubbing an angular service with a function that returns a promise using sinon

I'm trying to test a controller that calls a method on a service. The service method returns a promise, and the controller immediately invokes .then() inline after calling the service method. I'm trying to stub the service using sinon and Jasmine keeps throwing an error saying that then is undefined...

jasmine spyOn on javascript new Date

I am unit testing the my client code in angulajs and i understand this code means var newdate = new Date(2013,6,29); spyOn(Date.prototype, 'getTime').and.callFake(function() { return newdate; }); we mockout the getTime() methode of the Date object. but i want to mock out the new Date() instead. for example the code...

How to use Jasmine and CucumberJS with Protractor

I'm looking to use Protractor, CucumberJS, and Jasmine for testing my project. How do I use both Jasmine and CucumberJS with Protractor? Here's the project setup I've created: /path/to/myproj/protractor.conf.js exports.config = { seleniumServerJar: 'node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar', specs: [ 'features/*.feature' ], baseUrl: 'http://localhost:8080', multiCapabilities: [ { 'browserName': 'chrome' } ], allScriptsTimeout: 380000, getPageTimeout:...

How to define WIX agent requirment in TeamCity?

I have add a WIX installer project to solution in Visual Studio 2013. The project is built with every commit on TeamCity. There are several build agents connected to TeamCity cloud, but only some have WIX installed. Usually I would add the build agent requirement, so only the computer with...

Pass on branch name to a script in teamcity

I have a python script that runs as build step in teamcity 9.0. Now I need to know the branch name from which the build is triggered. I could use %teamcity.build.branch% to get the branch name. But I need it to be passed on to my script so that I...

adding a utility namespace in JasmineJS

I'm starting to modify a JasmineJS test suite, and there are some logging calls I want to clean up. Specifically I want to add a utilities.js file in the directory of the test spec... and reference it throughout all my test specs. There are now two test specs testSuite1.spec.js and...

Team city template missing

I was going to reuse teamcity configuration to new environments. Looks like the configuration is based on a template, but actually there is no clickable link to teamplate and I can't find it in the root project. I was thinking that the template was deleted but team city doen't allow...

Javascript Regex: “Any word” pattern

In a Jasmine test, I am trying to set this match to fit with expressions like: 'Request <any_word> for <any_word> - Open actions menu'. However, it's not being possible with this line, but Javascript doc says that \\w is the regex for any word: expect(item.getIconToolTip()).toMatch('Request \\w for \\w - Open...

Testing client side javascript code with Jasmine

I have javascript code that looks like this: this.ProgressBarUpdater = { poll: function() { setInterval(ProgressBarUpdater.request, 5000); }, request: function() { $(".progress_bar_updater[data-url]").each(function(i, elem) { url = $(elem).data("url"); $.getJSON(url, function(data) { if (isFinished(data)) { location.reload(); }; $.each(data, function(key, val) { updateProgressBar(key, val); }); }); }); } }; isFinished = function(obj) { var...

Order of independent Build Configs in TeamCity

I'm migrating our build system over to TeamCity and, because we have quite long build times, I'm trying to make good use of parallelism in build configurations. If two configs can run in parallel they are obviously not dependent on each other. However there are some cases where, if two...

Setting global variables in jasmine for angularjs

I have an angular application with some global environment variables defined in an env.js file: (function(sp) { 'use strict'; pk.env = pk.env || {}; // localhost pk.env.baseUrl = 'http://localhost:8080/'; })(typeof exports === 'undefined' ? (this.pk = this.pk || {}) : exports); These variables are used in multiple factories to make...

REST API of Teamcity for initiate a build

Can anybody suggest how TEAMCITY RestAPI can used for trigger a build for a particular project availble in bitbucket/mercurial repository and getting the result of the build ,that is jar/war file .

Why is address undefined in my app?

I have a simple express app: var express = require('express'); var path = require('path'); var app = express(); exports.app = app; var index = require('./routes/index'); app.use(express.static(path.join(__dirname,'client/dist/'))); app.get('/', index.get); function start(){ var port = process.env.PORT || 8080; app.listen(port, function(){ console.log('app is running on port: ' + port); }); }; exports.start =...

Injecting custom factory in jasmine test

I tried to inject a factory to my controller in jasmine test like in AngularJS - unit testing a factory that has dependencies When I $provide a factory in the test, I would expect the controller to use the provided factory. But the console.log still prints 'real value'. I don't...