test: add test codes (#20)

closes #16
This commit is contained in:
fengmk2 2016-07-18 21:16:35 +08:00 committed by GitHub
parent c87a3f66c1
commit 53a9bf4f2f
425 changed files with 7886 additions and 56 deletions

View File

@ -1,2 +1,4 @@
test/fixtures
test/benchmark
examples/**/app/public
logs
run

2
.gitignore vendored
View File

@ -12,3 +12,5 @@ run
.tmp
docs/CONTRIBUTING.md
docs/README.md
!test/fixtures/apps/loader-plugin/node_modules

View File

@ -8,4 +8,4 @@ install:
script:
- npm run ci
after_script:
- npm i codecov && codecov
- npminstall codecov && codecov

View File

@ -5,7 +5,7 @@ environment:
install:
- ps: Install-Product node $env:nodejs_version
- npm i npminstall && npminstall
- npm i npminstall && node_modules\.bin\npminstall
test_script:
- node --version

View File

@ -2,19 +2,6 @@
@startuml
digraph world {
"onerror";
"userservice";
"userrole";
"session";
"i18n";
"validate";
"watcher";
"multipart";
"security" -> "session";
"development" -> "watcher";
"rest";
"static";
"cors" -> "security";
"logrotater";
"schedule";
}
@enduml

View File

@ -0,0 +1,47 @@
'use strict';
const path = require('path');
const request = require('supertest-as-promised');
const mm = require('egg-mock');
describe('example cookie test', () => {
let app;
before(() => {
const baseDir = path.dirname(__dirname);
const customEgg = path.join(baseDir, '../..');
app = mm.app({
baseDir,
customEgg,
});
return app.ready();
});
after(() => app.close());
it('should GET / show "remember me" checkbox when cookie.remember not exists', () => {
return request(app.callback())
.get('/')
.expect(200)
.expect(/<input type="checkbox" name="remember"\/> remember me<\/label>/);
});
it('should POST /remember to set cookie.remember = 1', () => {
return request(app.callback())
.post('/remember')
.send({
remember: 'true',
})
.expect(302)
.expect('Location', '/')
.expect('Set-Cookie', /^remember=1; path=\/; expires=[^;]+; httponly,remember\.sig=[^;]+; path=\/; expires=[^;]+; httponly$/);
});
it('should GET /forget to delete cookie.remember', () => {
return request(app.callback())
.get('/forget')
.expect(302)
.expect('Location', '/')
.expect('Set-Cookie', /^remember=; path=\/; expires=[^;]+; httponly$/);
});
});

View File

@ -0,0 +1,43 @@
'use strict';
const path = require('path');
const request = require('supertest-as-promised');
const mm = require('egg-mock');
describe('example cookie_session test', () => {
let app;
let cookie;
before(() => {
const baseDir = path.dirname(__dirname);
const customEgg = path.join(baseDir, '../..');
app = mm.app({
baseDir,
customEgg,
});
return app.ready();
});
after(() => app.close());
it('should GET / first time', () => {
return request(app.callback())
.get('/')
.expect(200)
.expect(/^1 times/)
.expect('Set-Cookie', /^EGG_SESS=[^;]+; path=\/; expires=[^;]+; httponly$/)
.expect(res => {
cookie = res.headers['set-cookie'][0].split(';')[0];
});
});
it('should GET / second time', () => {
return request(app.callback())
.get('/')
.set('Cookie', cookie)
.expect(200)
.expect(/^2 times/)
// session.count change
.expect('Set-Cookie', /^EGG_SESS=[^;]+; path=\/; expires=[^;]+; httponly$/);
});
});

View File

@ -0,0 +1,35 @@
'use strict';
const path = require('path');
const request = require('supertest-as-promised');
const mm = require('egg-mock');
describe('example helloworld test', () => {
let app;
before(() => {
const baseDir = path.dirname(__dirname);
const customEgg = path.join(baseDir, '../..');
app = mm.app({
baseDir,
customEgg,
});
return app.ready();
});
after(() => app.close());
it('should GET / 200', () => {
return request(app.callback())
.get('/')
.expect(200)
.expect('Hello World');
});
it('should GET /foo', () => {
return request(app.callback())
.get('/foo')
.expect(200)
.expect('Hello foo');
});
});

View File

@ -0,0 +1,3 @@
'use strict';
exports.keys = 'my keys';

View File

@ -0,0 +1,63 @@
'use strict';
const assert = require('assert');
const path = require('path');
const request = require('supertest-as-promised');
const mm = require('egg-mock');
const formstream = require('formstream');
const urllib = require('urllib');
describe.skip('example multipart test', () => {
let app;
let csrfToken;
let cookies;
let host;
let server;
before(() => {
const baseDir = path.dirname(__dirname);
const customEgg = path.join(baseDir, '../..');
app = mm.app({
baseDir,
customEgg,
});
server = app.listen();
});
after(() => app.close());
it('should GET / show upload form', () => {
return request(server)
.get('/')
.expect(200)
.expect(/<p>Image: <input type="file" name="image" \/><\/p>/)
.expect(res => {
console.log(res.headers, res.text);
csrfToken = res.headers['x-csrf'];
cookies = res.headers['set-cookie'].join(';');
host = `http://127.0.0.1:${server.address().port}`;
});
});
it('should POST /upload success', done => {
const form = formstream();
form.file('file', __filename);
// other form fields
form.field('title', 'fengmk2 test title')
.field('love', 'egg');
const headers = form.headers();
headers.Cookie = cookies;
urllib.request(`${host}/upload?_csrf=${csrfToken}`, {
method: 'POST',
headers,
stream: form,
dataType: 'json',
}, (err, data, res) => {
assert(!err, err && err.message);
assert.equal(res.statusCode, 200);
console.log(data);
done();
});
});
});

View File

@ -1,5 +1,5 @@
'use strict';
module.exports = app => {
app.get('/', 'home');
app.get('/', app.controller.home);
};

View File

@ -0,0 +1,3 @@
'use strict';
exports.keys = 'my keys';

View File

@ -0,0 +1,35 @@
'use strict';
const path = require('path');
const request = require('supertest-as-promised');
const mm = require('egg-mock');
describe('example static test', () => {
let app;
before(() => {
const baseDir = path.dirname(__dirname);
const customEgg = path.join(baseDir, '../..');
app = mm.app({
baseDir,
customEgg,
});
return app.ready();
});
after(() => app.close());
it('should GET / 200', () => {
return request(app.callback())
.get('/')
.expect(200)
.expect(/<li>Download <a href="\/public\/hi\.txt">hi\.txt<\/a>\.<\/li>/);
});
it('should GET /public/hi.txt', () => {
return request(app.callback())
.get('/public/hi.txt')
.expect(200)
.expect('hi egg.\n你好蛋蛋。\n');
});
});

View File

@ -1,19 +1,19 @@
/**
* meta 中间件放在最前面
* meta middleware, should be the first middleware
*/
'use strict';
module.exports = function() {
module.exports = () => {
let serverId = process.env.HOSTNAME || '';
if (serverId.indexOf('-') > 0) {
// appname-90-1 => 90-1
// appname-1-1 => 1-1
serverId = serverId.split('-').slice(1).join('-');
}
return function* (next) {
return function* meta(next) {
/**
* 开始处理当前请求的时间戳单位 `ms`方便做一些时间计算
* Request start time
* @member {Number} Context#starttime
*/
this.starttime = Date.now();
@ -28,7 +28,7 @@ module.exports = function() {
this.set('X-Server-Id', serverId);
}
// 设置一个 x-readtime 头, 供 nginx access log 使用, 也方便调试
// total response time header
this.set('X-Readtime', Date.now() - this.starttime);
};
};

View File

@ -1,6 +1,6 @@
'use strict';
module.exports = function(options) {
module.exports = options => {
return function* notfound(next) {
yield next;

View File

@ -5,8 +5,8 @@
const path = require('path');
const MAX_AGE = 30 * 24 * 68 * 60;
module.exports = function fixture(options) {
return function* (next) {
module.exports = options => {
return function* siteFile(next) {
if (this.method !== 'HEAD' && this.method !== 'GET') return yield next;
if (!options.hasOwnProperty(this.path)) return yield next;

View File

@ -27,13 +27,13 @@ module.exports = {
/**
* userrole
* @member {Object} Plugin#userrole
* @property {Boolean} enable - 默认 true
* @property {Boolean} enable - `true` by default
* @since 1.0.0
*/
// userrole: {
// enable: true,
// package: 'egg-userrole',
// },
userrole: {
enable: true,
package: 'egg-userrole',
},
/**
* session
@ -63,10 +63,10 @@ module.exports = {
* @property {Boolean} enable - 默认 true
* @since 1.0.0
*/
// validate: {
// enable: true,
// package: 'egg-validate',
// },
validate: {
enable: true,
package: 'egg-validate',
},
/**
* file and dir watcher
@ -87,7 +87,7 @@ module.exports = {
*/
// multipart: {
// enable: true,
// package: '@ali/egg-multipart',
// package: 'egg-multipart',
// },
/**
@ -128,13 +128,13 @@ module.exports = {
/**
* `app/public` dir static serve
* @member {Object} Plugin#static
* @property {Boolean} enable - 默认 false
* @property {Boolean} enable - `false` by default
* @since 1.0.0
*/
// static: {
// enable: false,
// package: 'egg-static',
// },
static: {
enable: false,
package: 'egg-static',
},
/**
* CORS
@ -142,10 +142,10 @@ module.exports = {
* @property {Boolean} enable - 默认 false
* @since 1.0.0
*/
// cors: {
// enable: false,
// package: 'egg-cors',
// },
cors: {
enable: false,
package: 'egg-cors',
},
/**
* logger file rotater

View File

@ -3,18 +3,22 @@
"version": "0.0.4",
"description": "A web framework's framework for Node.js",
"dependencies": {
"egg-cluster": "*",
"egg-loader": "*",
"accepts": "^1.3.3",
"agentkeepalive": "^2.1.1",
"co": "^4.6.0",
"debug": "^2.2.0",
"delegates": "^1.0.0",
"depd": "^1.1.0",
"egg-cluster": "*",
"egg-cookies": "^1.0.0",
"egg-cors": "^0.0.2",
"egg-loader": "*",
"egg-logger": "^1.0.1",
"egg-onerror": "~0.0.2",
"egg-session": "~0.0.2",
"egg-onerror": "*",
"egg-session": "*",
"egg-static": "*",
"egg-userrole": "*",
"egg-validate": "*",
"graceful": "^1.0.0",
"humanize-ms": "^1.2.0",
"inflection": "^1.10.0",
@ -39,7 +43,8 @@
"co-sleep": "^0.0.1",
"coffee": "^3.2.2",
"egg-bin": "1",
"egg-ci": "^1.0.0",
"egg-ci": "1",
"egg-mock": "*",
"egg-plugin-puml": "1",
"eslint": "^3.0.0",
"eslint-config-egg": "^3.1.0",
@ -48,7 +53,6 @@
"glob": "^7.0.3",
"merge-descriptors": "^1.0.1",
"moment": "^2.13.0",
"node-uuid": "^1.4.7",
"once": "^1.3.3",
"pedding": "^1.0.0",
"rds": "^0.1.0",
@ -56,9 +60,7 @@
"should": "^6.0.3",
"stream-wormhole": "^1.0.0",
"supertest": "^1.2.0",
"supertest-as-promised": "^3.2.0",
"uuid": "^2.0.2",
"uuid-js": "^0.7.5"
"supertest-as-promised": "^3.2.0"
},
"main": "index.js",
"files": [
@ -67,11 +69,12 @@
"index.js"
],
"scripts": {
"lint": "eslint --fix lib test *.js",
"lint": "eslint --fix lib test examples *.js",
"test": "npm run lint && npm run test-local",
"test-local": "egg-bin test",
"test-examples": "TESTS=examples/**/test/**/*.test.js egg-bin test",
"cov": "egg-bin cov",
"ci": "node -v && npm run lint && npm run cov",
"ci": "npm run lint && npm run test-examples && npm run cov",
"autod": "autod",
"doc": "./scripts/doc.sh",
"puml": "puml . --dest ./docs",

54
test/benchmark/assign.js Normal file
View File

@ -0,0 +1,54 @@
'use strict';
const Benchmark = require('benchmark');
const benchmarks = require('beautify-benchmark');
const utils = require('../../lib/util');
new Benchmark.Suite()
.add('Object.assign', () => {
const a = {};
const b = { a: 1, b: 2, c: 3, d: 4, e: 5 };
Object.assign(a, b);
})
.add('for in', () => {
const a = {};
const b = { a: 1, b: 2, c: 3, d: 4, e: 5 };
for (const key in b) {
a[key] = b[key];
}
})
.add('Object.keys', () => {
const a = {};
const b = { a: 1, b: 2, c: 3, d: 4, e: 5 };
const keys = Object.keys(b);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
a[key] = b[key];
}
})
.add('utils.assign', () => {
const a = {};
const b = { a: 1, b: 2, c: 3, d: 4, e: 5 };
utils.assign(a, b);
})
.on('cycle', event => {
benchmarks.add(event.target);
})
.on('start', () => {
console.log('\n node version: %s, date: %s\n Starting...',
process.version, Date());
})
.on('complete', () => {
benchmarks.log();
process.exit(0);
})
.run({ async: false });
// node version: v4.2.3, date: Tue Jan 26 2016 16:52:46 GMT+0800 (CST)
// Starting...
// 4 tests completed.
//
// Object.assign x 646,034 ops/sec ±1.61% (86 runs sampled)
// for in x 2,754,639 ops/sec ±1.21% (88 runs sampled)
// Object.keys x 3,590,226 ops/sec ±1.04% (93 runs sampled)
// utils.assign x 3,192,343 ops/sec ±0.69% (93 runs sampled)

View File

@ -0,0 +1,9 @@
'use strict';
module.exports = agent => {
agent.startAgent({
name: 'test',
client: { ready: cb => cb() },
subscribe: (info, cb) => cb('test'),
});
};

View File

@ -0,0 +1,14 @@
'use strict';
module.exports = app => {
const done = app.readyCallback();
const test = app.createAppWorkerClient('test', {
listen(cb) {
this._subscribe('listening', cb);
},
});
test.listen(arg => {
app.arg = arg;
done();
})
};

View File

@ -0,0 +1,7 @@
'use strict';
module.exports = app => {
app.get('/', function*() {
this.body = this.app.arg;
})
};

View File

@ -0,0 +1,3 @@
{
"name": "agent-app-sync"
}

11
test/fixtures/apps/agent-app/app.js vendored Normal file
View File

@ -0,0 +1,11 @@
'use strict';
module.exports = app => {
const done = app.readyCallback('foo');
app.mockClient.subscribe({
id: 'foo'
}, value => {
app.foo = value;
done();
});
};

View File

@ -0,0 +1,25 @@
module.exports = app => {
app.get('/', function*() {
this.body = 'ok';
});
app.get('/getData', function*() {
this.body = yield app.mockClient.getData();
});
app.get('/getError', function*() {
try {
yield app.mockClient.getError();
} catch (err) {
this.body = err.message;
}
});
app.get('/getDataGenerator', function* () {
this.body = yield app.mockClient.getDataGenerator();
})
app.get('/sub', function*() {
this.body = app.foo;
});
};

View File

@ -0,0 +1,10 @@
'use strict';
const path = require('path');
module.exports = {
mock: {
enable: true,
path: path.join(__dirname, '../plugins/mock-client'),
},
};

View File

@ -0,0 +1,3 @@
{
"name": "agent-app"
}

View File

@ -0,0 +1,29 @@
'use strict';
const MockClient = require('./mock_client');
module.exports = agent => {
const done = agent.readyCallback('agent_configclient');
const options = agent.config.mock;
agent.mockClient = new MockClient();
// 启动 agent 任务
agent.startAgent({
client: agent.mockClient,
name: 'mock',
subscribe: function(info, listener) {
agent.mockClient.on(info.id, listener);
if (info.id === 'foo') {
setTimeout(function() {
agent.mockClient.emit('foo', 'bar');
}, 100);
}
},
});
agent.mockClient.ready(() => {
agent.logger.info('[agent] %s started mockClient', agent.config.name);
done();
});
};

View File

@ -0,0 +1,28 @@
'use strict';
module.exports = app => {
const options = app.config.mock;
app.mockClient = app.createAppWorkerClient('mock', {
subscribe: function(reg, listner) {
this._subscribe(reg, listner);
return this;
},
* getData(id) {
return yield this._invoke('getData', [id]);
},
* getError() {
return yield this._invoke('getError', []);
},
* getDataGenerator(id) {
return yield this._invoke('getDataGenerator', [id]);
},
}, options);
app.mockClient.ready(app.readyCallback('worker_mock_client'), {
isWeakDep: app.config.runMode === 0,
});
};

View File

@ -0,0 +1,9 @@
'use strict';
module.exports = () => {
return {
mock: {
name: 'mock',
},
};
}

View File

@ -0,0 +1,65 @@
'use strict';
const EventEmitter = require('events').EventEmitter;
const sleep = require('co-sleep');
class MockClient extends EventEmitter {
constructor(options) {
super();
setImmediate(function() {
this.ready(true);
}.bind(this));
}
ready(flagOrFunction) {
this._ready = !!this._ready;
this._readyCallbacks = this._readyCallbacks || [];
if (typeof flagOrFunction === 'function') {
this._readyCallbacks.push(flagOrFunction);
} else {
this._ready = !!flagOrFunction;
}
if (this._ready) {
this._readyCallbacks.splice(0, Infinity).forEach(function(callback) {
process.nextTick(callback);
});
}
return this;
}
getCallback(id, callback) {
setTimeout(function() {
if (id === 'error') {
callback(new Error('mock error'));
} else {
callback(null, 'mock data');
}
}, 100);
}
getData() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve('mock data');
}, 100);
});
}
* getDataGenerator() {
yield sleep(100);
return 'mock data';
}
getError() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
reject(new Error('mock error'));
}, 100);
});
}
}
module.exports = MockClient;

4
test/fixtures/apps/agent-die/agent.js vendored Normal file
View File

@ -0,0 +1,4 @@
setTimeout(() => {
throw new Error('app worker throw');
}, 5000);

View File

@ -0,0 +1,3 @@
{
"name": "agent-die"
}

13
test/fixtures/apps/agent-die/start.js vendored Normal file
View File

@ -0,0 +1,13 @@
'use strict';
const utils = require('../../../utils');
require('../../../../index').startCluster({
baseDir: __dirname,
workers: 1
})
setTimeout(() => {
process.exit();
// coverage will be slow
}, 5000);

View File

@ -0,0 +1,10 @@
'use strict';
module.exports = agent => {
const done = agent.readyCallback('custom-agent-ready')
const ins = agent.instrument('http', `/hello`);
setTimeout(() => {
ins.end();
done();
}, 500);
}

View File

@ -0,0 +1,3 @@
{
"name": "agent-instrument"
}

View File

@ -0,0 +1,17 @@
'use strict';
const client = require('./client');
module.exports = agent => {
agent.startAgent({
name: 'mock',
client: client,
subscribe: function(reg, listener) {
console.log('agent subscribe', reg);
},
});
agent.messenger.on('die', () => {
process.exit(1);
});
};

14
test/fixtures/apps/agent-restart/app.js vendored Normal file
View File

