feat(mock): use koa-mock for front end dev
demo:  Closes #509
This commit is contained in:
3
.node-dev.json
Normal file
3
.node-dev.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"notify": false
|
||||
}
|
||||
@@ -21,3 +21,4 @@ config/web_readme.md
|
||||
.dist/
|
||||
config/config.js
|
||||
*.sqlite
|
||||
.node-dev.json
|
||||
|
||||
2
Makefile
2
Makefile
@@ -87,7 +87,7 @@ test-travis-mysql: init-mysql
|
||||
test-travis-all: test-travis-sqlite test-travis-mysql
|
||||
|
||||
dev:
|
||||
@node_modules/.bin/node-dev --harmony dispatch.js
|
||||
@NODE_ENV=development node_modules/.bin/node-dev --harmony dispatch.js
|
||||
|
||||
contributors: install
|
||||
@node_modules/.bin/contributors -f plain -o AUTHORS
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
"contributors": "*",
|
||||
"istanbul-harmony": "*",
|
||||
"jshint": "*",
|
||||
"koa-mock": "^1.0.2",
|
||||
"mm": "*",
|
||||
"mocha": "*",
|
||||
"node-dev": "*",
|
||||
|
||||
@@ -39,6 +39,12 @@ app.use(middlewares.rt({headerName: 'X-ReadTime'}));
|
||||
app.use(middlewares.rewrite('/favicon.ico', '/favicon.png'));
|
||||
app.use(staticCache);
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
app.use(require('koa-mock')({
|
||||
datadir: path.join(rootdir, 'test', 'mocks')
|
||||
}));
|
||||
}
|
||||
|
||||
app.use(opensearch);
|
||||
app.keys = ['todokey', config.sessionSecret];
|
||||
app.proxy = true;
|
||||
|
||||
118
test/mocks/package/koa/default.js
Normal file
118
test/mocks/package/koa/default.js
Normal file
@@ -0,0 +1,118 @@
|
||||
module.exports = {
|
||||
title: 'Package - koa',
|
||||
package: {
|
||||
name: 'koa',
|
||||
version: '0.13.0',
|
||||
description: 'description: Koa web app framework',
|
||||
registryUrl: 'https://registry.npm.taobao.org/koa',
|
||||
engines: {
|
||||
node: {
|
||||
version: '>= 0.11.13',
|
||||
title: 'node: >=0.11.13',
|
||||
badgeURL: 'https://img.shields.io/badge/node-%3E%3D%200.11.13-red.svg?style=flat-square',
|
||||
}
|
||||
},
|
||||
_publish_on_cnpm: false,
|
||||
preferGlobal: false,
|
||||
fromNow: 'a month ago',
|
||||
lastPublishedUser: {
|
||||
name: 'dead-horse'
|
||||
},
|
||||
license: {
|
||||
name: 'MIT',
|
||||
},
|
||||
repository: {
|
||||
weburl: 'http://npm.taobao.org/package/koa',
|
||||
},
|
||||
bugs: {
|
||||
url: 'https://github.com/koajs/koa/issues'
|
||||
},
|
||||
dependencies: {
|
||||
accepts: '^1.1.0',
|
||||
co: '^3.1.0',
|
||||
'content-disposition': '~0.3.0',
|
||||
cookies: '~0.5.0',
|
||||
debug: '*',
|
||||
delegates: '0.0.3',
|
||||
destroy: '^1.0.3',
|
||||
'error-inject': '~1.0.0',
|
||||
'escape-html': '~1.0.1',
|
||||
fresh: '~0.2.1',
|
||||
'http-assert': '^1.0.1',
|
||||
'http-errors': '^1.2.0',
|
||||
'koa-compose': '^2.3.0',
|
||||
'koa-is-json': '^1.0.0',
|
||||
'media-typer': '~0.3.0',
|
||||
'mime-types': '^2.0.0',
|
||||
'on-finished': '^2.1.0',
|
||||
only: '0.0.2',
|
||||
parseurl: '^1.3.0',
|
||||
statuses: '^1.1.0',
|
||||
'type-is': '^1.5.0',
|
||||
vary: '^1.0.0'
|
||||
},
|
||||
devDependencies: {
|
||||
'istanbul-harmony': '~0.3.0',
|
||||
'make-lint': '^1.0.1',
|
||||
mocha: '^1.17.0',
|
||||
should: '^3.1.0',
|
||||
supertest: '~0.13.0',
|
||||
'test-console': '^0.7.1'
|
||||
},
|
||||
maintainers: [
|
||||
{
|
||||
name: 'fengmk2',
|
||||
gravatar: 'https://secure.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=50&d=retro',
|
||||
},
|
||||
{
|
||||
name: 'jongleberry',
|
||||
gravatar: 'https://secure.gravatar.com/avatar/6e33cc0412b61cc01daac23c8989003c?s=50&d=retro',
|
||||
},
|
||||
{
|
||||
name: 'dead_horse',
|
||||
gravatar: 'https://secure.gravatar.com/avatar/2e7cc21dde5f4e944eefff64bde07136?s=50&d=retro',
|
||||
},
|
||||
{
|
||||
name: 'fengmk2',
|
||||
gravatar: 'https://secure.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=50&d=retro',
|
||||
},
|
||||
{
|
||||
name: 'jongleberry',
|
||||
gravatar: 'https://secure.gravatar.com/avatar/6e33cc0412b61cc01daac23c8989003c?s=50&d=retro',
|
||||
},
|
||||
{
|
||||
name: 'dead_horse',
|
||||
gravatar: 'https://secure.gravatar.com/avatar/2e7cc21dde5f4e944eefff64bde07136?s=50&d=retro',
|
||||
},
|
||||
{
|
||||
name: 'fengmk2',
|
||||
gravatar: 'https://secure.gravatar.com/avatar/95b9d41231617a05ced5604d242c9670?s=50&d=retro',
|
||||
},
|
||||
{
|
||||
name: 'jongleberry',
|
||||
gravatar: 'https://secure.gravatar.com/avatar/6e33cc0412b61cc01daac23c8989003c?s=50&d=retro',
|
||||
},
|
||||
{
|
||||
name: 'dead_horse',
|
||||
gravatar: 'https://secure.gravatar.com/avatar/2e7cc21dde5f4e944eefff64bde07136?s=50&d=retro',
|
||||
},
|
||||
],
|
||||
readme: readme(),
|
||||
},
|
||||
download: {
|
||||
today: 100,
|
||||
thisweek: 700,
|
||||
thismonth: 3000,
|
||||
lastday: 100,
|
||||
lastweek: 800,
|
||||
lastmonth: 4000,
|
||||
},
|
||||
__view: 'package'
|
||||
};
|
||||
|
||||
function readme() {
|
||||
var marked = require('marked');
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
return marked(fs.readFileSync(path.join(__dirname, 'readme.md'), 'utf8'));
|
||||
}
|
||||
6
test/mocks/package/koa/deprecated.js
Normal file
6
test/mocks/package/koa/deprecated.js
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
package: {
|
||||
deprecated: 'This package has been deprecated.',
|
||||
},
|
||||
__requires: ['./default']
|
||||
};
|
||||
7
test/mocks/package/koa/no-bugs.js
Normal file
7
test/mocks/package/koa/no-bugs.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
package: {
|
||||
name: 'no-bugs',
|
||||
bugs: null,
|
||||
},
|
||||
__requires: ['./default']
|
||||
};
|
||||
7
test/mocks/package/koa/no-license.js
Normal file
7
test/mocks/package/koa/no-license.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
package: {
|
||||
name: 'no-license',
|
||||
license: null,
|
||||
},
|
||||
__requires: ['./default']
|
||||
};
|
||||
6
test/mocks/package/koa/no-readme.js
Normal file
6
test/mocks/package/koa/no-readme.js
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
package: {
|
||||
readme: '',
|
||||
},
|
||||
__requires: ['./default']
|
||||
};
|
||||
7
test/mocks/package/koa/no-repository.js
Normal file
7
test/mocks/package/koa/no-repository.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
package: {
|
||||
name: 'koa',
|
||||
repository: null,
|
||||
},
|
||||
__requires: ['./default']
|
||||
};
|
||||
6
test/mocks/package/koa/preferGlobal-true.js
Normal file
6
test/mocks/package/koa/preferGlobal-true.js
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
package: {
|
||||
preferGlobal: true,
|
||||
},
|
||||
__requires: ['./default']
|
||||
};
|
||||
7
test/mocks/package/koa/private-package.js
Normal file
7
test/mocks/package/koa/private-package.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
package: {
|
||||
name: '@fengmk2/fs',
|
||||
_publish_on_cnpm: true,
|
||||
},
|
||||
__requires: ['./default']
|
||||
};
|
||||
99
test/mocks/package/koa/readme.md
Normal file
99
test/mocks/package/koa/readme.md
Normal file
@@ -0,0 +1,99 @@
|
||||
<img src="https://dl.dropboxusercontent.com/u/6396913/koa/logo.png" alt="koa middleware framework for nodejs" width="255px" />
|
||||
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![build status][travis-image]][travis-url]
|
||||
[![Test coverage][coveralls-image]][coveralls-url]
|
||||
|
||||
[![gitter][gitter-image]][gitter-url]
|
||||
|
||||
Expressive middleware for node.js using generators via [co](https://github.com/visionmedia/co)
|
||||
to make web applications and APIs more enjoyable to write. Koa's middleware flow in a stack-like manner allowing you to perform actions downstream, then filter and manipulate the response upstream. Koa's use of generators also greatly increases the readability and robustness of your application.
|
||||
|
||||
Only methods that are common to nearly all HTTP servers are integrated directly into Koa's small ~550 SLOC codebase. This
|
||||
includes things like content-negotiation, normalization of node inconsistencies, redirection, and a few others.
|
||||
|
||||
No middleware are bundled with koa. If you prefer to only define a single dependency for common middleware, much like Connect, you may use
|
||||
[koa-common](https://github.com/koajs/common).
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
$ npm install koa
|
||||
```
|
||||
|
||||
To use Koa you must be running __node 0.11.9__ or higher for generator support, and must run node(1)
|
||||
with the `--harmony` flag. If you don't like typing this, add an alias to your shell profile:
|
||||
|
||||
```
|
||||
alias node='node --harmony'
|
||||
```
|
||||
|
||||
## Community
|
||||
|
||||
- [API](docs/api/index.md) documentation
|
||||
- [Badgeboard](https://koajs.github.io/badgeboard) and list of official modules
|
||||
- [Examples](https://github.com/koajs/examples)
|
||||
- [Middleware](https://github.com/koajs/koa/wiki) list
|
||||
- [Wiki](https://github.com/koajs/koa/wiki)
|
||||
- [G+ Community](https://plus.google.com/communities/101845768320796750641)
|
||||
- [Reddit Community](http://reddit.com/r/koajs)
|
||||
- [Mailing list](https://groups.google.com/forum/#!forum/koajs)
|
||||
- [Guide](docs/guide.md)
|
||||
- [FAQ](docs/faq.md)
|
||||
- [中文文档](http://koajs.cn/)
|
||||
- __#koajs__ on freenode
|
||||
|
||||
## Getting started
|
||||
|
||||
- [kick-off-koa](https://github.com/koajs/kick-off-koa) - An intro to koa via a set of self-guided workshops.
|
||||
- [workshop](https://github.com/koajs/workshop) - A workshop to learn the basics of koa, Express' spiritual successor.
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
var koa = require('koa');
|
||||
var app = koa();
|
||||
|
||||
// logger
|
||||
|
||||
app.use(function *(next){
|
||||
var start = new Date;
|
||||
yield next;
|
||||
var ms = new Date - start;
|
||||
console.log('%s %s - %s', this.method, this.url, ms);
|
||||
});
|
||||
|
||||
// response
|
||||
|
||||
app.use(function *(){
|
||||
this.body = 'Hello World';
|
||||
});
|
||||
|
||||
app.listen(3000);
|
||||
```
|
||||
|
||||
## Running tests
|
||||
|
||||
```
|
||||
$ make test
|
||||
```
|
||||
|
||||
## Authors
|
||||
|
||||
- [TJ Holowaychuk](https://github.com/tj)
|
||||
- [Jonathan Ong](https://github.com/jonathanong)
|
||||
- [Julian Gruber](https://github.com/juliangruber)
|
||||
- [Yiyu He](https://github.com/dead-horse)
|
||||
|
||||
# License
|
||||
|
||||
MIT
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/koa.svg?style=flat-square
|
||||
[npm-url]: https://npmjs.org/package/koa
|
||||
[travis-image]: https://img.shields.io/travis/koajs/koa/master.svg?style=flat-square
|
||||
[travis-url]: https://travis-ci.org/koajs/koa
|
||||
[coveralls-image]: https://img.shields.io/coveralls/koajs/koa/master.svg?style=flat-square
|
||||
[coveralls-url]: https://coveralls.io/r/koajs/koa?branch=master
|
||||
[gitter-image]: https://badges.gitter.im/Join%20Chat.svg
|
||||
[gitter-url]: https://gitter.im/koajs/koa?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
||||
6
test/mocks/package/koa/very-long-name.js
Normal file
6
test/mocks/package/koa/very-long-name.js
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
package: {
|
||||
name: 'inch-plugin-socket-behaviour-desktop',
|
||||
},
|
||||
__requires: ['./default']
|
||||
};
|
||||
Reference in New Issue
Block a user