0.6.1 • Published 5 years ago

koa-mocks v0.6.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

koa-mocks

koa2/express mock middleware

install

yarn add koa-mocks

init

node_modules/.bin/mock init

use

const koaMocks = require('koa-mocks')
app.use(koaMocks(config))

Parameter Description

  • config.basePath [string] The root directory of mock - default process.cwd()
  • config.routeFile [string] Mock routing file - default config.basePath + 'route.js'
  • config.staticFolder [string] Mock static file address - default config.basePath + 'static'
  • config.express [boolean] is whether use express - default false

route.js Explain

Example

[method]::<url> : <type>::<file>

module.exports = {
  'post::/test': 'mock::test.js',
  'get::/test2': 'mock::test.json',
  '/lock':'file::lock.png',
  '/baidu':'url::https://www.baidu.com'
}

Parameter description

  • method default get support any method and all
  • url Address of mock
  • type Type of mock - mock - file - url

test.js Explain

module.exports = function(req, res, utils) {
  return {
    "data": utils.random([111,222,333])
  }
}
  • req request Object
  • utils tool
    • utils.random() Random fetch of a data in an array

test.json Explain

{
	"$$statusCode":400,
	"$$delay":3000,
	"data":"111"
}
  • $$statusCode default 200
  • $$delay delay time default 0

TO DO LIST

0.6.1

5 years ago

0.6.0

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago