Skip to content

Commit

Permalink
added more tests and dependencies for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dmill-bz committed Apr 3, 2016
1 parent 4a704de commit b6dee2e
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ dist*
umd*
node_modules/*
api/*
coverage/*
.coveralls.yml
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ install:
before_script:
- npm run build

script: npm run test
script: npm run test:coverage

#~ after_script:
#~ - npm run coverage:travis
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

[![Build Status](https://travis-ci.org/PommeVerte/gremlin-console-js.svg?branch=master)](https://travis-ci.org/PommeVerte/gremlin-console-js) [![Coverage Status](https://coveralls.io/repos/github/PommeVerte/gremlin-console-js/badge.svg?branch=master)](https://coveralls.io/github/PommeVerte/gremlin-console-js?branch=master)

## Gremlin Console

Expand Down
27 changes: 23 additions & 4 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var path = require('path');
module.exports = function (config) {
config.set({

Expand All @@ -7,10 +8,12 @@ module.exports = function (config) {
singleRun: true, //just run once by default

files: [
'tests.webpack.js' //just load this file
'tests.webpack.js', //just load this file
{pattern: 'test/index.html', watched: false, served:true} // load html file
],
preprocessors: {
'tests.webpack.js': [ 'webpack', 'sourcemap' ] //preprocess with webpack and our sourcemap loader
'test/index.html': ['html2js'], // helps load html file for dom testing
'tests.webpack.js': [ 'webpack', 'sourcemap'] //preprocess with webpack and our sourcemap loader
},

webpack: { //kind of a copy of your webpack config
Expand All @@ -20,13 +23,26 @@ module.exports = function (config) {
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'],
reporters: ['mocha', 'coverage', 'coveralls'],

coverageReporter: {
type: 'lcov', // lcov or lcovonly are required for generating lcov.info files
dir: 'coverage/'
},

port: 9876,
colors: true,
Expand All @@ -44,7 +60,10 @@ module.exports = function (config) {
'karma-chai',
'karma-webpack',
'karma-sourcemap-loader',
'karma-mocha-reporter'
'karma-mocha-reporter',
'karma-coverage',
'karma-coveralls',
'karma-html2js-preprocessor'
]

});
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"build:umd": "NODE_ENV=production webpack src/index.js umd/gremlin-console.js && cp -r static/* umd/",
"build:min": "NODE_ENV=production webpack -p src/index.js umd/gremlin-console.min.js",
"build:watch": "npm run build -- --watch",
"test": "karma start karma.conf.js --single-run"
"test": "karma start karma.conf.js --single-run --reporters mocha",
"test:coverage": "karma start karma.conf.js --single-run && rm -rf coverage"
},
"dependencies": {
"babel-cli": "~6.6.5",
Expand All @@ -26,9 +27,13 @@
},
"devDependencies": {
"chai": "^3.5.0",
"isparta-loader": "^2.0.0",
"karma": "^0.13.22",
"karma-chai": "^0.1.0",
"karma-coverage": "^0.5.5",
"karma-coveralls": "^1.1.2",
"karma-firefox-launcher": "^0.1.7",
"karma-html2js-preprocessor": "^0.1.0",
"karma-mocha": "^0.2.2",
"karma-mocha-reporter": "^2.0.0",
"karma-phantomjs-launcher": "^1.0.0",
Expand Down
4 changes: 1 addition & 3 deletions src/Console.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ class Console extends EventEmitter {
}

//lets init the client
console.log("connection to ws://" + this.options.host + ":" + this.options.port);
console.log(this.options.driverOptions);
this.client = new Client(this.options.port, this.options.host, this.options.driverOptions);
this.client = new Client(this.options.host, this.options.port, this.options.driverOptions);

this._attachHandlers();

Expand Down
4 changes: 0 additions & 4 deletions test/.babelrc

This file was deleted.

68 changes: 65 additions & 3 deletions test/ClientTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import Client from '../src/DriverClient.js';
describe('DriverClient.construct()', () => {
it('should create a client with default options', () => {
const client = new Client();
console.log(client);
client.should.be.a('Object');
client.client.should.be.a('Object');

client.constructor.name.should.equal('DriverClient');
should.exist(client.client);
client.client.constructor.name.should.equal('GremlinClient');

client.client.port.should.equal(8182);
client.client.host.should.equal('localhost');
Expand All @@ -28,3 +28,65 @@ describe('DriverClient.construct()', () => {
});
});


describe('DriverClient.buildResult()', () => {

it('should create and populate a Result object', () => {
const client = new Client();
const result = client.buildResult("raw error", "results");

result.constructor.name.should.equal('Result');
result._rawResults.should.equal('results');
result._rawError.should.equal('raw error');

});

it('should accept a Result object generated from undefined vars', () => {
const client = new Client();
const result = client.buildResult(undefined, undefined);

result.constructor.name.should.equal('Result');
});
});

describe('DriverClient.execute()', () => {

it('should execute correctly with: query', () => {
const client = new Client();
client.execute("5+5");
});

it('should execute correctly with: query + bindings', () => {
const client = new Client();
client.execute("5+variable", {variable:5});
});

it('should execute correctly with: query + callback', () => {
const client = new Client();
client.execute("5+5", () => {});
});

it('should execute correctly with: query + bindings + callback', () => {
const client = new Client();
client.execute("5+variable", {variable:5}, () => {});
});

//~ it('callback should receive query + Result object', () => {
//~ const client = new Client();
//~ client.execute("5+5", (query, result) => {
//~ console.log(query);console.log(result);
//~ query.should.be.a('string');
//~ result.constructor.name.should.equal('Result');
//~ });
//~ });
//~
//~ it('output query and Result object should contain the correct information', () => {
//~ const client = new Client();
//~ let query, result;
//~
//~ async client.execute("5+5", (q, r) => {
//~
//~ });
//~
//~ });
});
1 change: 1 addition & 0 deletions test/ConsoleTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Console from '../src/Console.js';
4 changes: 2 additions & 2 deletions test/HtmlTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Html.jsonSyntaxHighlight()', () => {
highlighted.should.equal(expected);
});
it('should return a highlighted string from a json string', () => {
const highlighted = Html.jsonSyntaxHighlight(JSON.stringify(json));
highlighted.should.equal(expected.replace(/[\r\n]| /g, "").replace(/\> \</g, "><")); // outputs differ to we normalize
const highlighted = Html.jsonSyntaxHighlight(JSON.stringify(json, undefined, 2));
highlighted.should.equal(expected);
});
});
10 changes: 10 additions & 0 deletions test/IndexTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import create from '../src/index.js';

describe('index.js .create()', () => {
it('should create a client with default options', () => {
document.body.innerHTML = __html__['test/index.html'];
const client = create("#window", "#input");

client.constructor.name.should.equal('Console');
});
});
2 changes: 2 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div id="window"></div>
<input id="input" type="text" name="query" placeholder="Enter query here">
7 changes: 5 additions & 2 deletions tests.webpack.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//tell karma which files to load.
var context = require.context('./test', true, /Test\.js$/);
context.keys().forEach(context);
var testContext = require.context('./test', true, /Test\.js$/);
testContext.keys().forEach(testContext);

var allContext = require.context('./src', true, /\.js$/);
allContext.keys().forEach(allContext);

0 comments on commit b6dee2e

Please sign in to comment.