0.1.15 • Published 7 years ago

n-mocker v0.1.15

Weekly downloads
19
License
ISC
Repository
github
Last release
7 years ago

Node-Mocker

npm.io

mock service and http api with nodejs.

Features

  • js config file,modify and effective
  • mock services
  • mock http api power by koa2

Requirements

  • Node v6.0+

config

module.exports = (log) => ({ //log inner mock server
  services: {  // mock service
    key: 4, // return number
    say(word) {
      log('sayaaa');
      return `hello1 ${word}!`;
    },
    promiseTest(n, k) { // return Promise
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve(n + k);
        }, 10);
      });
    },
    say2(word) {
      throw Error('say2 Error!');
    },
  },
  proxyServers: [ // mock http,each will start a http server
    {
      port: 8081,
      routes: {
        '[GET]/api/shops/:shopId': { // return a object
          a: 'a',
          b: 'b'
        },
        '[GET]/api/items/:itemId': (ctx) => { // or a function
          ctx.body = ctx.params.itemId;
        },
      },
    },
    {
      port: 8082,
      routes: {
        '[GET]/api/test': {
          c: 'c',
          d: 'd',
          e: 'e'
        },
        '[GET]/api/site': (ctx) => {
          ctx.body = `siteId111:${ctx.query.id}`;
        }
      },
    },
  ]
});

Use

npm i n-mocker
 const mocker = new Mock(path.resolve(process.cwd(), 'config-file.js'));  
 await mocker.start();

Workflow

  • npm install
  • npm run test
0.1.15

7 years ago

0.1.14

8 years ago

0.1.13

9 years ago

0.1.12

9 years ago

0.1.11

9 years ago

0.1.10

9 years ago

0.1.9

9 years ago

0.1.8

9 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago