From dacd2f218a3774bd200f17c7e9274088043a25ef Mon Sep 17 00:00:00 2001 From: kaeff Date: Wed, 16 Sep 2015 02:12:50 +0200 Subject: Run tests via cli using karma & PhantomJS for Travis Instead of jasmine's HTML runner, use karma to run specs. karma & all other dependencies are installed via npm and executed via node.js. This allows TravisCI to execute the test, and as a side effect, bumps the versions on the testing toolchain. - Install node.js - Run `npm install` once to download dependencies. - Run `npm test` to run all tests Things to bear in mind: - This commit adds general project information in `package.js` - `karma.conf.js` specifies the order in which src, spec and lib files are loaded - Switch to jasmine spies instead of sinon --- spec/helper.js | 4 ++++ spec/login_spec.js | 16 +++++++++------- spec/signup_spec.js | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'spec') diff --git a/spec/helper.js b/spec/helper.js index 8bae2c6..d1c699b 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -42,3 +42,7 @@ var specHelper = (function() { } })(); + +beforeEach(function () { + setFixtures("
Username:
Password:
"); +}); diff --git a/spec/login_spec.js b/spec/login_spec.js index 461a4bb..24c7f4f 100644 --- a/spec/login_spec.js +++ b/spec/login_spec.js @@ -42,6 +42,10 @@ describe("Login with srp var", function() { beforeEach(function() { specHelper.setupFakeXHR.apply(this); + calculate = new srp.Calculate(); + calculate.randomSalt = function() {return "4c78c3f8"}; + srp.session = new srp.Session(undefined, calculate); + A_ = srp.session.calculateAndSetA(data.a) old_login = $('#srp_username').val(); old_conf = $('#srp_password_confirmation').val(); @@ -68,7 +72,7 @@ describe("Login with srp var", function() { }); it("authenticates successfully", function(){ - srp.loggedIn = sinon.spy(); + srp.loggedIn = jasmine.createSpy(); srp.login(); this.expectRequest('/1/sessions.json', 'login=' +data.username+ '&A=' +data.aa, 'POST'); @@ -80,7 +84,7 @@ describe("Login with srp var", function() { }); it("reports errors during handshake", function(){ - srp.error = sinon.spy(); + srp.error = jasmine.createSpy(); var error = {login: "something went wrong on the server side"}; srp.login(); @@ -88,14 +92,12 @@ describe("Login with srp var", function() { this.respondJSON(error, 422); //this.expectNoMoreRequests(); - expect(srp.error).toHaveBeenCalled; - var args = srp.error.args[0]; - expect(args[0]).toEqual(error); + expect(srp.error).toHaveBeenCalledWith(error); }); it("rejects B = 0", function(){ - srp.loggedIn = sinon.spy(); - srp.error = sinon.spy(); + srp.loggedIn = jasmine.createSpy(); + srp.error = jasmine.createSpy(); srp.login(); this.expectRequest('/1/sessions.json', 'login=' +data.username+ '&A=' +data.aa, 'POST'); diff --git a/spec/signup_spec.js b/spec/signup_spec.js index 0bd8d48..89b0936 100644 --- a/spec/signup_spec.js +++ b/spec/signup_spec.js @@ -19,7 +19,7 @@ describe("Signup with srp var", function() { }); it("identifies after successful registration (INTEGRATION)", function(){ - var callback = sinon.spy(); + var callback = jasmine.createSpy(); srp.signedUp = callback; srp.signup(); this.expectRequest('/1/users.json', "user[login]=testuser&user[password_salt]=4c78c3f8&user[password_verifier]=474c26aa42d11f20544a00f7bf9711c4b5cf7aab95ed448df82b95521b96668e7480b16efce81c861870302560ddf6604c67df54f1d04b99d5bb9d0f02c6051ada5dc9d594f0d4314e12f876cfca3dcd99fc9c98c2e6a5e04298b11061fb8549a22cde0564e91514080df79bca1c38c682214d65d590f66b3719f954b078b83c", 'POST') -- cgit v1.2.3