Fix space-before-blocks

This commit is contained in:
bananaappletw 2016-10-20 13:12:07 +08:00
parent 0d87e0e000
commit 2f205052ed
30 changed files with 112 additions and 112 deletions

View File

@ -2,7 +2,7 @@ var koa = require('koa');
var app = module.exports = koa();
app.use(function *pageNotFound(next){
app.use(function *pageNotFound(next) {
yield next;
if (404 != this.status) return;

View File

@ -2,9 +2,9 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('404', function(){
describe('when GET /', function(){
it('should return the 404 page', function(done){
describe('404', function() {
describe('when GET /', function() {
it('should return the 404 page', function(done) {
request
.get('/')
.expect(404)

View File

@ -4,7 +4,7 @@ var app = module.exports = koa();
// custom 401 handling
app.use(function* (next){
app.use(function* (next) {
try {
yield next;
} catch (err) {
@ -24,7 +24,7 @@ app.use(auth({ name: 'tj', pass: 'tobi' }));
// secret response
app.use(function* (){
app.use(function* () {
this.body = 'secret';
});

View File

@ -1,17 +1,17 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('Koa Basic Auth', function(){
describe('with no credentials', function(){
it('should `throw` 401', function(done){
describe('Koa Basic Auth', function() {
describe('with no credentials', function() {
it('should `throw` 401', function(done) {
request
.get('/')
.expect(401, done);
})
})
describe('with invalid credentials', function(){
it('should `throw` 401', function(done){
describe('with invalid credentials', function() {
it('should `throw` 401', function(done) {
request
.get('/')
.auth('user', 'invalid password')
@ -19,8 +19,8 @@ describe('Koa Basic Auth', function(){
})
})
describe('with valid credentials', function(){
it('should call the next middleware', function(done){
describe('with valid credentials', function() {
it('should call the next middleware', function(done) {
request
.get('/')
.auth('tj', 'tobi')

View File

@ -1,12 +1,12 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('Blog', function(){
describe('GET /', function(){
it('should see title "Posts"', function(done){
describe('Blog', function() {
describe('GET /', function() {
it('should see title "Posts"', function(done) {
request
.get('/')
.expect(200, function(err, res){
.expect(200, function(err, res) {
if (err) return done(err);
res.should.be.html;
@ -14,10 +14,10 @@ describe('Blog', function(){
done();
});
});
it('should see 0 post', function(done){
it('should see 0 post', function(done) {
request
.get('/')
.expect(200, function(err, res){
.expect(200, function(err, res) {
if (err) return done(err);
res.should.be.html;
@ -26,12 +26,12 @@ describe('Blog', function(){
});
});
});
describe('POST /post/new', function(){
it('should create post and redirect to /', function(done){
describe('POST /post/new', function() {
it('should create post and redirect to /', function(done) {
request
.post('/post')
.send({title: 'Title', body: 'Contents'})
.end(function(err, res){
.end(function(err, res) {
if (err) return done(err);
res.header.location.should.be.equal('/')
@ -39,11 +39,11 @@ describe('Blog', function(){
});
});
});
describe('GET /post/0', function(){
it('should see post', function(done){
describe('GET /post/0', function() {
it('should see post', function(done) {
request
.get('/post/0')
.expect(200, function(err, res){
.expect(200, function(err, res) {
if (err) return done(err);
res.should.be.html;

View File

@ -8,7 +8,7 @@ var app = module.exports = koa();
// co-body accepts application/json
// and application/x-www-form-urlencoded
app.use(function *(next){
app.use(function *(next) {
if ('POST' != this.method) return yield next;
var body = yield parse(this, { limit: '1kb' });
if (!body.name) this.throw(400, '.name required');

View File

@ -1,10 +1,10 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('Body Parsing', function(){
describe('POST /uppercase', function(){
describe('with JSON', function(){
it('should work', function(done){
describe('Body Parsing', function() {
describe('POST /uppercase', function() {
describe('with JSON', function() {
it('should work', function(done) {
request
.post('/uppercase')
.send({ name: 'tobi' })
@ -13,8 +13,8 @@ describe('Body Parsing', function(){
})
})
describe('with urlencoded', function(){
it('should work', function(done){
describe('with urlencoded', function() {
it('should work', function(done) {
request
.post('/uppercase')
.send('name=tj')
@ -23,8 +23,8 @@ describe('Body Parsing', function(){
})
})
describe('when length > limit', function(){
it('should 413', function(done){
describe('when length > limit', function() {
it('should 413', function(done) {
request
.post('/json')
.send({ name: Array(5000).join('a') })
@ -32,8 +32,8 @@ describe('Body Parsing', function(){
})
})
describe('when no name is sent', function(){
it('should 400', function(done){
describe('when no name is sent', function() {
it('should 400', function(done) {
request
.post('/uppsercase')
.send('age=10')

View File

@ -18,7 +18,7 @@ var app = module.exports = koa();
// x-response-time
function *responseTime(next){
function *responseTime(next) {
var start = new Date();
yield next;
var ms = new Date() - start;
@ -27,7 +27,7 @@ function *responseTime(next){
// logger
function* logger(next){
function* logger(next) {
var start = new Date();
yield next;
var ms = new Date() - start;
@ -38,7 +38,7 @@ function* logger(next){
// response
function* respond(next){
function* respond(next) {
yield next;
if ('/' != this.url) return;
this.body = 'Hello World';

View File

@ -1,16 +1,16 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('Compose', function(){
describe('when GET /', function(){
it('should say "Hello World"', function(done){
describe('Compose', function() {
describe('when GET /', function() {
it('should say "Hello World"', function(done) {
request
.get('/')
.expect(200)
.expect('Hello World', done);
})
it('should set X-Response-Time', function(done){
it('should set X-Response-Time', function(done) {
request
.get('/')
.expect('X-Response-Time', /ms$/)
@ -18,8 +18,8 @@ describe('Compose', function(){
})
})
describe('when not GET /', function(){
it('should 404', function(done){
describe('when not GET /', function() {
it('should 404', function(done) {
request
.get('/aklsjdf')
.expect(404, done);

View File

@ -8,7 +8,7 @@ var app = koa();
// middleware may "wrap" other middleware.
function ignoreAssets(mw) {
return function *(next){
return function *(next) {
if (/(\.js|\.css|\.ico)$/.test(this.path)) {
yield next;
} else {
@ -26,7 +26,7 @@ function ignoreAssets(mw) {
app.use(ignoreAssets(logger()));
app.use(function *(){
app.use(function *() {
this.body = 'Hello World';
});

View File

@ -6,7 +6,7 @@
var koa = require('koa');
var app = module.exports = koa();
app.use(function *(){
app.use(function *() {
var n = ~~this.cookies.get('view') + 1;
this.cookies.set('view', n);
this.body = n + ' views';

View File

@ -1,10 +1,10 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('Cookies Views', function(){
describe('Cookies Views', function() {
[1, 2, 3].forEach(function(i) {
describe('on iteration #' + i, function(){
it('should set the views as a cookie and as the body', function(done){
describe('on iteration #' + i, function() {
it('should set the views as a cookie and as the body', function(done) {
request
.get('/')
.expect(200)

View File

@ -4,9 +4,9 @@ var request = require('supertest').agent(app.listen());
var token;
var cookie;
describe('csrf', function(){
describe('GET /token', function(){
it('should get token', function(done){
describe('csrf', function() {
describe('GET /token', function() {
it('should get token', function(done) {
request
.get('/token')
.expect(200)

View File

@ -4,7 +4,7 @@ var app = module.exports = koa();
// look ma, error propagation!
app.use(function *(next){
app.use(function *(next) {
try {
yield next;
} catch (err) {
@ -24,13 +24,13 @@ app.use(function *(next){
// response
app.use(function *(){
app.use(function *() {
throw new Error('boom boom');
});
// error handler
app.on('error', function(err){
app.on('error', function(err) {
if (process.env.NODE_ENV != 'test') {
console.log('sent error %s to the cloud', err.message);
console.log(err);

View File

@ -2,14 +2,14 @@ var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('Errors', function() {
it('should catch the error', function(done){
it('should catch the error', function(done) {
request
.get('/')
.expect(500)
.expect('Content-Type', /text\/html/, done);
})
it('should emit the error on app', function(done){
it('should emit the error on app', function(done) {
app.once('error', function(err, ctx) {
err.message.should.equal('boom boom');
ctx.should.be.ok;
@ -18,6 +18,6 @@ describe('Errors', function() {
request
.get('/')
.end(function(){});
.end(function() {});
})
})

View File

@ -13,7 +13,7 @@ var app = module.exports = koa();
app.keys = ['key1', 'key2'];
app.use(session(app));
app.use(function *(next){
app.use(function *(next) {
if (this.method !== 'GET' || this.path !== '/messages') return yield next;
// get any messages saved in the session
@ -24,7 +24,7 @@ app.use(function *(next){
delete this.session.messages;
})
app.use(function *(next){
app.use(function *(next) {
if (this.method !== 'POST' || this.path !== '/messages') return yield next;
// the request string is the flash message

View File

@ -1,8 +1,8 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('Flash Messages', function(){
it('GET should return an empty array', function(done){
describe('Flash Messages', function() {
it('GET should return an empty array', function(done) {
request
.get('/messages')
.expect(200)
@ -10,14 +10,14 @@ describe('Flash Messages', function(){
.expect('[]', done);
})
it('POST should return 204', function(done){
it('POST should return 204', function(done) {
request
.post('/messages')
.send('hello')
.expect(204, done);
})
it('GET should return the message', function(done){
it('GET should return the message', function(done) {
request
.get('/messages')
.expect(200)
@ -25,7 +25,7 @@ describe('Flash Messages', function(){
.expect('["hello"]', done);
})
it('GET should return no more messages', function(done){
it('GET should return no more messages', function(done) {
request
.get('/messages')
.expect(200)

View File

@ -2,7 +2,7 @@
var koa = require('koa');
var app = module.exports = koa();
app.use(function *(){
app.use(function *() {
this.body = 'Hello World';
});

View File

@ -1,8 +1,8 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('Hello World', function(){
it('should say "Hello World"', function(done){
describe('Hello World', function() {
it('should say "Hello World"', function(done) {
request
.get('/')
.expect(200)

View File

@ -14,7 +14,7 @@ var saveTo = require('save-to');
var app = module.exports = koa();
app.use(function *(){
app.use(function *() {
// parse the multipart body
var parts = parse(this, {
autoFields: true // saves the fields to parts.field(s)

View File

@ -25,7 +25,7 @@ var users = {
// may want to check the type, as it may
// be a stream, buffer, string, etc.
app.use(function *(next){
app.use(function *(next) {
yield next;
// no body? nothing to format, early return
@ -64,7 +64,7 @@ app.use(function *(next){
// filter responses, in this case remove ._id
// since it's private
app.use(function *(next){
app.use(function *(next) {
yield next;
if (!this.body) return;
@ -75,7 +75,7 @@ app.use(function *(next){
// try $ GET /tobi
// try $ GET /loki
app.use(function *(){
app.use(function *() {
var name = this.path.slice(1);
var user = users[name];
this.body = user;

View File

@ -1,28 +1,28 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('Stream File', function(){
it('GET /app.js', function(done){
describe('Stream File', function() {
it('GET /app.js', function(done) {
request
.get('/app.js')
.expect('content-type', /application\/javascript/)
.expect(200, done);
});
it('GET /test.js', function(done){
it('GET /test.js', function(done) {
request
.get('/test.js')
.expect('content-type', /application\/javascript/)
.expect(200, done);
});
it('GET /alksjdf.js', function(done){
it('GET /alksjdf.js', function(done) {
request
.get('/lajksdf.js')
.expect(404, done);
});
it('GET /', function(done){
it('GET /', function(done) {
request
.get('/')
.expect(404, done);

View File

@ -4,7 +4,7 @@ var JSONStream = require('streaming-json-stringify');
var app = module.exports = koa();
app.use(function *(){
app.use(function *() {
this.type = 'json';
var stream = this.body = JSONStream();

View File

@ -1,11 +1,11 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('Stream Objects', function(){
it('GET /', function(done){
describe('Stream Objects', function() {
it('GET /', function(done) {
request
.get('/app.js')
.expect(200, function(err, res){
.expect(200, function(err, res) {
if (err) return done(err);
res.body.should.eql([{

View File

@ -1,11 +1,11 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('Stream View', function(){
it('GET /', function(done){
describe('Stream View', function() {
it('GET /', function(done) {
request
.get('/')
.expect(200, function(err, res){
.expect(200, function(err, res) {
if (err) return done(err);
res.should.be.html;

View File

@ -21,7 +21,7 @@ var user = {
// render
app.use(function *(){
app.use(function *() {
this.body = yield render('user', { user: user });
});

View File

@ -1,9 +1,9 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());
describe('Templates', function(){
describe('GET /', function(){
it('should respond with a rendered view', function(done){
describe('Templates', function() {
describe('GET /', function() {
it('should respond with a rendered view', function(done) {
request
.get('/')
.expect(200)

View File

@ -18,7 +18,7 @@ app.use(logger());
// custom 404
app.use(function *(next){
app.use(function *(next) {
yield next;
if (this.body || !this.idempotent) return;
this.redirect('/404.html');
@ -30,7 +30,7 @@ app.use(serve(__dirname + '/public'));
// handle uploads
app.use(function *(next){
app.use(function *(next) {
// ignore non-POSTs
if ('POST' != this.method) return yield next;

View File

@ -1,7 +1,7 @@
// rather than koa apps we can also use array
// bundles of middleware to the same effect.
function *responseTime(next){
function *responseTime(next) {
var start = new Date();
yield next;
var ms = new Date() - start;

View File

@ -1,10 +1,10 @@
var app = require('./app');
var request = require('supertest').agent(app.listen());;
describe('Virtual Host', function(){
describe('www subdomain koa app', function(){
describe('when GET /', function(){
it('should say "Hello from www app"', function(done){
describe('Virtual Host', function() {
describe('www subdomain koa app', function() {
describe('when GET /', function() {
it('should say "Hello from www app"', function(done) {
request
.get('/')
.set('Host', 'www.example.com')
@ -12,7 +12,7 @@ describe('Virtual Host', function(){
.expect('Hello from www app', done);
})
it('should set X-Custom', function(done){
it('should set X-Custom', function(done) {
request
.get('/')
.set('Host', 'www.example.com')
@ -21,8 +21,8 @@ describe('Virtual Host', function(){
})
})
describe('when GET / without subdomain', function(){
it('should say "Hello from www app"', function(done){
describe('when GET / without subdomain', function() {
it('should say "Hello from www app"', function(done) {
request
.get('/')
.set('Host', 'example.com')
@ -30,7 +30,7 @@ describe('Virtual Host', function(){
.expect('Hello from www app', done);
})
it('should set X-Custom', function(done){
it('should set X-Custom', function(done) {
request
.get('/')
.set('Host', 'example.com')
@ -39,8 +39,8 @@ describe('Virtual Host', function(){
})
})
describe('when not GET /', function(){
it('should 404', function(done){
describe('when not GET /', function() {
it('should 404', function(done) {
request
.get('/aklsjdf')
.set('Host', 'example.com')
@ -48,9 +48,9 @@ describe('Virtual Host', function(){
})
})
})
describe('bar subdomain array bundle', function(){
describe('when GET /', function(){
it('should say "Howzit? From bar middleware bundle"', function(done){
describe('bar subdomain array bundle', function() {
describe('when GET /', function() {
it('should say "Howzit? From bar middleware bundle"', function(done) {
request
.get('/')
.set('Host', 'bar.example.com')
@ -58,7 +58,7 @@ describe('Virtual Host', function(){
.expect('Howzit? From bar middleware bundle', done);
})
it('should set X-Response-Time', function(done){
it('should set X-Response-Time', function(done) {
request
.get('/')
.set('Host', 'bar.example.com')
@ -67,8 +67,8 @@ describe('Virtual Host', function(){
})
})
describe('when not GET /', function(){
it('should 404', function(done){
describe('when not GET /', function() {
it('should 404', function(done) {
request
.get('/aklsjdf')
.set('Host', 'bar.example.com')
@ -76,9 +76,9 @@ describe('Virtual Host', function(){
})
})
})
describe('default vhost', function(){
describe('when GET /', function(){
it('should 404', function(done){
describe('default vhost', function() {
describe('when GET /', function() {
it('should 404', function(done) {
request
.get('/')
.set('Host', '127.0.0.1')