diff --git a/.travis.yml b/.travis.yml index e6673cf..eb25b5f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,25 @@ language: node_js node_js: - 5.2.0 +sudo: required +cache: + directories: + - node_modules +before_install: + - sudo apt-get update + - sudo apt-get install -y libappindicator1 fonts-liberation + - wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb + - sudo dpkg -i google-chrome*.deb + - wget http://chromedriver.storage.googleapis.com/2.21/chromedriver_linux64.zip + - unzip chromedriver_linux64 + - sudo mv chromedriver /usr/bin before_script: + - export CHROME_BIN=/usr/bin/google-chrome + - "export DISPLAY=:99.0" + - "sh -e /etc/init.d/xvfb start" + - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x16" + - sleep 5 # give xvfb some time to start - gulp bundle + - node index.js & - sleep 5 -script: gulp test \ No newline at end of file +script: node_modules/mocha/bin/mocha test/unit --compilers js:babel-core/register && node_modules/nightwatch/bin/nightwatch --test test/acceptance/index.js --config test/acceptance/nightwatch.json -e chrome diff --git a/gulpfile.babel.js b/gulpfile.babel.js index b5686a5..4231a4b 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -45,9 +45,31 @@ gulp.task('start', function() { }); gulp.task('test', function() { - let test = spawn( + let unitTest = spawn( 'node_modules/mocha/bin/mocha', - ['test', '--compilers', 'js:babel-core/register'], + ['test/unit', '--compilers', 'js:babel-core/register'], {stdio: 'inherit'} ); + + unitTest.on('exit', function() { + + // Start app + let app = spawn('node', ['index.js']); + + app.stdout.on('data', function(data) { + console.log(String(data)); + }); + + let acceptanceTest = spawn( + 'node_modules/nightwatch/bin/nightwatch', + ['--test', 'test/acceptance/index.js', '--config', 'test/acceptance/nightwatch.json'], + {stdio: 'inherit'} + ); + + acceptanceTest.on('exit', function() { + // Kill app Node process when tests are done + app.kill(); + }); + }); + }); diff --git a/package.json b/package.json index 24ef79e..53adc9d 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "browserify": "^13.0.0", "compression": "^1.6.0", "express": "^4.13.3", + "forever": "^0.15.1", "gulp": "^3.9.0", "gulp-uglify": "^1.5.1", "moment": "^2.11.2", @@ -33,9 +34,13 @@ "mocha": "^2.4.5", "mocha-jscs": "^4.2.0", "mocha-jshint": "^2.3.1", + "nightwatch": "^0.8.16", "vinyl-buffer": "^1.0.0", - "vinyl-source-stream": "^1.1.0", - "zombie": "^4.2.1" + "vinyl-source-stream": "^1.1.0" + }, + "scripts": { + "dev": "gulp start", + "test": "gulp test" }, "scripts": { "start": "gulp start", diff --git a/test/acceptance/app.js b/test/acceptance/app.js new file mode 100644 index 0000000..0e63b92 --- /dev/null +++ b/test/acceptance/app.js @@ -0,0 +1,90 @@ +describe('Darkwire', () => { + + describe('starting a room', () => { + + let browser; + + before((client, done) => { + browser = client + .url('http://localhost:3000/', () => { + done(); + }); + }); + + after((client, done) => { + browser.end(() => { + done(); + }); + }); + + afterEach((client, done) => { + done(); + }); + + beforeEach((client, done) => { + done(); + }); + + it('should show welcome modal', () => { + browser + .waitForElementVisible('#first-modal', 5000) + .assert.containsText('#first-modal .modal-title', 'Welcome to darkwire.io'); + }); + + it('should have correct header', () => { + browser.expect.element('#first-modal .modal-title').text.to.equal('Welcome to darkwire.io'); + }); + + describe('opening a second window', () => { + + before((client, done) => { + browser.url((result) => { + let urlSplit = result.value.split('/'); + let roomId = urlSplit[urlSplit.length - 1]; + let url = 'http://localhost:3000/' + roomId; + browser.execute(() => { + window.open('http://localhost:3000/', '_blank'); + }, [], () => { + browser.window_handles((result) => { + browser.switchWindow(result.value[1], () => { + browser.execute((id) => { + window.open('http://localhost:3000/' + id, '_self'); + }, [roomId], () => { + done(); + }); + }); + }); + }); + }); + }); + + it('should not show welcome modal', () => { + browser.assert.hidden('#first-modal'); + }); + + describe('sending messages', () => { + + before((client, done) => { + browser.waitForElementPresent('ul.users li:nth-child(2)', 5000, () => { + browser.setValue('input.inputMessage', ['Hello world', browser.Keys.RETURN], () => { + done(); + }); + }); + }); + + it('should work', () => { + browser.window_handles((result) => { + browser.switchWindow(result.value[0], () => { + browser.waitForElementPresent('span.messageBody', 5000, () => { + browser.assert.containsText('span.messageBody', 'Hello world'); + }); + }); + }); + }); + + }); + + }); + + }); +}); diff --git a/test/acceptance/bin/selenium-server-standalone-2.52.0.jar b/test/acceptance/bin/selenium-server-standalone-2.52.0.jar new file mode 100644 index 0000000..f62a462 Binary files /dev/null and b/test/acceptance/bin/selenium-server-standalone-2.52.0.jar differ diff --git a/test/acceptance/index.js b/test/acceptance/index.js new file mode 100644 index 0000000..36104ea --- /dev/null +++ b/test/acceptance/index.js @@ -0,0 +1,2 @@ +require('babel-register')(); +require('./app.js'); diff --git a/test/acceptance/nightwatch.json b/test/acceptance/nightwatch.json new file mode 100644 index 0000000..852be86 --- /dev/null +++ b/test/acceptance/nightwatch.json @@ -0,0 +1,49 @@ +{ + "src_folders" : ["test"], + "output_folder" : "reports", + "custom_commands_path" : "", + "custom_assertions_path" : "", + "page_objects_path" : "", + "globals_path" : "", + "test_runner" : "mocha", + "selenium" : { + "start_process" : true, + "server_path" : "test/acceptance/bin/selenium-server-standalone-2.52.0.jar", + "log_path" : false, + "host" : "127.0.0.1", + "port" : 4444, + "cli_args" : { + "webdriver.chrome.driver" : "/usr/bin/chromedriver", + "webdriver.ie.driver" : "" + } + }, + + "test_settings" : { + "default" : { + "launch_url" : "http://localhost", + "selenium_port" : 4444, + "selenium_host" : "localhost", + "silent": true, + "screenshots" : { + "enabled" : false, + "path" : "" + }, + "desiredCapabilities": { + "browserName": "firefox", + "javascriptEnabled": true, + "acceptSslCerts": true + } + }, + + "chrome" : { + "desiredCapabilities": { + "browserName": "chrome", + "javascriptEnabled": true, + "acceptSslCerts": true, + "chromeOptions" : { + "args" : ["-e", "--no-sandbox"] + } + } + } + } +} diff --git a/test/unit/app.js b/test/unit/app.js new file mode 100644 index 0000000..b40541c --- /dev/null +++ b/test/unit/app.js @@ -0,0 +1,6 @@ +import mochaJSCS from 'mocha-jscs'; +import mochaJSHint from 'mocha-jshint'; + +mochaJSCS(); +mochaJSHint(); +