Allow extend tests

This commit is contained in:
Anatoliy Chakkaev 2012-12-14 21:44:38 +04:00
parent 90624174f7
commit d1eb481fce
2 changed files with 32 additions and 18 deletions

View File

@ -54,11 +54,8 @@
"test": "nodeunit test/*_test*" "test": "nodeunit test/*_test*"
}, },
"engines": [ "engines": [
"node >= 0.4.12" "node >= 0.6"
], ],
"dependencies": {
"node-uuid": ">= 1.3.3"
},
"devDependencies": { "devDependencies": {
"semicov": "*", "semicov": "*",
"coffee-script": ">= 1.2.0", "coffee-script": ">= 1.2.0",

View File

@ -27,33 +27,60 @@ var Text = Schema.Text;
var nbSchemaRequests = 0; var nbSchemaRequests = 0;
var batch; var batch;
var schemaName;
function it(name, cases) { function it(name, cases) {
batch[name] = cases; batch[schemaName][name] = cases;
} }
module.exports = function testSchema(exportCasesHere, schema) { module.exports = function testSchema(exportCasesHere, schema) {
batch = exportCasesHere; batch = exportCasesHere;
schemaName = schema.name;
if (schema.name.match(/^\/.*\/test\/\.\.$/)) {
schemaName = schemaName.split('/').slice(-3).shift();
}
var start;
it('should connect to database', function (test) { batch['should connect to database'] = function (test) {
start = Date.now();
if (schema.connected) return test.done(); if (schema.connected) return test.done();
schema.on('connected', test.done); schema.on('connected', test.done);
}); };
schema.log = function (a) { schema.log = function (a) {
console.log(a); console.log(a);
nbSchemaRequests++; nbSchemaRequests++;
}; };
batch[schemaName] = {};
testOrm(schema); testOrm(schema);
batch['all tests done'] = function (test) {
test.done();
process.nextTick(allTestsDone);
};
function allTestsDone() {
schema.disconnect();
console.log('Test done in %dms\n', Date.now() - start);
}
}; };
module.exports.it = it;
Object.defineProperty(module.exports, 'it', {
writable: true,
enumerable: false,
configurable: true,
value: it
});
function testOrm(schema) { function testOrm(schema) {
var requestsAreCounted = schema.name !== 'mongodb'; var requestsAreCounted = schema.name !== 'mongodb';
var Post, User, Passport; var Post, User, Passport;
var start = Date.now();
it('should define class', function (test) { it('should define class', function (test) {
@ -1136,14 +1163,4 @@ function testOrm(schema) {
}); });
}); });
it('all tests done', function (test) {
test.done();
process.nextTick(allTestsDone);
});
function allTestsDone() {
schema.disconnect();
console.log('Test done in %dms\n', Date.now() - start);
}
} }