From 4c19f3351b566f9d802a43ec2a5fd6f3a0bd788f Mon Sep 17 00:00:00 2001 From: Dylan Millikin Date: Thu, 7 Apr 2016 23:03:04 +0200 Subject: [PATCH] initial commit for browser and coverage support --- .travis.yml | 8 +- Gulpfile.babel.js | 89 ------------------- karma.conf.js | 79 ++++++++++++++++ package.json | 56 ++++++------ src/.babelrc | 4 - test/GremlinClientTest.js | 25 ++++++ ...{bindForClient.js => bindForClientTest.js} | 0 test/{bindings.js => bindingsTest.js} | 0 ....session.js => buildCommandSessionTest.js} | 0 test/{createClient.js => createClientTest.js} | 0 ...ecute.nashorn.js => executeNashornTest.js} | 0 test/{execute.js => executeTest.js} | 0 ...eTemplateTag.js => makeTemplateTagTest.js} | 0 ...{messageStream.js => messageStreamTest.js} | 0 test/{nashorn.js => nashornTest.js} | 0 test/{stream.js => streamTest.js} | 0 tests.webpack.js | 6 ++ 17 files changed, 141 insertions(+), 126 deletions(-) delete mode 100644 Gulpfile.babel.js create mode 100644 karma.conf.js delete mode 100644 src/.babelrc create mode 100644 test/GremlinClientTest.js rename test/{bindForClient.js => bindForClientTest.js} (100%) rename test/{bindings.js => bindingsTest.js} (100%) rename test/{buildCommand.session.js => buildCommandSessionTest.js} (100%) rename test/{createClient.js => createClientTest.js} (100%) rename test/{execute.nashorn.js => executeNashornTest.js} (100%) rename test/{execute.js => executeTest.js} (100%) rename test/{makeTemplateTag.js => makeTemplateTagTest.js} (100%) rename test/{messageStream.js => messageStreamTest.js} (100%) rename test/{nashorn.js => nashornTest.js} (100%) rename test/{stream.js => streamTest.js} (100%) create mode 100644 tests.webpack.js diff --git a/.travis.yml b/.travis.yml index ef38ed1..565ed61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,9 +18,9 @@ install: - npm install before_script: + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start + - sleep 3 - npm run build -script: npm run test:node - -after_script: - - npm run coverage:travis +script: npm run test:node && npm run test:browser:coverage diff --git a/Gulpfile.babel.js b/Gulpfile.babel.js deleted file mode 100644 index be31669..0000000 --- a/Gulpfile.babel.js +++ /dev/null @@ -1,89 +0,0 @@ -'use strict'; -import gulp from 'gulp'; -import browserify from 'browserify'; -import babelify from 'babelify'; -import source from 'vinyl-source-stream'; - -import buffer from 'gulp-buffer'; -import uglify from 'gulp-uglify'; -import size from 'gulp-size'; -import rename from 'gulp-rename'; -import mocha from 'gulp-mocha'; - -var karma = require('karma').server; -var args = require('yargs').argv; - - -function printError(error) { - console.error('\nError:', error.plugin); - console.error(error.message); -} - -function printEvent(event) { - console.log('File', event.type +':', event.path); -} - - -var bundler; -function getBundler() { - if (!bundler) { - bundler = browserify('./index.js', { - debug: true, - standalone: 'gremlin' - }); - } - return bundler; -} - -gulp.task('build', () => { - return getBundler() - .transform(babelify) - .bundle() - .on('error', function(err) { console.log('Error: ' + err.message); }) - .pipe(source('./gremlin.js')) - .pipe(gulp.dest('./')) - .pipe(buffer()) - .pipe(size({ showFiles: true })) - .pipe(uglify()) - .pipe(rename('gremlin.min.js')) - .pipe(size({ showFiles: true })) - .pipe(gulp.dest('./')); -}); - -gulp.task('test', ['test:node', 'test:browsers']); - -gulp.task('test:node', () => { - return gulp.src('test/**/*') - .pipe(mocha({ - reporter: 'spec', - bail: !!args.bail - })) - .on('error', printError); -}); - -gulp.task('test:browsers', (done) => { - const karmaCommonConf = { - browsers: ['Chrome', 'Firefox', 'Safari'], - frameworks: ['mocha', 'chai', 'browserify'], - preprocessors: { - 'test/*': ['browserify'] - }, - files: [ - 'test/**/*.js' - ], - browserify: { - watch: true // Watches dependencies only (Karma watches the tests) - } - }; - - karma.start(karmaCommonConf, done); -}); - -gulp.task('watch', function() { - gulp.watch(['src/**/*', 'test/**/*', 'index.js'], ['test-node']) - .on('change', printEvent); -}); - -gulp.task('default', ['build']); - -gulp.task('dev', ['test', 'watch']); diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..20b442a --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,79 @@ +var path = require('path'); +module.exports = function (config) { + config.set({ + + basePath: '.', + + frameworks: ['mocha', 'chai', 'sinon'], + singleRun: true, //just run once by default + + files: [ + 'tests.webpack.js', //just load this file instead of individual test files. It will fetch the proper content + ], + preprocessors: { + 'tests.webpack.js': [ 'webpack', 'sourcemap'] //preprocess with webpack and our sourcemap loader + }, + + //~ babelPreprocessor: { + //~ "plugins": [ + //~ "transform-runtime", + //~ ["transform-async-to-module-method", { + //~ "module": "bluebird", + //~ "method": "coroutine" + //~ }] + //~ ] + //~ }, + + webpack: { //kind of a copy of your webpack config + debug:true, + devtool: 'inline-source-map', //just do inline source maps instead of the default + output: { + library: 'gremlin', + libraryTarget: 'umd' + }, + module: { + preLoaders: [ + // instrument only testing sources with Istanbul + { + test: /\.js$/, + include: path.resolve('src/'), + loader: 'isparta' + } + ], + loaders: [ + { test: /\.js$/, exclude: /node_modules/, loader: 'babel' } + ] + } + }, + + reporters: ['mocha', 'coverage', 'coveralls'], + + coverageReporter: { + type: 'lcov', // lcov or lcovonly are required for generating lcov.info files + dir: 'coverage/' + }, + + port: 9876, + colors: true, + autoWatch: false, + singleRun: false, + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + browsers: ['Firefox'], + plugins: [ + 'karma-firefox-launcher', + 'karma-mocha', + 'karma-chai', + 'karma-webpack', + 'karma-sourcemap-loader', + 'karma-mocha-reporter', + 'karma-coverage', + 'karma-coveralls', + 'karma-sinon' + ] + + }); +}; diff --git a/package.json b/package.json index cb4dc46..ec1ba94 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,17 @@ "scripts": { "build": "babel ./src -d lib", "build:umd": "NODE_ENV=production webpack src/index.js umd/gremlin.js", - "build:min": "NODE_ENV=production webpack -p src/index.js umd/gremlin.min.js", + "build:min": "NODE_ENV=production webpack -p src/index.js umd/gremlin.min.js --optimize-occurence-order --optimize-dedupe", "build:watch": "npm run build -- --watch", - "coverage": "babel-node ./node_modules/istanbul/lib/cli.js cover _mocha", - "coverage:travis": "babel-node ./node_modules/istanbul/lib/cli.js cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", "examples:browser": "babel-node examples/server", "examples:node": "babel-node examples/node-example", + "test": "npm run test:node && npm run test:browser", + "test:coverage": "npm run test:node && npm run test:browser:coverage", "test:node": "mocha ./test --compilers js:babel-register --recursive --reporter spec", - "test:node:watch": "npm run test:node -- --watch" + "test:node:watch": "npm run test:node -- --watch", + "test:browser": "karma start karma.conf.js --single-run --reporters mocha", + "test:browser:coverage": "karma start karma.conf.js --single-run", + "test:browser:debug": "karma start karma.conf.js --reporters mocha" }, "repository": { "type": "git", @@ -41,39 +44,34 @@ "ws": "^0.8.0" }, "devDependencies": { - "babel-cli": "^6.4.5", - "babel-core": "^6.4.0", - "babel-loader": "^6.2.1", + "babel-cli": "~6.6.5", + "babel-core": "~6.7.2", + "babel-loader": "~6.2.4", + "babel-preset-es2015": "~6.6.0", + "babel-preset-stage-2": "~6.5.0", + "babel-register": "~6.7.2", "babel-plugin-transform-async-to-module-method": "^6.5.2", "babel-plugin-transform-runtime": "^6.5.2", - "babel-preset-es2015": "^6.3.13", - "babel-preset-stage-2": "^6.3.13", - "babel-register": "^6.3.13", "babelify": "^5.0.4", "bluebird": "^3.3.3", - "browserify": "^9.0.3", - "chai": "^2.1.1", "finalhandler": "^0.1.0", - "gulp": "^3.9.0", - "gulp-buffer": "0.0.2", - "gulp-mocha": "^2.0.0", - "gulp-rename": "^1.2.0", - "gulp-size": "^1.0.0", - "gulp-uglify": "^0.3.1", - "istanbul": "^0.4.2", - "istanbul-coveralls": "^1.0.3", - "karma": "^0.12.31", - "karma-browserify": "^0.2.1", + "chai": "^3.5.0", + "isparta-loader": "^2.0.0", + "sinon": "^1.17.3", + "karma": "^0.13.22", "karma-chai": "^0.1.0", - "karma-chrome-launcher": "^0.1.4", - "karma-firefox-launcher": "^0.1.3", - "karma-mocha": "^0.1.10", - "karma-safari-launcher": "^0.1.1", - "mocha": "^1.21.4", - "mocha-lcov-reporter": "^1.2.0", + "karma-coverage": "^0.5.5", + "karma-coveralls": "^1.1.2", + "karma-firefox-launcher": "^0.1.7", + "karma-mocha": "^0.2.2", + "karma-mocha-reporter": "^2.0.0", + "karma-sinon": "^1.0.4", + "karma-sourcemap-loader": "^0.3.7", + "karma-webpack": "^1.7.0", + "mocha": "^2.4.5", "serve-static": "^1.5.3", "vinyl-source-stream": "^1.0.0", - "webpack": "^1.12.11", + "webpack": "^1.12.14", "yargs": "^1.3.1" } } diff --git a/src/.babelrc b/src/.babelrc deleted file mode 100644 index 73c559e..0000000 --- a/src/.babelrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "presets": ["es2015", "stage-2"], - "sourceMaps": "inline" -} \ No newline at end of file diff --git a/test/GremlinClientTest.js b/test/GremlinClientTest.js new file mode 100644 index 0000000..faa3512 --- /dev/null +++ b/test/GremlinClientTest.js @@ -0,0 +1,25 @@ +import Client from '../src/GremlinClient'; + +describe('GremlinClient', () => { + describe('.construct()', () => { + + it('should allow setting the `port` option', () => { + const client = new Client(8183); + client.on('error', (err) => {}); //catch error + client.port.should.equal(8183); + }); + + it('should allow setting the `host` option', () => { + const client = new Client(8182, "otherhost"); + client.on('error', (err) => {}); //catch error + client.host.should.equal('otherhost'); + }); + + it('should allow setting session option', () => { + const client = new Client(8182, "localhost", {session:true}); + client.port.should.equal(8182); + client.host.should.equal('localhost'); + client.options.session.should.equal(true); + }); + }); +}); diff --git a/test/bindForClient.js b/test/bindForClientTest.js similarity index 100% rename from test/bindForClient.js rename to test/bindForClientTest.js diff --git a/test/bindings.js b/test/bindingsTest.js similarity index 100% rename from test/bindings.js rename to test/bindingsTest.js diff --git a/test/buildCommand.session.js b/test/buildCommandSessionTest.js similarity index 100% rename from test/buildCommand.session.js rename to test/buildCommandSessionTest.js diff --git a/test/createClient.js b/test/createClientTest.js similarity index 100% rename from test/createClient.js rename to test/createClientTest.js diff --git a/test/execute.nashorn.js b/test/executeNashornTest.js similarity index 100% rename from test/execute.nashorn.js rename to test/executeNashornTest.js diff --git a/test/execute.js b/test/executeTest.js similarity index 100% rename from test/execute.js rename to test/executeTest.js diff --git a/test/makeTemplateTag.js b/test/makeTemplateTagTest.js similarity index 100% rename from test/makeTemplateTag.js rename to test/makeTemplateTagTest.js diff --git a/test/messageStream.js b/test/messageStreamTest.js similarity index 100% rename from test/messageStream.js rename to test/messageStreamTest.js diff --git a/test/nashorn.js b/test/nashornTest.js similarity index 100% rename from test/nashorn.js rename to test/nashornTest.js diff --git a/test/stream.js b/test/streamTest.js similarity index 100% rename from test/stream.js rename to test/streamTest.js diff --git a/tests.webpack.js b/tests.webpack.js new file mode 100644 index 0000000..5e91da2 --- /dev/null +++ b/tests.webpack.js @@ -0,0 +1,6 @@ +//tell karma which files to load. +var testContext = require.context('./test', true, /Test\.js$/); +testContext.keys().forEach(testContext); + +var allContext = require.context('./src', true, /\.js$/); +allContext.keys().forEach(allContext);