@ -0,0 +1,14 @@
'use strict';
const client = require('./client');
module.exports = app => {
const mock = app.createAppWorkerClient('mock', {
subscribe: function(info, listener) {
this._subscribe(info, listener);
return this;
},
});
mock.subscribe('aaa', data => console.log(data));
};

View File

@ -0,0 +1,3 @@
module.exports = {
ready: cb => cb(),
};

View File

@ -0,0 +1,3 @@
{
"name": "agent-restart"
}

View File

@ -0,0 +1,7 @@
'use strict';
module.exports = agent => {
agent.messenger.on('agent-throw', () => {
throw new Error('agent error');
});
};

View File

@ -0,0 +1,8 @@
'use strict';
module.exports = app => {
app.get('/agent-throw', function*() {
app.messenger.broadcast('agent-throw');
this.body = 'done';
});
};

View File

@ -0,0 +1 @@
exports.keys = 'foo';

View File

@ -0,0 +1,3 @@
{
"name": "agent-throw"
}

View File

@ -0,0 +1,9 @@
'use strict';
module.exports = function*() {
this.body = {
'aliyun-egg-core': !!this.app['aliyun-egg'],
'aliyun-egg-plugin': !!this.app.custom,
'aliyun-egg-agent': !!this.app.agent,
}
};

View File

@ -0,0 +1,5 @@
'use strict';
module.exports = app => {
app.get('/', app.controller.home);
};

View File

@ -0,0 +1 @@
exports.keys = 'foo';

View File

@ -0,0 +1,3 @@
{
"name": "aliyun-egg-app"
}

View File

@ -0,0 +1,3 @@
'use strict';
module.exports = require('../aliyun-egg');

View File

@ -0,0 +1,3 @@
{
"name": "aliyun-egg-biz"
}

View File

@ -0,0 +1,7 @@
'use strict';
const egg = require('../../../..');
module.exports = egg;
module.exports.Application = require('./lib/aliyun-egg');
module.exports.Agent = require('./lib/agent');

View File

@ -0,0 +1,19 @@
'use strict';
const path = require('path');
const egg = require('../../../../..');
const Agent = egg.Agent;
const AppWorkerLoader = egg.AppWorkerLoader;
class MyAgent extends Agent {
constructor(options) {
super(options);
}
get [Symbol.for('egg#eggPath')]() {
return path.join(__dirname, '..');
}
}
module.exports = MyAgent;

View File

@ -0,0 +1,37 @@
'use strict';
const path = require('path');
const egg = require('../../../../..');
const Application = egg.Application;
const AppWorkerLoader = egg.AppWorkerLoader;
class Loader extends AppWorkerLoader {
constructor(options) {
super(options);
}
loadConfig() {
this.loadServerConf();
super.loadConfig();
}
loadServerConf() {}
}
class ChairApplication extends Application {
constructor(options) {
super(options);
}
get [Symbol.for('egg#eggPath')]() {
return path.join(__dirname, '..');
}
get [Symbol.for('egg#loader')]() {
return Loader;
}
}
module.exports = ChairApplication;

