Merge pull request #424 from glowing-bear/add-e2e-tests

Setup testing
This commit is contained in:
Lorenz Hübschle-Schneider 2014-08-27 17:23:57 +01:00
commit aef707a12f
10 changed files with 293 additions and 2 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
bower_components/
node_modules/

View file

@ -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:

View file

@ -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,22 @@ 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` 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 (first, you might want to use `npm link` on any packages you have already installed globally):
`$ npm install`
Finally, you can run the unit tests:
`$ npm test`
Or the end to end tests:
`$ npm run protractor`
Contributing
------------

15
bower.json Normal file
View file

@ -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"
}
}

35
package.json Normal file
View file

@ -0,0 +1,35 @@
{
"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",
"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');\""
}
}

2
run_tests.sh Executable file
View file

@ -0,0 +1,2 @@
./node_modules/.bin/jshint js/*.js test/unit/*.js
npm test

26
test/e2e/scenarios.js Normal file
View file

@ -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();
});
});

34
test/karma.conf.js Normal file
View file

@ -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'
}
});
};

19
test/protractor-conf.js Normal file
View file

@ -0,0 +1,19 @@
exports.config = {
allScriptsTimeout: 11000,
specs: [
'e2e/*.js'
],
capabilities: {
'browserName': 'firefox'
},
baseUrl: 'http://localhost:8000/',
framework: 'jasmine',
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};

140
test/unit/plugins.js Normal file
View file

@ -0,0 +1,140 @@
/* plugins go here */
var msg = function(msg) {
return {'text': msg };
};
var metadata_name = function(message) {
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++) {
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([
'spotify:track:6JEK0CvvjDjjMUBFoXShNZ',
'https://open.spotify.com/track/6JEK0CvvjDjjMUBFoXShNZ'
],
'Spotify track',
plugins);
}));
it('should recognize youtube videos', inject(function(plugins) {
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/dQw4w9WgXcQ',
'https://www.youtube.com/embed/dQw4w9WgXcQ',
'youtu.be/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://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',
'http://foo.bar/baz.php?img=trololo.png&dummy=yes',
'https://tro.lo.lo/images/rick.png?size=123x45'
],
'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);
}));
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);
}));
});
});