From c4b8c00b16c37528d9c46919cd0ecec9a04ab5e4 Mon Sep 17 00:00:00 2001 From: Alan Friedman Date: Tue, 23 Feb 2016 15:52:05 -0500 Subject: [PATCH 1/2] Add zombie.js tests --- gulpfile.babel.js | 4 +-- package.json | 4 ++- test/app.js | 75 +++++++++++++++++++++++++++++++++++++++++++++++ test/helpers.js | 50 +++++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 test/helpers.js diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 19130e2..c122946 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -25,7 +25,7 @@ gulp.task('start', function() { nodemon({ script: 'index.js', ext: 'css js mustache', - ignore: ['src/public/main.js'], + ignore: ['src/public/main.js', 'test'], env: { 'NODE_ENV': 'development' }, @@ -35,7 +35,7 @@ gulp.task('start', function() { gulp.task('test', function() { let test = spawn( - 'mocha', + 'node_modules/mocha/bin/mocha', ['test', '--compilers', 'js:babel-core/register'], {stdio: 'inherit'} ); diff --git a/package.json b/package.json index f9b9512..c56ced5 100644 --- a/package.json +++ b/package.json @@ -27,10 +27,12 @@ "gulp-nodemon": "^2.0.6", "jscs": "^2.10.1", "jshint": "^2.9.1", + "mocha": "^2.4.5", "mocha-jscs": "^4.2.0", "mocha-jshint": "^2.3.1", "vinyl-buffer": "^1.0.0", - "vinyl-source-stream": "^1.1.0" + "vinyl-source-stream": "^1.1.0", + "zombie": "^4.2.1" }, "author": "Daniel Seripap", "license": "MIT" diff --git a/test/app.js b/test/app.js index 3da3280..afbd0cf 100644 --- a/test/app.js +++ b/test/app.js @@ -1,5 +1,80 @@ +import helpers from './helpers'; +import app from '../index'; import mochaJSCS from 'mocha-jscs'; import mochaJSHint from 'mocha-jshint'; +const Browser = require('zombie'); +Browser.localhost('localhost', 3000); + mochaJSCS(); mochaJSHint(); + +describe('Visiting /', () => { + + const browser = new Browser(); + + before((done) => { + browser.on('active', () => { + // browser.evaluate needs a string, so this regex just extracts the body of the function as a string + browser.evaluate(helpers.polyfillCrypto.toString().match(/function[^{]+\{([\s\S]*)\}$/)[1]); + }); + + browser.visit('/', done); + }); + + it('should be successful', () => { + browser.assert.success(); + }); + + it('should show welcome modal', () => { + browser.assert.evaluate('$("#first-modal:visible").length', 1); + browser.assert.text('#first-modal h4.modal-title', 'Welcome to darkwire.io'); + }); + + describe('closing the initial modal', () => { + + before((done) => { + browser.pressButton('#first-modal .modal-footer button', done); + }); + + it('should close the modal and show the main chat page', () => { + browser.assert.evaluate('$("#first-modal:hidden").length', 1); + }); + + describe('opening another tab', () => { + + before((done) => { + let roomIdSplit = browser.url.split('/'); + let roomId = roomIdSplit[roomIdSplit.length - 1]; + browser.open(); + browser.tabs.current = 1; + browser.visit(`/${roomId}`, done); + }); + + it('should be successful', () => { + browser.assert.success(); + }); + + it('should not show welcome modal', () => { + browser.assert.evaluate('$("#first-modal.fade.in").length', 0); + }); + + describe('sending message', () => { + + before((done) => { + browser.fill('.inputMessage', 'Hello world'); + browser.click('span#send-message-btn', done); + }); + + it('should send message', () => { + browser.tabs.current = 0; + browser.assert.text('body', /Hello world/); + }); + + }); + + }); + + }); + +}); diff --git a/test/helpers.js b/test/helpers.js new file mode 100644 index 0000000..e752691 --- /dev/null +++ b/test/helpers.js @@ -0,0 +1,50 @@ +var helpers = { + polyfillCrypto: () => { + window.crypto = { + subtle: { + generateKey: () => { + return new Promise((resolve, reject) => { + resolve({}); + }); + }, + exportKey: () => { + return new Promise((resolve, reject) => { + resolve([{}]); + }); + }, + importKey: () => { + return new Promise((resolve, reject) => { + resolve([{}]); + }); + }, + encrypt: () => { + return {}; + }, + decrypt: (opts, key, data) => { + if (opts.name === 'AES-CBC') { + // This means it's decrypted a message + return new Promise((resolve, reject) => { + // "Hello world" as an array buffer + resolve(new Uint8Array([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])); + }); + } else { + return new Promise((resolve, reject) => { + resolve({}); + }); + } + }, + sign: () => { + return {}; + }, + verify: () => { + return true; + } + }, + getRandomValues: () => { + return [1,2,3,4]; + } + }; + } +}; + +module.exports = helpers; From 885a74b1e64b5c13613d91061a3e4ccaae813fbe Mon Sep 17 00:00:00 2001 From: Alan Friedman Date: Tue, 23 Feb 2016 15:57:15 -0500 Subject: [PATCH 2/2] Add Travis yml file --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e6673cf --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: node_js +node_js: + - 5.2.0 +before_script: + - gulp bundle + - sleep 5 +script: gulp test \ No newline at end of file