View File

@ -0,0 +1,5 @@
'use strict';
module.exports = agent => {
};

View File

@ -0,0 +1,5 @@
'use strict';
module.exports = app => {
app['aliyun-egg'] = {};
};

View File

@ -0,0 +1,10 @@
'use strict';
const path = require('path');
module.exports = {
custom: {
enable: true,
path: path.join(__dirname, '../../plugins/custom'),
},
};

View File

@ -0,0 +1,7 @@
'use strict';
module.exports = agent => {
agent.messenger.on('custom-aliyun-egg-worker', data => {
agent.messenger.broadcast('custom-aliyun-egg-agent', data);
})
};

View File

@ -0,0 +1,9 @@
'use strict';
module.exports = app => {
app.custom = {};
app.messenger.broadcast('custom-aliyun-egg-worker', 123);
app.messenger.on('custom-aliyun-egg-agent', data => {
app.agent = data;
})
};

View File

@ -0,0 +1,3 @@
{
"name": "aliyun-egg"
}

View File

@ -0,0 +1,13 @@
'use strict';
module.exports = app => {
app.get('/exit', function*() {
process.exit(1);
});
app.get('/uncaughtException', function*() {
setTimeout(() => {
throw new Error('get uncaughtException');
}, 100);
});
};

View File

@ -0,0 +1 @@
exports.keys = 'foo';

