-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
172 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
const env = require('./utils/env'); | ||
const expect = env.expect; | ||
const config = require('../config.js'); | ||
|
||
describe('config', function() { | ||
it('should have default value', function() { | ||
config.factory().root.should.be.a('string'); | ||
expect(config.factory().root).to.be.a('string'); | ||
}); | ||
it('should respect init config', function() { | ||
config.factory({root: 'xx'}).root.should.equal('xx'); | ||
expect(config.factory({root: 'xx'}).root).to.equal('xx'); | ||
}); | ||
it('set should return this', function() { | ||
var cfg = config.factory(); | ||
cfg.set('foo', 'bar').should.equal(cfg); | ||
expect(cfg.set('foo', 'bar')).to.equal(cfg); | ||
}); | ||
it('should get correctly after set', function() { | ||
config.factory().set('bar', 'foo').get('bar').should.equal('foo'); | ||
expect(config.factory().set('bar', 'foo').get('bar')).to.equal('foo'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
require('./config'); | ||
require('./http'); | ||
require('./parser'); | ||
require('./loader'); | ||
require('./render'); | ||
require('./context'); | ||
require('./resolver'); | ||
var request = require('supertest'); | ||
//var brick = require('..'); | ||
|
||
describe('express', function () { | ||
var server; | ||
beforeEach(function () { | ||
//server = require('./server'); | ||
}); | ||
afterEach(function () { | ||
//server.close(); | ||
}); | ||
//it('responds to /', function testSlash(done) { | ||
//request(server) | ||
//.get('/') | ||
//.expect(200, done); | ||
//}); | ||
//it('404 everything else', function testPath(done) { | ||
//}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const env = require('./utils/env'); | ||
const expect = env.expect; | ||
const mock = require('mock-fs'); | ||
const m = require('../src/module.js'); | ||
const config = require('../config.js'); | ||
const stubs = require('./utils/stubs.js'); | ||
const sinon = require('sinon'); | ||
|
||
describe('module', function() { | ||
var cfg; | ||
before(function(){ | ||
mock({ | ||
'/foo/router.js': 'exports.url="/"', | ||
'/bar/view.html': 'bar' | ||
}); | ||
cfg = config.factory({ | ||
root: '/' | ||
}); | ||
}); | ||
after(function() { | ||
mock.restore(); | ||
}); | ||
it('should use dirname as mid by default', function() { | ||
var mod = m.loadModule('/foo', cfg); | ||
expect(mod.id).to.equal('foo'); | ||
}); | ||
it('should use default context when no router present', function() { | ||
var mod = m.loadModule('/bar', cfg); | ||
return expect(mod.context(stubs.req, stubs.res)).to.be.fullfilled; | ||
}); | ||
it('render should call renderer', function() { | ||
var mod = m.loadModule('/bar', cfg); | ||
var spy = sinon.spy(mod, 'renderer'); | ||
var ctx = { | ||
foo: 'bar' | ||
}; | ||
return mod.render(stubs.req, stubs.res, ctx).then(function() { | ||
var args = spy.args[0]; | ||
expect(args[0]).to.equal('/bar/view.html'); | ||
expect(args[1]).to.deep.equal(ctx); | ||
expect(args[2]).to.be.a('function'); | ||
expect(args[3]).to.equal('bar'); | ||
}); | ||
}); | ||
it('render should be called recursively', function() { | ||
var mod = m.loadModule('/bar', cfg); | ||
return expect(mod.render(stubs.req, stubs.res, stubs.ctx)) | ||
.to.eventually.equal('bar'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,46 @@ | ||
const env = require('./utils/env'); | ||
const stubs = require('./utils/stubs'); | ||
const should = env.should; | ||
const expect = env.expect; | ||
const Path = require('path'); | ||
const config = require('../config.js'); | ||
const _ = require('lodash'); | ||
const parser = require('../src/parser.js'); | ||
const mockRequire = require('mock-require'); | ||
const mockFs = require('mock-fs'); | ||
|
||
describe('parser', function() { | ||
var cfg, path; | ||
before(function() { | ||
cfg = config.factory(stubs.brickConfig); | ||
path = Path.resolve(stubs.root, 'sample-module/package.json'); | ||
beforeEach(function() { | ||
mockRequire('/package.json', { | ||
"name": "sample-module", | ||
"version": "1.0.0", | ||
"view": "htmls/my-html.hbs", | ||
"router": "svr.js" | ||
}); | ||
mockRequire('/router.js', { | ||
url: '/foo', | ||
get: function() {} | ||
}); | ||
}); | ||
afterEach(function() { | ||
mockRequire.stopAll(); | ||
}); | ||
it('should parse package.json', function() { | ||
var pkg = parser.parsePackageFile(path); | ||
pkg.name.should.equal("sample-module"); | ||
pkg.version.should.equal("1.0.0"); | ||
pkg.view.should.equal('htmls/my-html.hbs'); | ||
pkg.router.should.equal("svr.js"); | ||
var pkg = parser.parsePackageFile('/package.json'); | ||
expect(pkg.name).to.equal("sample-module"); | ||
expect(pkg.version).to.equal("1.0.0"); | ||
expect(pkg.view).to.equal('htmls/my-html.hbs'); | ||
expect(pkg.router).to.equal("svr.js"); | ||
}); | ||
|
||
it('should parse normal router', function() { | ||
var router = parser.parseRouter('/router.js'); | ||
expect(router.url).to.exist; | ||
expect(router.get).to.exist; | ||
}); | ||
}); | ||
|
||
it('should parse empty router', function() { | ||
var router = parser.parseRouter('/not-exist-router.js'); | ||
expect(router.url).to.not.exist; | ||
expect(router).to.exist; | ||
}); | ||
}); |
Oops, something went wrong.