kopia lustrzana https://github.com/c9/core
convert tests to mocha
rodzic
f6f5e02877
commit
eb671b6d13
|
@ -3,9 +3,12 @@
|
||||||
var sinon = require("sinon");
|
var sinon = require("sinon");
|
||||||
var frontdoor = require('../frontdoor');
|
var frontdoor = require('../frontdoor');
|
||||||
var Route = frontdoor.Route;
|
var Route = frontdoor.Route;
|
||||||
var test = require('tape');
|
var assert = require('assert');
|
||||||
|
|
||||||
test("test router: simple route with argument", function(assert) {
|
require("c9/inline-mocha")(module);
|
||||||
|
require("amd-loader");
|
||||||
|
|
||||||
|
it("test router: simple route with argument", function(done) {
|
||||||
var route = new Route("/user/:name", sinon.stub());
|
var route = new Route("/user/:name", sinon.stub());
|
||||||
|
|
||||||
var req = {};
|
var req = {};
|
||||||
|
@ -15,10 +18,10 @@ test("test router: simple route with argument", function(assert) {
|
||||||
assert.equal(route.match(req, "/user/fabian"), true);
|
assert.equal(route.match(req, "/user/fabian"), true);
|
||||||
assert.equal(req.match.name, "fabian");
|
assert.equal(req.match.name, "fabian");
|
||||||
|
|
||||||
assert.end();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("test router: simple route with number argument", function(assert) {
|
it("test router: simple route with number argument", function(done) {
|
||||||
var route = new Route("/user/:id", {
|
var route = new Route("/user/:id", {
|
||||||
params: {
|
params: {
|
||||||
id: {
|
id: {
|
||||||
|
@ -32,10 +35,10 @@ test("test router: simple route with number argument", function(assert) {
|
||||||
assert.equal(route.match(req, "/user/123"), true);
|
assert.equal(route.match(req, "/user/123"), true);
|
||||||
assert.equal(req.match.id, 123);
|
assert.equal(req.match.id, 123);
|
||||||
|
|
||||||
assert.end();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("test router: for params if the value is a string it is treated as the type", function(assert) {
|
it("test router: for params if the value is a string it is treated as the type", function(done) {
|
||||||
var route = new Route("/user/:id", {
|
var route = new Route("/user/:id", {
|
||||||
params: {
|
params: {
|
||||||
id: "int"
|
id: "int"
|
||||||
|
@ -46,10 +49,10 @@ test("test router: for params if the value is a string it is treated as the type
|
||||||
assert.equal(route.match(req, "/user/123"), true);
|
assert.equal(route.match(req, "/user/123"), true);
|
||||||
assert.equal(req.match.id, 123);
|
assert.equal(req.match.id, 123);
|
||||||
|
|
||||||
assert.end();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("test router: complex route with wildcard arguments", function(assert) {
|
it("test router: complex route with wildcard arguments", function(done) {
|
||||||
var route = new Route("/user/:name/:rest*", {
|
var route = new Route("/user/:name/:rest*", {
|
||||||
params: {
|
params: {
|
||||||
id: {
|
id: {
|
||||||
|
@ -74,11 +77,11 @@ test("test router: complex route with wildcard arguments", function(assert) {
|
||||||
assert.equal(req.match.name, "fabian");
|
assert.equal(req.match.name, "fabian");
|
||||||
assert.equal(req.match.rest, "/abc/123");
|
assert.equal(req.match.rest, "/abc/123");
|
||||||
|
|
||||||
assert.end();
|
done();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("test router: complex route with multiple arguments", function(assert) {
|
it("test router: complex route with multiple arguments", function(done) {
|
||||||
var route = new Route("/user/:name/:id", {
|
var route = new Route("/user/:name/:id", {
|
||||||
params: {
|
params: {
|
||||||
id: {
|
id: {
|
||||||
|
@ -95,11 +98,11 @@ test("test router: complex route with multiple arguments", function(assert) {
|
||||||
assert.equal(req.match.id, 123);
|
assert.equal(req.match.id, 123);
|
||||||
assert.equal(req.match.name, "fabian");
|
assert.equal(req.match.name, "fabian");
|
||||||
|
|
||||||
assert.end();
|
done();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("test regexp types", function(assert) {
|
it("test regexp types", function(done) {
|
||||||
var route = new Route("/users/:uid", {
|
var route = new Route("/users/:uid", {
|
||||||
params: {
|
params: {
|
||||||
uid: /u\d+/
|
uid: /u\d+/
|
||||||
|
@ -111,11 +114,11 @@ test("test regexp types", function(assert) {
|
||||||
assert.ok(route.match(req, "/users/u123"));
|
assert.ok(route.match(req, "/users/u123"));
|
||||||
assert.ok(!route.match(req, "/users/_u123"));
|
assert.ok(!route.match(req, "/users/_u123"));
|
||||||
|
|
||||||
assert.end();
|
done();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("test custom type without register", function(assert) {
|
it("test custom type without register", function(done) {
|
||||||
var DateType = {
|
var DateType = {
|
||||||
parse: function(string) {
|
parse: function(string) {
|
||||||
if (!/\d{13}/.test(string))
|
if (!/\d{13}/.test(string))
|
||||||
|
@ -144,6 +147,5 @@ test("test custom type without register", function(assert) {
|
||||||
assert.ok(!route.match(req, "/ts/353676299181"));
|
assert.ok(!route.match(req, "/ts/353676299181"));
|
||||||
assert.ok(!route.match(req, "/ts/abc"));
|
assert.ok(!route.match(req, "/ts/abc"));
|
||||||
|
|
||||||
|
done();
|
||||||
assert.end();
|
|
||||||
});
|
});
|
|
@ -1,7 +1,11 @@
|
||||||
var test = require('tape');
|
var assert = require('assert-diff');
|
||||||
var Section = require('../frontdoor').Section;
|
var Section = require('../frontdoor').Section;
|
||||||
var Url = require('url');
|
var Url = require('url');
|
||||||
|
|
||||||
|
require("c9/inline-mocha")(module);
|
||||||
|
// require("amd-loader");
|
||||||
|
|
||||||
|
|
||||||
var mock = {
|
var mock = {
|
||||||
req: function( method, uri) {
|
req: function( method, uri) {
|
||||||
var parsedUrl = Url.parse(uri||'', true);
|
var parsedUrl = Url.parse(uri||'', true);
|
||||||
|
@ -15,7 +19,7 @@ var mock = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
test('Defines params on section level', function(assert, things, done) {
|
it('Defines params on section level', function(done) {
|
||||||
var testParams = {
|
var testParams = {
|
||||||
required: {
|
required: {
|
||||||
type: 'int',
|
type: 'int',
|
||||||
|
@ -155,12 +159,12 @@ test('Defines params on section level', function(assert, things, done) {
|
||||||
|
|
||||||
api.handle( req.pathname, req, {}, function(err) {
|
api.handle( req.pathname, req, {}, function(err) {
|
||||||
if ( testCase.err ) {
|
if ( testCase.err ) {
|
||||||
assert.pass( 'route not matched: ' + testCase.label );
|
assert.ok( 'route not matched: ' + testCase.label );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert.fail( 'route not matched: ' + testCase.label );
|
assert.fail( 'route not matched: ' + testCase.label );
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.end();
|
done();
|
||||||
});
|
});
|
||||||
|
|
Ładowanie…
Reference in New Issue