• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alovajs / alova / #210

08 Oct 2024 07:26AM CUT coverage: 93.734% (-0.09%) from 93.826%
#210

push

github

web-flow
Merge pull request #554 from alovajs/changeset-release/main

ci: release

1608 of 1761 branches covered (91.31%)

Branch coverage included in aggregate %.

9537 of 10129 relevant lines covered (94.16%)

60.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.69
/packages/adapter-mock/src/consoleRequestInfo.ts
1
import { MockRequestLoggerAdapter } from '~/typings';
1✔
2

1✔
3
// 预定义的样式和固定文本
1✔
4
const mockLabel = 'mock';
1✔
5
const mockLabelColor = '#64bde8';
1✔
6
const mockLabelBg = '#ccefff';
1✔
7
const realRequestLabel = 'Realtime';
1✔
8
const realRequestLabelColor = '#999999';
1✔
9
const realRequestLabelBg = '#ededed';
1✔
10
const labelStyle = (bgColor: string, color: string) => `padding: 2px 6px; background: ${bgColor}; color: ${color};`;
1✔
11
const titleStyle = 'color: black; font-size: 12px; font-weight: bolder';
1✔
12
const transform2TableData = (obj: AnyObject) => {
1✔
13
  const tableData = {} as AnyObject;
×
14
  for (const key in obj) {
×
15
    tableData[key] = { value: obj[key] };
×
16
  }
×
17
  return tableData;
×
18
};
×
19

1✔
20
type AnyObject = Record<string, any>;
1✔
21
// 打印请求信息,模拟数据请求专用
1✔
22
const consoleRequestInfo: MockRequestLoggerAdapter = ({
1✔
23
  isMock,
×
24
  url,
×
25
  method,
×
26
  headers,
×
27
  query,
×
28
  data,
×
29
  responseHeaders,
×
30
  response
×
31
}) => {
×
32
  const cole = console;
×
33
  cole.groupCollapsed(
×
34
    `%c${isMock ? mockLabel : realRequestLabel}`,
×
35
    labelStyle(isMock ? mockLabelBg : realRequestLabelBg, isMock ? mockLabelColor : realRequestLabelColor),
×
36
    url
×
37
  );
×
38

×
39
  // 请求方法
×
40
  cole.log('%c[Method]', titleStyle, method.toUpperCase());
×
41

×
42
  // 输出Request Headers
×
43
  cole.log('%c[Request Headers]', titleStyle);
×
44
  cole.table(transform2TableData(headers));
×
45

×
46
  // 输出Query String Parameters
×
47
  cole.log('%c[Query String Parameters]', titleStyle);
×
48
  cole.table(transform2TableData(query));
×
49

×
50
  // 输出request body
×
51
  cole.log('%c[Request Body]', titleStyle, data || '');
×
52

×
53
  // 输出response body
×
54
  if (isMock) {
×
55
    // 响应头有数据时,输出Response Headers
×
56
    if (Object.keys(responseHeaders).length > 0) {
×
57
      cole.log('%c[Response Headers]', titleStyle);
×
58
      cole.table(transform2TableData(responseHeaders));
×
59
    }
×
60
    cole.log('%c[Response Body]', titleStyle, response || '');
×
61
  }
×
62
  cole.groupEnd();
×
63
};
×
64

1✔
65
export default consoleRequestInfo;
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc