thrift-mock
Mock response data from thrift idl files.
Main Features
- Customize module.exports template. (the mock data MUST using '@@dataPlaceholder' as its placeholder)
- Method extends.
Config & Execute
const mock = ; const config = service: require require /* require.resolve('./idl/CommonService.thrift'),*/ /* require.resolve('./idl/BaseService.thrift'),*/ /* require.resolve('./idl/ExtendsService.thrift'),*/ /* require.resolve('./idl/GrandExtendsService.thrift'),*/ /* require.resolve('./idl/CustomizedTypeService.thrift'),*/ output: path: path exportsTemplate: statusCode: 200 body: data: '@@dataPlaceholder' ; ;
Source
idl directory structure
idl├── a│ ├── accountVo.thrift│ ├── pageVo.thrift│ └── request.thrift├── aService.thrift├── b│ ├── changeVo.thrift│ ├── request.thrift│ └── stepVo.thrift├── bService.thrift└── exception.thrift
aService's methods and modals
// aService.thrift
Output
It will output each thrift method with a mock file, which contains a mockjs template. You can then custom the properties as you need.
The mocked method's filepath as follows:
${config.output.path}/${serviceName}/${methodName}.js
Demo output tree structure:
mockapi├── AService│ └── search.js└── BService ├── getStep.js └── submit.js
mockapi/Aservice/search.js 's content:
const mock = ; const body = ;moduleexports = statusCode: 200 body ;
TODO
- add unit test.
- add args judgement(args' type & count) by api property:
args
. - mock data more real.