View File

@ -0,0 +1,3 @@
{
"name": "app-die"
}

View File

@ -0,0 +1,3 @@
module.exports = function* () {
this.body = 'hello';
};

View File

@ -0,0 +1,4 @@
module.exports = app => {
app.get('home', '/', 'home');
app.get('/home', app.controller.home);
};

View File

@ -0,0 +1,3 @@
{
"name": "app-router"
}

7
test/fixtures/apps/app-server/app.js vendored Normal file
View File

@ -0,0 +1,7 @@
'use strict';
module.exports = app => {
app.on('server', server => {
app.serverEmit = true;
});
};

View File

@ -0,0 +1,5 @@
module.exports = app => {
app.get('/', function* () {
this.body = this.app.serverEmit;
});
};

View File

@ -0,0 +1 @@
exports.keys = 'my keys';

View File

@ -0,0 +1,3 @@
{
"name": "app-server"
}

View File

@ -0,0 +1,19 @@
module.exports = app => {
app.get('/test/body_parser/user', function* () {
this.body = {
url: this.url,
csrf: this.csrf
};
});
app.post('/test/body_parser/user', function* () {
this.body = this.request.body;
});
app.post('/test/body_parser/foo.json', function* () {
this.body = this.request.body;
});
app.post('/test/body_parser/form.json', function* () {
this.body = this.request.body;
});
};

View File

@ -0,0 +1,7 @@
exports.bodyParser = {
queryString: {
arrayLimit: 5
}
};
exports.keys = 'foo';

View File

@ -0,0 +1,3 @@
{
"name": "body_parser_testapp"
}

View File

