From d1eb481fce2b1cf61e102ca37fc31d928db255a3 Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Fri, 14 Dec 2012 21:44:38 +0400 Subject: [PATCH] Allow extend tests --- package.json | 5 +---- test/common_test.js | 45 +++++++++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 60c5783d..500a39e5 100644 --- a/package.json +++ b/package.json @@ -54,11 +54,8 @@ "test": "nodeunit test/*_test*" }, "engines": [ - "node >= 0.4.12" + "node >= 0.6" ], - "dependencies": { - "node-uuid": ">= 1.3.3" - }, "devDependencies": { "semicov": "*", "coffee-script": ">= 1.2.0", diff --git a/test/common_test.js b/test/common_test.js index d080793b..e402bd3b 100644 --- a/test/common_test.js +++ b/test/common_test.js @@ -27,33 +27,60 @@ var Text = Schema.Text; var nbSchemaRequests = 0; var batch; +var schemaName; function it(name, cases) { - batch[name] = cases; + batch[schemaName][name] = cases; } module.exports = function testSchema(exportCasesHere, schema) { 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(); schema.on('connected', test.done); - }); + }; schema.log = function (a) { console.log(a); nbSchemaRequests++; }; + batch[schemaName] = {}; + 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) { var requestsAreCounted = schema.name !== 'mongodb'; var Post, User, Passport; - var start = Date.now(); 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); - } - }