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 --- .gitignore | 1 + .nvmrc | 1 + .travis.yml | 1 + karma.conf.js | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 29 +++++++++++++++++++ spec/helper.js | 4 +++ spec/login_spec.js | 16 ++++++----- spec/signup_spec.js | 2 +- 8 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 .gitignore create mode 100644 .nvmrc create mode 100644 .travis.yml create mode 100644 karma.conf.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..9212624 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v0.12.7 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..587bd3e --- /dev/null +++ b/.travis.yml @@ -0,0 +1 @@ +language: node_js diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..6eec6d9 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,81 @@ +// Karma configuration +// Generated on Tue Sep 15 2015 01:01:08 GMT+0200 (CEST) + +module.exports = function(config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine'], + + + // list of files / patterns to load in the browser + files: [ + // dependencies + 'lib/*.js', + 'node_modules/jquery/dist/jquery.min.js', + + // src + 'src/srp.js', + 'src/*.js', + 'src/jqueryRest.js', + + // devDependencies + 'node_modules/sinon/pkg/sinon.js', + 'node_modules/jasmine-jquery/lib/jasmine-jquery.js', + + // spec + 'spec/spec_helper.js', + 'spec/*.js' + ], + + + // list of files to exclude + exclude: [ + 'spec/lib/jasmine/*.js' + ], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + }, + + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress'], + + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: false, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['PhantomJS'], + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false + }); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..9c3ead0 --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "srp_js", + "version": "0.0.1", + "description": "A secure remote password implementation for JavaScript", + "homepage": "https://github.com/leapcode/srp_js#readme", + "main": "index.js", + "devDependencies": { + "jasmine-core": "^2.3.4", + "jasmine-jquery": "^2.1.0", + "jquery": "^2.1.4", + "karma": "^0.13.9", + "karma-jasmine": "^0.3.6", + "karma-phantomjs-launcher": "^0.2.1", + "phantomjs": "^1.9.18", + "sinon": "^1.16.1" + }, + "scripts": { + "test": "node_modules/karma/bin/karma start --single-run" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/leapcode/srp_js.git" + }, + "author": "LEAP contributors", + "license": "BSD-3-Clause", + "bugs": { + "url": "https://github.com/leapcode/srp_js/issues" + } +} 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