Skip to content

Commit

Permalink
#205 add new config structure to tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zsolt Lattmann committed Mar 7, 2015
1 parent 7b4c672 commit f8a6fc8
Show file tree
Hide file tree
Showing 30 changed files with 140 additions and 47 deletions.
15 changes: 15 additions & 0 deletions config/config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*jshint node: true*/
/**
* @author lattmann / https://github.com/lattmann
*/

var config = require('./config.global');

config.server.port = 9001;


config.mongo.uri = 'mongodb://127.0.0.1:27017/webgme_tests';



module.exports = config;
13 changes: 12 additions & 1 deletion test/_globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@
//TODO TESTING have to be set before including webgme
global.TESTING = true;

// TODO: maybe add the testing flag to config?
process.env.NODE_ENV = 'test';

//adding a local storage class to the global Namespace
var WebGME = require('../webgme'),
var gmeConfig = require('../config'),
getGmeConfig = function () {
'use strict';
// makes sure that for each request it returns with a unique object and tests will not interfere
return JSON.parse(JSON.stringify(gmeConfig));
},
WebGME = require('../webgme'),
requirejs = require('requirejs'),

Local = requirejs('storage/local'),
Expand Down Expand Up @@ -203,6 +212,8 @@ function loadNodes(parameters, done) {
*/
}
module.exports = {
getGmeConfig: getGmeConfig,

WebGME: WebGME,
Storage: Storage,
Log: Log,
Expand Down
3 changes: 2 additions & 1 deletion test/bin/apply.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ var testFixture = require('../_globals');
describe('apply CLI tests', function () {
'use strict';

var applyCLI = require('../../src/bin/apply'),
var gmeConfig = testFixture.getGmeConfig(),
applyCLI = require('../../src/bin/apply'),
importCLI = require('../../src/bin/import'),
exportCLI = require('../../src/bin/export'),
mongodb = testFixture.mongodb,
Expand Down
3 changes: 2 additions & 1 deletion test/bin/diff.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var testFixture = require('../_globals');

describe('diff CLI tests', function () {
'use strict';
var diffCLI = require('../../src/bin/diff'),
var gmeConfig = testFixture.getGmeConfig(),
diffCLI = require('../../src/bin/diff'),
importCLI = require('../../src/bin/import'),
mongodb = testFixture.mongodb,
FS = testFixture.fs,
Expand Down
3 changes: 2 additions & 1 deletion test/bin/usermanager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var testFixture = require('../_globals');
describe('User manager command line interface (CLI)', function () {
'use strict';

var should = testFixture.should,
var gmeConfig = testFixture.getGmeConfig(),
should = testFixture.should,
spawn = testFixture.childProcess.spawn,
requirejs = testFixture.requirejs,
mongodb = testFixture.mongodb,
Expand Down
3 changes: 2 additions & 1 deletion test/client/client.basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ var testFixture = require('../_globals');
describe('Client tests', function () {
'use strict';

var should = testFixture.should,
var gmeConfig = testFixture.getGmeConfig(),
should = testFixture.should,
WebGME = testFixture.WebGME,
requirejs = testFixture.requirejs,
config = WebGMEGlobal.getConfig(),
Expand Down
11 changes: 7 additions & 4 deletions test/common/core/core.intrapersist.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
/**
* @author kecso / https://github.com/kecso
*/
var tGlobals = require('../../_globals.js');
var testFixture = require('../../_globals.js');

describe('Core IntraPersist', function () {
'use strict';
var storage = null,
var gmeConfig = testFixture.getGmeConfig(),
storage = null,
requirejs = require('requirejs'),
CANON = requirejs('../src/common/util/canon');

function loadNodes(paths, next) {
var needed = paths.length,
nodes = {}, error = null, i,
nodes = {},
error = null,
i,
loadNode = function (path) {
core.loadByPath(root, path, function (err, node) {
error = error || err;
Expand All @@ -38,7 +41,7 @@ describe('Core IntraPersist', function () {

describe('Pre', function () {
it('import the basic project', function (done) {
tGlobals.importProject({
testFixture.importProject({
filePath: './test/asset/intraPersist.json',
projectName: 'coreIntrapersistTest'
}, function (err, result) {
Expand Down
15 changes: 8 additions & 7 deletions test/common/core/core.mongo.cov.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
/**
* @author kecso / https://github.com/kecso
*/
var tGlobals = require('../../_globals.js');
var testFixture = require('../../_globals.js');

describe('Core Mongo Coverage', function () {
'use strict';
var storage = new tGlobals.WebGME.serverUserStorage({
var gmeConfig = testFixture.getGmeConfig(),
storage = new testFixture.WebGME.serverUserStorage({
host: '127.0.0.1',
port: 27017,
database: 'multi',
log: tGlobals.Log.create('mongoLog')
log: testFixture.Log.create('mongoLog')
});

it('fails to connect to database', function (done) {
this.timeout(20000);
storage = new tGlobals.WebGME.serverUserStorage({
storage = new testFixture.WebGME.serverUserStorage({
host: '127.0.0.1',
port: 65535,
database: 'multi',
log: tGlobals.Log.create('mongoLog')
log: testFixture.Log.create('mongoLog')
});
storage.openDatabase(function (err) {
if (!err) {
Expand All @@ -29,11 +30,11 @@ describe('Core Mongo Coverage', function () {
});
});
it('try double database closing', function (done) {
storage = new tGlobals.WebGME.serverUserStorage({
storage = new testFixture.WebGME.serverUserStorage({
host: '127.0.0.1',
port: 27017,
database: 'multi',
log: tGlobals.Log.create('mongoLog')
log: testFixture.Log.create('mongoLog')
});
storage.openDatabase(function (err) {
if (err) {
Expand Down
9 changes: 5 additions & 4 deletions test/common/core/core.serialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
/**
* @author kecso / https://github.com/kecso
*/
var tGlobals = require('../../_globals.js');
var testFixture = require('../../_globals.js');

describe('Core Serialization', function () {
'use strict';
//global variables of the test
var storage = null,
var gmeConfig = testFixture.getGmeConfig(),
storage = null,
commit = '',
baseCommit = '',
root = null,
Expand All @@ -23,7 +24,7 @@ describe('Core Serialization', function () {
guidToPath,
jsonData;
it('imports the example project', function (done) {
tGlobals.importProject({
testFixture.importProject({
filePath: './test/asset/exportimport.json',
projectName: 'coreSerializationTest'
}, function (err, result) {
Expand All @@ -46,7 +47,7 @@ describe('Core Serialization', function () {
this.timeout(5000);
iData = jsonData;
eData = {};
tGlobals.WebGME.serializer.export(core, root, function (err, exp) {
testFixture.WebGME.serializer.export(core, root, function (err, exp) {
if (err) {
return done(err);
}
Expand Down
3 changes: 2 additions & 1 deletion test/common/core/corediff.spec.apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var testFixture = require('../../_globals.js');

describe('corediff apply', function () {
'use strict';
var projectName = 'coreDiffApply',
var gmeConfig = testFixture.getGmeConfig(),
projectName = 'coreDiffApply',
project,
core,
root,
Expand Down
3 changes: 2 additions & 1 deletion test/common/core/corediff.spec.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var testFixture = require('../../_globals.js');

describe('corediff-base', function () {
'use strict';
var storage = new testFixture.Storage();
var gmeConfig = testFixture.getGmeConfig(),
storage = new testFixture.Storage();

describe('commitAncestor', function () {
describe('straight line', function () {
Expand Down
3 changes: 2 additions & 1 deletion test/common/core/corediff.spec.merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ var testFixture = require('../../_globals.js');

describe('corediff-merge', function () {
'use strict';
var FS = testFixture.fs,
var gmeConfig = testFixture.getGmeConfig(),
FS = testFixture.fs,
WebGME = testFixture.WebGME,
storage = testFixture.Storage();

Expand Down
7 changes: 4 additions & 3 deletions test/common/core/corerel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
/**
* @author kecso / https://github.com/kecso
*/
var tGlobals = require('../../_globals.js');
var testFixture = require('../../_globals.js');

describe('corerel', function () {
'use strict';
var storage = null,
var gmeConfig = testFixture.getGmeConfig(),
storage = null,
project = null,
baseCommitHash = '',
root = null,
core = null;

before(function (done) {
//load the project, import it, and save the base commit hash
tGlobals.importProject({
testFixture.importProject({
filePath: './test/common/core/corerel/base001.json',
projectName: 'coreRelTests'
}, function (err, result) {
Expand Down
5 changes: 3 additions & 2 deletions test/common/core/coretree.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
var testFixture = require('../../_globals.js');

describe('CoreTree', function () {
"use strict";
'use strict';

var should = require('chai').should(),
var gmeConfig = testFixture.getGmeConfig(),
should = require('chai').should(),
requirejs = require('requirejs'),

CoreTree = requirejs('common/core/coretree'),
Expand Down
3 changes: 2 additions & 1 deletion test/common/storage/local.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ var testFixture = require('../../_globals.js');

describe('local', function () {
'use strict';
var storage = new testFixture.Storage();
var gmeConfig = testFixture.getGmeConfig(),
storage = new testFixture.Storage();

describe('Database', function () {
it('should be empty initially', function (done) {
Expand Down
7 changes: 4 additions & 3 deletions test/common/storage/mongo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
*/
//these tests intended to ensure that every used feature of mongodb and its used client is work as expected

var tGlobals = require('../../_globals.js');
var testFixture = require('../../_globals.js');
describe('mongo database', function () {
'use strict';
var db,
var gmeConfig = testFixture.getGmeConfig(),
db,
collection,
collectionName = 'mongotest___test',
fsyncDatabase = function (callback) {
Expand Down Expand Up @@ -41,7 +42,7 @@ describe('mongo database', function () {
};

before(function (done) {
tGlobals.mongodb.MongoClient.connect('mongodb://127.0.0.1/mongotest', {
testFixture.mongodb.MongoClient.connect('mongodb://127.0.0.1/mongotest', {
'w': 1,
'native-parser': true,
'auto_reconnect': true,
Expand Down
37 changes: 37 additions & 0 deletions test/config/config.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*jshint node: true, mocha: true*/
/**
* @author lattmann / https://github.com/lattmann
*/

describe('configuration', function () {

var should = require('chai').should(),
oldNodeEnv = process.env.NODE_ENV,
configGlobal = require('../../config/config.global.js'),
configTest = require('../../config/config.test.js');

before(function () {

});

after(function () {
process.env.NODE_ENV = oldNodeEnv;
});

it('should load global as a default config', function () {
var config;
process.env.NODE_ENV = '';
config = require('../../config/index');

config.should.deep.equal(configGlobal);
});

it('should load test config', function () {
var config;
process.env.NODE_ENV = 'test';
config = require('../../config/index');

config.should.deep.equal(configTest);
});

});
7 changes: 4 additions & 3 deletions test/issue/110_serialization_of_aspect_meta_rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
* @author kecso / https://github.com/kecso
*/

var testFixtures = require('./../_globals.js');
var testFixture = require('./../_globals.js');

describe('issue110 testing', function () {
'use strict';
var storage = null,
var gmeConfig = testFixture.getGmeConfig(),
storage = null,

// global helper functions and globally used variables
baseCommit = null,
Expand All @@ -19,7 +20,7 @@ describe('issue110 testing', function () {
core = null;

it('import the problematic project', function (done) {
testFixtures.importProject({
testFixture.importProject({
filePath: './test/issue/110/input.json',
projectName: 'issue110test'
}, function (err, result) {
Expand Down
4 changes: 3 additions & 1 deletion test/issue/171_nonexistent_branch_crash.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var testFixture = require('../_globals.js');

describe('issue 171 server crashes when trying to switch to non-existent branch', function () {
'use strict';
var requirejs = testFixture.requirejs,
var gmeConfig = testFixture.getGmeConfig(),
requirejs = testFixture.requirejs,
ClientClass,
WebGME = testFixture.WebGME,
Q = testFixture.Q,
Expand All @@ -18,6 +19,7 @@ describe('issue 171 server crashes when trying to switch to non-existent branch'
should = testFixture.should,
server;


requirejs.config({
nodeRequire: require,
paths: {
Expand Down
3 changes: 2 additions & 1 deletion test/middleware/blob/Artifact.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var testFixture = require('../../_globals.js');

describe('Artifact', function () {
'use strict';
var Artifact = testFixture.requirejs('blob/Artifact'),
var gmeConfig = testFixture.getGmeConfig(),
Artifact = testFixture.requirejs('blob/Artifact'),
rimraf = testFixture.rimraf,
should = testFixture.should,
superagent = testFixture.superagent,
Expand Down
3 changes: 2 additions & 1 deletion test/middleware/blob/BlobClient.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ var testFixture = require('../../_globals.js');

describe('BlobClient', function () {
'use strict';
var rimraf = testFixture.rimraf,
var gmeConfig = testFixture.getGmeConfig(),
rimraf = testFixture.rimraf,
should = testFixture.should,
superagent = testFixture.superagent,
expect = testFixture.expect,
Expand Down
Loading

0 comments on commit f8a6fc8

Please sign in to comment.