mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
feat: 优化plugin-mock
1. Mock更名为mockjs 2. file功能从cgiMock中抽取到utils中
This commit is contained in:
parent
20bd23acb7
commit
16aa19f08a
@ -3,7 +3,7 @@ import { resolve } from 'path';
|
||||
import { chokidar, lodash } from '@umijs/utils';
|
||||
import bodyParser from 'body-parser';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import Mock from 'mockjs';
|
||||
import mockjs from 'mockjs';
|
||||
|
||||
export default (api) => {
|
||||
let mockFlag = false; // mock 开关flag
|
||||
@ -76,7 +76,9 @@ export default (api) => {
|
||||
if (!option.url || !option.result) return;
|
||||
requestList.push(option);
|
||||
};
|
||||
cgiMock.file = function (file) {
|
||||
|
||||
const utils = {};
|
||||
utils.file = function (file) {
|
||||
return readFileSync(parsePath(file));
|
||||
};
|
||||
|
||||
@ -98,9 +100,9 @@ export default (api) => {
|
||||
if (!lodash.isFunction(projectMock)) {
|
||||
api.logger.info('mock.js should export Function'); return;
|
||||
}
|
||||
projectMock({ cgiMock, Mock });
|
||||
projectMock({ cgiMock, mockjs, utils });
|
||||
} catch (err) {
|
||||
api.logger.info('mock.js run fail!');
|
||||
api.logger.error('mock.js run fail!');
|
||||
}
|
||||
|
||||
return (req, res, next) => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
module.exports = ({ cgiMock, Mock }) => {
|
||||
const { Random } = Mock;
|
||||
module.exports = function ({ cgiMock, mockjs, utils }) {
|
||||
const { Random } = mockjs;
|
||||
|
||||
// 测试 proxy 与 mock 用例集合
|
||||
cgiMock('/movie/in_theaters_mock', (req, res) => {
|
||||
@ -48,7 +48,7 @@ module.exports = ({ cgiMock, Mock }) => {
|
||||
cgiMock('/text', Random.cparagraph());
|
||||
|
||||
// 返回一个字符串 利用 mock.js 产生随机字符
|
||||
cgiMock('/random', Mock.mock({
|
||||
cgiMock('/random', mockjs.mock({
|
||||
'string|1-10': '★'
|
||||
}));
|
||||
|
||||
@ -61,7 +61,7 @@ module.exports = ({ cgiMock, Mock }) => {
|
||||
});
|
||||
|
||||
// 返回文本 readFileSync
|
||||
cgiMock('/file', cgiMock.file('./package.json'));
|
||||
cgiMock('/file', utils.file('./package.json'));
|
||||
|
||||
// 更复杂的规则配置
|
||||
cgiMock({
|
||||
|
@ -7,7 +7,9 @@
|
||||
<link rel="shortcut icon" type="image/x-icon" href="./logo.png">
|
||||
</head>
|
||||
<body>
|
||||
<%= FES_APP_PUBLISH_ERROR_PAGE %>
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
console.log('<%= FES_APP_PUBLISH_ERROR_PAGE %>');
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user