Skip to content

Commit

Permalink
add test suite and fixes JSteunou#3
Browse files Browse the repository at this point in the history
  • Loading branch information
yeyu456 committed Jun 9, 2016
1 parent 693b5d8 commit ba9de99
Show file tree
Hide file tree
Showing 11 changed files with 960 additions and 14 deletions.
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: node_js
node_js:
- "6"
- "5"
branches:
only:
- master
env :
- BROWSSER=chromium_browser
addons:
firefox: 'latest'
cache:
directories:
- node_modules
before_script:
- npm install -g gulp
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- sleep 3 # give xvfb some time to start
script: gulp test
after_success:
- gulp coverage
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# webstomp-client
[![Build Status](https://travis-ci.org/yeyu456/webstomp-client.svg?branch=master)](https://travis-ci.org/yeyu456/webstomp-client)
[![Coverage Status](https://coveralls.io/repos/github/yeyu456/webstomp-client/badge.svg?branch=master)](https://coveralls.io/github/yeyu456/webstomp-client?branch=master)

This library provides a [stomp](https://stomp.github.io/) client for Web browsers and nodejs through Web Sockets.

Expand Down
66 changes: 66 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
'use strict';

var gulp = require('gulp');
var webpack = require('webpack');
var del = require('del');
var karma = require('karma').Server;
var spawn = require('child_process').spawn;
var coveralls = require('gulp-coveralls');
var node;

gulp.task('clean', function(cb) {
del.sync(['./dist/*']);
cb();
});

gulp.task('testServer', ['clean'], function _testServer(cb) {
if (node) {
node.kill();
}
webpack({
entry: './test/support/server-mock.js',
output: {
path: __dirname + '/dist/support',
filename: 'server-mock.js'
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
}
]
},
target: 'node',
resolve: {
extensions: ['', '.js']
}
}, function(err) {
if (err) {
cb(err);

} else {
node = spawn('node', ['./dist/support/server-mock.js'], {stdio: 'inherit'});
cb();
}
});
});

gulp.task('test', ['testServer'], function _test(cb) {
// jscs:disable requireCapitalizedConstructors
return new karma({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, function _testCB(code) {
if (node) {
node.kill();
}
cb(code);
}).start();
});

gulp.task('coverage', function _coverage(cb) {
return gulp.src('dist/coverage/*/coverage.info')
.pipe(coveralls());
});
113 changes: 113 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Karma configuration
// Generated on Sat Jun 04 2016 17:41:44 GMT+0800 (中国标准时间)
var webpack = require('karma-webpack');

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: ['mocha'],
// list of files / patterns to load in the browser
files: [
'node_modules/core-js/client/core.js',
'test/utils-test.js',
'test/frame-test.js',
'test/webstomp-test.js',
'test/client-test.js'
],
plugins: [
webpack,
'karma-mocha',
'karma-firefox-launcher',
'karma-chrome-launcher',
'karma-ie-launcher',
'karma-coverage'
],
// list of files to exclude
exclude: [],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/*.js': ['webpack'],
'src/**/*.js': ['webpack']
},
webpack: {
module: {
preLoaders: [
{
test: /\.js$/,
loader: 'isparta',
exclude: /(node_modules|test)/
}
],
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['', '.js']
},
externals: {
ws:'WebSocket'
},
debug: true
},
webpackMiddleware: {
noInfo: true
},
reporters: ['progress', 'coverage'],
coverageReporter: {
dir: 'dist/coverage/',
subdir: function(browser) {
return browser.toLowerCase().split(/[ /-]/)[0];
},
reporters: [{
type: 'html',
file: 'coverage.html'
}, {
type: 'lcovonly',
file: 'coverage.info'
}],
watermarks: {
statements: [60, 90],
functions: [60, 90],
branches: [60, 90],
lines: [60, 90]
}
},
// web server port
port: 1110,
// 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: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['IE', 'Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
});
if (process.env.TRAVIS) {
config.customLaunchers = {
Chrome: {
base: 'Chrome',
flags: ['--no-sandbox']
}
};
config.browsers = ['Firefox', 'Chrome'];
}
};
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,26 @@
"jshint": "^2.9.1",
"opn-cli": "^3.1.0",
"webpack": "^1.12.14",
"ws": "^1.0.1"
"isparta-loader": "^2.0.0",
"ws": "^1.0.1",
"sockjs": "^0.3.17",
"sockjs-client": "^1.1.1",
"gulp": "^3.9.1",
"gulp-coveralls": "^0.1.4",
"del": "^2.2.0",
"mocha": "^2.5.3",
"chai": "^3.5.0",
"karma": "^0.13.22",
"karma-mocha": "^1.0.1",
"karma-webpack": "^1.7.0",
"karma-chrome-launcher": "^1.0.1",
"karma-ie-launcher": "^1.0.0",
"karma-firefox-launcher": "^1.0.0",
"karma-coverage": "^1.0.0",
"core-js": "^2.4.0"
},
"scripts": {
"test": "echo \"TODO: add tests\"",
"test": "gulp test",
"build": "webpack && webpack -p --config webpack.min.config.js",
"dev": "webpack --watch",
"example": "webpack && opn http://localhost:8080/example & http-server",
Expand Down
Loading

0 comments on commit ba9de99

Please sign in to comment.