Add UID to each test, save test name when available

Each test now has a unique ID to reference by. This will be useful for reporters and tracking of "done" events. Also, each test now saves the name it's been given.
This commit is contained in:
Jesse Gibson
2016-03-03 16:26:41 -07:00
parent 3e4946951a
commit 87332c088b
6 changed files with 51 additions and 9 deletions

View File

@@ -4,8 +4,16 @@
// deeply merge objects
var assign = require('object-assign-deep');
var defaults = require('./defaults');
var Gun = require('gun/gun');
/*
This is the test configuration constructor.
An instance is created each time a new
`test()` is declared, and is later configured
dynamically by "Context.js".
*/
function Response(obj) {
this.testID = Gun.text.random();
// provide defaults
assign(this, defaults);

View File

@@ -14,7 +14,6 @@ function done() {
}
function Test(name, cb, time) {
var ctx;
if (!(this instanceof Test)) {
return new Test(name, cb);
}
@@ -22,7 +21,11 @@ function Test(name, cb, time) {
cb = name;
}
ctx = new Context(this);
if (typeof name === 'string') {
this.description = name;
}
var ctx = new Context(this);
stack.push(ctx);
cb.call(ctx, ctx);
bump(ctx, done);

View File

@@ -1,11 +1,11 @@
/*jslint node: true, nomen: true*/
'use strict';
//require('../libb/polyfill');
var express = require('express');
var server = express();
var port = process.argv[2] || 8080;
var host = 'localhost';
var path = require('path');
var dist = path.join(__dirname, '../dist');
@@ -28,9 +28,11 @@ module.exports = {
router: server,
host: host,
// return the full URL
toString: function () {
return 'http://localhost:' + port + '/';
return 'http://' + host + ':' + port + '/';
}
};
@@ -53,4 +55,4 @@ server.post('/done', function (req, res) {
module.exports.done.apply(this, arguments);
});
server.listen(port);
server.listen(port, host);

View File

@@ -24,4 +24,16 @@ describe('The Response constructor', function () {
var keys = Object.keys(new Response());
expect(keys.length).toBeGreaterThan(0);
});
it('should produce a test ID string', function () {
var id = new Response().testID;
expect(id).toEqual(jasmine.any(String));
});
it('should produce unique IDs for each instance', function () {
var id2, id1;
id1 = new Response().testID;
id2 = new Response().testID;
expect(id1).not.toBe(id2);
});
});

View File

@@ -1,5 +1,5 @@
/*jslint node: true*/
/*global jasmine, describe, it, expect*/
/*global jasmine, describe, it, expect, pending*/
'use strict';
@@ -23,13 +23,22 @@ describe('The test function', function () {
});
});
it('should allow you to name tests', function (done) {
test('Named test', done);
it('should allow you to name tests', function () {
var called = false;
test('Named test', function () {
called = true;
});
expect(called).toBe(true);
});
it('should pass the context as arg1', function () {
it('should pass the context as arg0', function () {
test(function (ctx) {
expect(ctx).toEqual(jasmine.any(Context));
});
});
it('should remember the test name', function () {
var result = test('fabulous success', function () {});
expect(result.description).toBe('fabulous success');
});
});

View File

@@ -13,6 +13,14 @@ describe('The router', function () {
expect(stringy).toBe(true);
});
it('should export the current port', function () {
expect(route.port).toEqual(jasmine.any(Number));
});
it('should export the hostname', function () {
expect(route.host).toEqual(jasmine.any(String));
});
it('should return the full URL when `toString`ed', function () {
expect(route.toString()).toMatch(/http/i);
});