From 583f5b0abed6ae6130c460b9f158dc02e02ac2be Mon Sep 17 00:00:00 2001 From: David Cormier Date: Tue, 26 Aug 2014 20:17:02 -0400 Subject: [PATCH 01/12] Add necessary files for unit tests setup --- bower.json | 15 +++++++++++++++ package.json | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 bower.json create mode 100644 package.json diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..8557a60 --- /dev/null +++ b/bower.json @@ -0,0 +1,15 @@ +{ + "name": "glowing-bear", + "description": "A webclient for WeeChat", + "version": "0.4.0", + "homepage": "https://github.com/glowing-bear/glowing-bear", + "license": "GPLv3", + "private": true, + "dependencies": { + "angular": "1.3.x", + "angular-route": "1.3.x", + "angular-loader": "1.3.x", + "angular-mocks": "~1.3.x", + "html5-boilerplate": "~4.3.0" + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..81d8608 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "glowing-bear", + "private": true, + "version": "0.4.0", + "description": "A web client for Weechat", + "repository": "https://github.com/glowing-bear/glowing-bear", + "license": "GPLv3", + "devDependencies": { + "karma": "~0.10", + "protractor": "~0.20.1", + "http-server": "^0.6.1", + "bower": "^1.3.1", + "shelljs": "^0.2.6", + "jshint": "^2.5.2", + "karma-junit-reporter": "^0.2.2" + }, + "scripts": { + "postinstall": "bower install", + + "prestart": "npm install", + "start": "http-server -a localhost -p 8000", + + "pretest": "npm install", + "test": "karma start test/karma.conf.js", + "test-single-run": "karma start test/karma.conf.js --single-run", + + "preupdate-webdriver": "npm install", + "update-webdriver": "webdriver-manager update", + + "update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/@@NG_LOADER_START@@[\\s\\S]*\\/\\/@@NG_LOADER_END@@/, '//@@NG_LOADER_START@@\\n' + cat('app/bower_components/angular-loader/angular-loader.min.js') + '\\n//@@NG_LOADER_END@@', 'app/index-async.html');\"" + } +} From 341fa9f616a9e05cb64c09d9407b691d2610da47 Mon Sep 17 00:00:00 2001 From: David Cormier Date: Sat, 2 Aug 2014 11:46:19 -0400 Subject: [PATCH 02/12] Add unit test setup files and sample plugin unit test --- test/karma.conf.js | 34 ++++++++++++++++++++++++++++++++++ test/unit/plugins.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 test/karma.conf.js create mode 100644 test/unit/plugins.js diff --git a/test/karma.conf.js b/test/karma.conf.js new file mode 100644 index 0000000..379b976 --- /dev/null +++ b/test/karma.conf.js @@ -0,0 +1,34 @@ +module.exports = function(config){ + config.set({ + + basePath : '../', + + files : [ + 'bower_components/angular/angular.js', + 'bower_components/angular-route/angular-route.js', + 'bower_components/angular-mocks/angular-mocks.js', + 'js/**/*.js', + 'test/unit/**/*.js' + ], + + autoWatch : true, + + frameworks: ['jasmine'], + + browsers : ['PhantomJS'], + + singleRun: true, + + plugins : [ + 'karma-phantomjs-launcher', + 'karma-jasmine', + 'karma-junit-reporter' + ], + + junitReporter : { + outputFile: 'test_out/unit.xml', + suite: 'unit' + } + + }); +}; diff --git a/test/unit/plugins.js b/test/unit/plugins.js new file mode 100644 index 0000000..3f35d69 --- /dev/null +++ b/test/unit/plugins.js @@ -0,0 +1,29 @@ +/* plugins go here */ + +var msg = function(msg) { + return {'text': msg } +} + +var metadata_name = function(message) { + return message['metadata'][0]['name'] +} + +describe('filter', function() { + beforeEach(module('plugins')); + + + describe('Plugins', function() { + beforeEach(module(function($provide) { + $provide.value('version', 'TEST_VER'); + })); + + + it('should recognize youtube videos', inject(function(plugins) { + expect( + metadata_name( + plugins.PluginManager.contentForMessage(msg('https://www.youtube.com/watch?v=dQw4w9WgXcQ')) + ) + ).toEqual('YouTube video'); + })); + }); +}); From 9da4ece76d934eadc0f09cc5119c0f4c0744525b Mon Sep 17 00:00:00 2001 From: David Cormier Date: Sat, 2 Aug 2014 11:52:44 -0400 Subject: [PATCH 03/12] Add instructions on how to run the tests --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 9798c44..789b2a9 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ FAQ Development ----------- +Setup +^^^^^ Getting started with the development of Glowing Bear is really simple, partly because we don't have a build process (pure client-side JS, remember). All you have to do is clone the repository, fire up a webserver to host the files, and start fiddling around. You can try out your changes by reloading the page. Here's a simple example using the python simple web server: @@ -58,6 +60,19 @@ If you'd prefer a version hosted with HTTPS, GitHub serves that as well with an You can also use the latest and greatest development version of Glowing Bear at [https://latest.glowing-bear.org/](https://latest.glowing-bear.org/). +Running the tests +^^^^^^^^^^^^^^^^^ +Glowing Bear uses Karma and Jasmine to run its unit tests. To run the tests locally, you will first need to install `npm` and `bower` on your machine. + +Once this is done, you will need to retrieve the necessary packages for testing Glowing-Bear: + +`$ npm install` + +Finally, you can run the tests: + +`$ npm test` + + Contributing ------------ From b16e9536f08cf8116ea56e3c0f40dc7b88f6d387 Mon Sep 17 00:00:00 2001 From: David Cormier Date: Tue, 26 Aug 2014 20:15:13 -0400 Subject: [PATCH 04/12] Make travis run the tests --- .travis.yml | 4 ++-- run_tests.sh | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 run_tests.sh diff --git a/.travis.yml b/.travis.yml index 4fee055..1f369fd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: node_js node_js: - "0.10" -install: "npm -g install jshint" -script: "jshint js/*" +install: "npm install" +script: "sh -e run_tests.sh" notifications: email: false irc: diff --git a/run_tests.sh b/run_tests.sh new file mode 100644 index 0000000..da07a28 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,2 @@ +./node_modules/.bin/jshint js/* +npm test From 4c3d481447f55fa7446f91e65d081affb5ed00c2 Mon Sep 17 00:00:00 2001 From: David Cormier Date: Sat, 2 Aug 2014 23:48:09 -0400 Subject: [PATCH 05/12] Add tests for all plugins --- test/unit/plugins.js | 99 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 6 deletions(-) diff --git a/test/unit/plugins.js b/test/unit/plugins.js index 3f35d69..c7533dc 100644 --- a/test/unit/plugins.js +++ b/test/unit/plugins.js @@ -8,22 +8,109 @@ var metadata_name = function(message) { return message['metadata'][0]['name'] } +var expectTheseMessagesToContain = function(urls, pluginType, plugins) { + for (var i = 0; i < urls.length; i++) { + expect( + metadata_name( + plugins.PluginManager.contentForMessage(msg(urls[i])) + ) + ).toEqual(pluginType); + } +} + describe('filter', function() { beforeEach(module('plugins')); - describe('Plugins', function() { beforeEach(module(function($provide) { $provide.value('version', 'TEST_VER'); })); + it('should recognize spotify tracks', inject(function(plugins) { + expectTheseMessagesToContain([ + 'https://spotify:track:3AAAAAAAAAAAAAAAAAAAAA', + 'https://open.spotify.com/track/3AAAAAAAAAAAAAAAAAAAAA' + ], + 'Spotify track', + plugins); + })); + it('should recognize youtube videos', inject(function(plugins) { - expect( - metadata_name( - plugins.PluginManager.contentForMessage(msg('https://www.youtube.com/watch?v=dQw4w9WgXcQ')) - ) - ).toEqual('YouTube video'); + expectTheseMessagesToContain([ + 'https://www.youtube.com/watch?v=dQw4w9WgXcQ', + 'http://www.youtube.com/watch?v=dQw4w9WgXcQ', + 'http://youtu.be/J6vIS8jb6Fs', + 'https://youtu.be/J6vIS8jb6Fs', + 'http://www.youtube.com/embed?v=dQw4w9WgXcQ', + 'https://www.youtube.com/embed?v=dQw4w9WgXcQ' + ], + 'YouTube video', + plugins); + })); + + it('should recognize dailymotion videos', inject(function(plugins) { + expectTheseMessagesToContain([ + 'dailymotion.com/video/test', + 'dailymotion.com/video/#video=asdf', + 'dai.ly/sfg' + ], + 'Dailymotion video', + plugins); + })); + + it('should recognize allocine videos', inject(function(plugins) { + expectTheseMessagesToContain([ + 'allocine.fr/videokast/video-12', + 'allocine.fr/cmedia=234' + ], + 'AlloCine video', + plugins); + })); + + it('should recognize images', inject(function(plugins) { + expectTheseMessagesToContain([ + 'http://test.png', + 'https://test.jpg', + 'https://test.jpeg', + 'https://test.gif', + ], + 'image', + plugins); + })); + + it('should recognize cloud music', inject(function(plugins) { + expectTheseMessagesToContain([ + 'http://soundcloud.com/', + 'https://sadf.mixcloud.com/', + ], + 'cloud music', + plugins); + })); + + it('should recognize google map', inject(function(plugins) { + expectTheseMessagesToContain([ + 'https://www.google.com/maps/@48.0034139,-74.9129088,6z', + ], + 'Google Map', + plugins); })); + + it('should recognize google map', inject(function(plugins) { + expectTheseMessagesToContain([ + 'https://asciinema.org/a/10625', + ], + 'ascii cast', + plugins); + })); + + it('should recognize meteograms', inject(function(plugins) { + expectTheseMessagesToContain([ + 'http://www.yr.no/sted/Canada/Quebec/Montreal/', + ], + 'meteogram', + plugins); + })); + }); }); From f2bfb3444e78fd939698f230c801d38dcbb83d71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Sat, 9 Aug 2014 13:54:11 +0100 Subject: [PATCH 06/12] Documentation; make test file executable, jshint tests, add a gitignore --- .gitignore | 2 ++ README.md | 4 ++-- run_tests.sh | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 .gitignore mode change 100644 => 100755 run_tests.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c346b13 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +bower_components/ +node_modules/ diff --git a/README.md b/README.md index 789b2a9..f19d5f5 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,9 @@ You can also use the latest and greatest development version of Glowing Bear at Running the tests ^^^^^^^^^^^^^^^^^ -Glowing Bear uses Karma and Jasmine to run its unit tests. To run the tests locally, you will first need to install `npm` and `bower` on your machine. +Glowing Bear uses Karma and Jasmine to run its unit tests. To run the tests locally, you will first need to install `npm` on your machine. Check out the wonderful [nvm](https://github.com/creationix/nvm) if you don't know it already, it's highly recommended. -Once this is done, you will need to retrieve the necessary packages for testing Glowing-Bear: +Once this is done, you will need to retrieve the necessary packages for testing Glowing-Bear (first, you might want to use `npm link` on any packages you have already installed globally): `$ npm install` diff --git a/run_tests.sh b/run_tests.sh old mode 100644 new mode 100755 index da07a28..7ae7475 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,2 +1,2 @@ -./node_modules/.bin/jshint js/* +./node_modules/.bin/jshint js/*.js test/unit/*.js npm test From 230e33136c6434292e7c5ca56c49fe55236f14cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Sat, 9 Aug 2014 13:54:18 +0100 Subject: [PATCH 07/12] Don't fail failed tests by accessing undefined members If a plugin didn't recognize something it should have recognized, don't fail in checking whether it failed. Also, semicolons. --- test/unit/plugins.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/unit/plugins.js b/test/unit/plugins.js index c7533dc..9ca41d0 100644 --- a/test/unit/plugins.js +++ b/test/unit/plugins.js @@ -1,12 +1,15 @@ /* plugins go here */ var msg = function(msg) { - return {'text': msg } -} + return {'text': msg }; +}; var metadata_name = function(message) { - return message['metadata'][0]['name'] -} + if (message.metadata && message.metadata[0] && message.metadata[0].name) { + return message.metadata[0].name; + } + return null; +}; var expectTheseMessagesToContain = function(urls, pluginType, plugins) { for (var i = 0; i < urls.length; i++) { @@ -16,7 +19,7 @@ var expectTheseMessagesToContain = function(urls, pluginType, plugins) { ) ).toEqual(pluginType); } -} +}; describe('filter', function() { beforeEach(module('plugins')); From a46df4baab7e6015395ac20798c326cca664810a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Sat, 9 Aug 2014 14:06:34 +0100 Subject: [PATCH 08/12] Use valid test URLs --- test/unit/plugins.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/test/unit/plugins.js b/test/unit/plugins.js index 9ca41d0..59e4364 100644 --- a/test/unit/plugins.js +++ b/test/unit/plugins.js @@ -31,8 +31,8 @@ describe('filter', function() { it('should recognize spotify tracks', inject(function(plugins) { expectTheseMessagesToContain([ - 'https://spotify:track:3AAAAAAAAAAAAAAAAAAAAA', - 'https://open.spotify.com/track/3AAAAAAAAAAAAAAAAAAAAA' + 'spotify:track:6JEK0CvvjDjjMUBFoXShNZ', + 'https://open.spotify.com/track/6JEK0CvvjDjjMUBFoXShNZ' ], 'Spotify track', plugins); @@ -45,8 +45,9 @@ describe('filter', function() { 'http://www.youtube.com/watch?v=dQw4w9WgXcQ', 'http://youtu.be/J6vIS8jb6Fs', 'https://youtu.be/J6vIS8jb6Fs', - 'http://www.youtube.com/embed?v=dQw4w9WgXcQ', - 'https://www.youtube.com/embed?v=dQw4w9WgXcQ' + 'http://www.youtube.com/embed/dQw4w9WgXcQ', + 'https://www.youtube.com/embed/dQw4w9WgXcQ', + 'youtu.be/dQw4w9WgXcQ' ], 'YouTube video', plugins); @@ -73,10 +74,11 @@ describe('filter', function() { it('should recognize images', inject(function(plugins) { expectTheseMessagesToContain([ - 'http://test.png', - 'https://test.jpg', - 'https://test.jpeg', - 'https://test.gif', + 'http://i.imgur.com/BTNIDBR.gif', + 'https://i.imgur.com/1LmDmct.jpg', + 'http://i.imgur.com/r4FKrnu.jpeg', + 'https://4z2.de/gb-mobile-new.png', + 'http://static.weechat.org/images/screenshots/relay/medium/glowing-bear.png', ], 'image', plugins); From 6d36bf1c829a331c29c7e244f1643d0a377210b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Sat, 9 Aug 2014 14:41:55 +0100 Subject: [PATCH 09/12] Add tests for Gist & Tweet plugins --- test/unit/plugins.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/unit/plugins.js b/test/unit/plugins.js index 59e4364..d515c18 100644 --- a/test/unit/plugins.js +++ b/test/unit/plugins.js @@ -117,5 +117,22 @@ describe('filter', function() { plugins); })); + it('should recognize gists', inject(function(plugins) { + expectTheseMessagesToContain([ + 'https://gist.github.com/lorenzhs/e8c1a7d56fa170320eb8', + 'https://gist.github.com/e8c1a7d56fa170320eb8', + ], + 'Gist', + plugins); + })); + + it('should recognize tweets', inject(function(plugins) { + expectTheseMessagesToContain([ + 'https://twitter.com/DFB_Team_EN/statuses/488436782959448065', + ], + 'Tweet', + plugins); + })); + }); }); From 92282e3a9315197bed41a96ff45fcce9dbf39c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCbschle-Schneider?= Date: Mon, 18 Aug 2014 16:43:55 +0100 Subject: [PATCH 10/12] Test images with GET parameters as well (#414) --- test/unit/plugins.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/unit/plugins.js b/test/unit/plugins.js index d515c18..774e724 100644 --- a/test/unit/plugins.js +++ b/test/unit/plugins.js @@ -79,6 +79,8 @@ describe('filter', function() { 'http://i.imgur.com/r4FKrnu.jpeg', 'https://4z2.de/gb-mobile-new.png', 'http://static.weechat.org/images/screenshots/relay/medium/glowing-bear.png', + 'http://foo.bar/baz.php?img=trololo.png&dummy=yes', + 'https://tro.lo.lo/images/rick.png?size=123x45' ], 'image', plugins); From f1d36c1f9668d3a3fac0b44d544654af866c6e2e Mon Sep 17 00:00:00 2001 From: David Cormier Date: Tue, 26 Aug 2014 19:47:38 -0400 Subject: [PATCH 11/12] Setup end to end testing Add necessary targets in the package.json file and update test instructions --- README.md | 5 ++++- package.json | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f19d5f5..424f8d8 100644 --- a/README.md +++ b/README.md @@ -68,10 +68,13 @@ Once this is done, you will need to retrieve the necessary packages for testing `$ npm install` -Finally, you can run the tests: +Finally, you can run the unit tests: `$ npm test` +Or the end to end tests: +`$ npm run protractor` + Contributing ------------ diff --git a/package.json b/package.json index 81d8608..536fd28 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,9 @@ "preupdate-webdriver": "npm install", "update-webdriver": "webdriver-manager update", + "preprotractor": "npm run update-webdriver", + "protractor": "protractor test/protractor-conf.js", + "update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/@@NG_LOADER_START@@[\\s\\S]*\\/\\/@@NG_LOADER_END@@/, '//@@NG_LOADER_START@@\\n' + cat('app/bower_components/angular-loader/angular-loader.min.js') + '\\n//@@NG_LOADER_END@@', 'app/index-async.html');\"" } } From 9675909ab5612a6612b4ac70d010252c6b73c301 Mon Sep 17 00:00:00 2001 From: David Cormier Date: Tue, 26 Aug 2014 20:01:47 -0400 Subject: [PATCH 12/12] Add sample E2E test --- test/e2e/scenarios.js | 26 ++++++++++++++++++++++++++ test/protractor-conf.js | 19 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test/e2e/scenarios.js create mode 100644 test/protractor-conf.js diff --git a/test/e2e/scenarios.js b/test/e2e/scenarios.js new file mode 100644 index 0000000..a1efb07 --- /dev/null +++ b/test/e2e/scenarios.js @@ -0,0 +1,26 @@ +'use strict'; + +/* https://github.com/angular/protractor/blob/master/docs/getting-started.md */ + +describe('Auth', function() { + + browser.get('index.html'); + var ptor = protractor.getInstance(); + it('auth should fail when trying to connect to an unused port', function() { + var host = ptor.findElement(protractor.By.model('host')); + var password = ptor.findElement(protractor.By.model('password')); + var port = ptor.findElement(protractor.By.model('port')); + var submit = ptor.findElement(protractor.By.tagName('button')); + // Fill out the form? + host.sendKeys('localhost'); + password.sendKeys('password'); + port.sendKeys(2462); + submit.click(); + + var error = ptor.findElement( + protractor.By.css('.alert.alert-danger > strong') + ) + + expect(error.getText()).toBeDefined(); + }); +}); diff --git a/test/protractor-conf.js b/test/protractor-conf.js new file mode 100644 index 0000000..d5bf372 --- /dev/null +++ b/test/protractor-conf.js @@ -0,0 +1,19 @@ +exports.config = { + allScriptsTimeout: 11000, + + specs: [ + 'e2e/*.js' + ], + + capabilities: { + 'browserName': 'firefox' + }, + + baseUrl: 'http://localhost:8000/', + + framework: 'jasmine', + + jasmineNodeOpts: { + defaultTimeoutInterval: 30000 + } +};