@ -0,0 +1 @@
exports.keys = 'foo';

View File

@ -0,0 +1,2 @@
exports.logrotater = false;
exports.watcher = false;

View File

@ -0,0 +1,3 @@
{
"name": "close-watcher-logrotator"
}

View File

@ -0,0 +1,5 @@
'use strict';
exports.index = function* () {
this.body = 'hi cluster';
};

View File

@ -0,0 +1,5 @@
'use strict';
module.exports = app => {
app.get('/', app.controller.home.index);
};

View File

@ -0,0 +1 @@
exports.keys = 'foo';

View File

@ -0,0 +1,3 @@
{
"name": "cluster_mod_app"
}

View File

@ -0,0 +1,6 @@
module.exports = {
foo: 1,
bar: function() {
return 2;
}
};

View File

@ -0,0 +1,18 @@
'use strict';
exports.index = function* () {
this.body = {
path: this.router.pathFor('home'),
foo: this.foo,
bar: this.bar()
};
};
exports.runtime = function* () {
this.runtime.mysql = 10;
this.runtime.foo = 11;
this.body = {
mysql: this.runtime.mysql,
foo: this.runtime.foo
};
};

View File

@ -0,0 +1,4 @@
module.exports = app => {
app.get('home', '/', 'home.index');
app.get('runtime', '/runtime', 'home.runtime');
};

View File

@ -0,0 +1,5 @@
exports.security = {
csrf: false
}
exports.keys = 'foo';

View File

@ -0,0 +1,5 @@
'use stirct';
exports.logger = {
stdoutLevel: 'NONE',
};

View File

@ -0,0 +1,3 @@
{
"name": "context-config-app"
}

13
test/fixtures/apps/cors/app/router.js vendored Normal file
View File

@ -0,0 +1,13 @@
module.exports = app => {
app.get('/', function*() {
this.body = {
foo: 'bar'
};
});
app.post('/', function*() {
this.body = {
foo: 'bar'
};
});
};

View File

@ -0,0 +1,3 @@
exports.cors = {
credentials: true,
};

View File

@ -0,0 +1 @@
exports.cors = true;

3
test/fixtures/apps/cors/package.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"name": "cors"
}

View File

@ -0,0 +1,9 @@
'use strict';
module.exports = app => {
app.get('/', function*() {
this.body = {
env: this.app.config.env,
};
});
};

View File

@ -0,0 +1,3 @@
'use strict';
exports.keys = 'foo';

View File

@ -0,0 +1,3 @@
{
"name": "custom-env-app"
}

View File

@ -0,0 +1,14 @@
'use strict';
const path = require('path');
module.exports = info => {
return {
customLogger: {
myLogger: {
file: path.join(info.baseDir, 'logs/my.log'),
formatter: meta => meta.message,
},
},
};
};

View File

@ -0,0 +1,3 @@
{
"name": "custom-logger"
}

View File

@ -0,0 +1,6 @@
'use strict';
module.exports = function*() {
this.setCookie('hi', 'foo');
this.body = 'hello';
};

View File

@ -0,0 +1,5 @@
module.exports = function* () {
this.body = {
workerTitle: process.title
};
};

View File

@ -0,0 +1,17 @@
'use strict';
module.exports = function*() {
const message = this.query.message;
this.logger.debug('debug %s', message);
this.logger.info('info %s', message);
this.logger.warn('warn %s', message);
this.logger.error(new Error('error ' + message));
this.coreLogger.debug('core debug %s', message);
this.coreLogger.info('core info %s', message);
this.coreLogger.warn('core warn %s', message);
this.coreLogger.error(new Error('core error ' + message));
this.body = 'logger';
};

12
test/fixtures/apps/demo/app/router.js vendored Normal file
View File

@ -0,0 +1,12 @@
module.exports = app => {
app.get('home', '/', 'home');
app.get('/hello', app.controller.hello);
app.get('/logger', app.controller.logger);
app.get('/protocol', function*() {
this.body = this.protocol;
});
app.get('/user.json', function*() {
this.jsonp = { name: 'fengmk2' };
});
};

View File

@ -0,0 +1,2 @@
exports.keys = 'foo';
exports.protocolHeaders = 'X-Forwarded-Proto';

3
test/fixtures/apps/demo/package.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"name": "demo"
}

Some files were not shown because too many files have changed in this diff Show More