Compare commits
No commits in common. "main" and "v2.7.1" have entirely different histories.
|
@ -1,12 +1,3 @@
|
||||||
## [2.7.2](https://github.com/zjxxxxxxxxx/axios-miniprogram/compare/v2.7.1...v2.7.2) (2024-01-31)
|
|
||||||
|
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
* 修复设置请求 headers 影响了全局配置 ([#56](https://github.com/zjxxxxxxxxx/axios-miniprogram/issues/56)) ([5d45cd9](https://github.com/zjxxxxxxxxx/axios-miniprogram/commit/5d45cd9670c3bc8b58437d2defc58753ebc6392e)), closes [#55](https://github.com/zjxxxxxxxxx/axios-miniprogram/issues/55)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [2.7.1](https://github.com/zjxxxxxxxxx/axios-miniprogram/compare/v2.7.0...v2.7.1) (2023-12-16)
|
## [2.7.1](https://github.com/zjxxxxxxxxx/axios-miniprogram/compare/v2.7.0...v2.7.1) (2023-12-16)
|
||||||
|
|
||||||
|
|
||||||
|
|
16
README.md
16
README.md
|
@ -1,26 +1,24 @@
|
||||||
<h1 align="center">axios-miniprogram</h1>
|
<h1 align="center">axios-miniprogram</h1>
|
||||||
|
|
||||||
<p style="text-align: center;" align="center">
|
<p align="center">
|
||||||
<a style="display: inline-block;margin-left: 5px;" href="https://github.com/zjxxxxxxxxx/axios-miniprogram/actions/workflows/ci.yml">
|
<a href="https://github.com/zjxxxxxxxxx/axios-miniprogram/actions/workflows/ci.yml">
|
||||||
<img src="https://github.com/zjxxxxxxxxx/axios-miniprogram/actions/workflows/ci.yml/badge.svg" alt="ci"/>
|
<img src="https://github.com/zjxxxxxxxxx/axios-miniprogram/actions/workflows/ci.yml/badge.svg" alt="ci"/>
|
||||||
</a>
|
</a>
|
||||||
<a style="display: inline-block;margin-left: 5px;" href="https://codecov.io/gh/zjxxxxxxxxx/axios-miniprogram" >
|
<a style="margin-left:5px;" href="https://codecov.io/gh/zjxxxxxxxxx/axios-miniprogram" >
|
||||||
<img src="https://codecov.io/gh/zjxxxxxxxxx/axios-miniprogram/branch/main/graph/badge.svg?token=WIQVYX2WIK" alt="codecov"/>
|
<img src="https://codecov.io/gh/zjxxxxxxxxx/axios-miniprogram/branch/main/graph/badge.svg?token=WIQVYX2WIK" alt="codecov"/>
|
||||||
</a>
|
</a>
|
||||||
<a style="display: inline-block;margin-left: 5px;" href="https://opensource.org/licenses/MIT">
|
<a style="margin-left:5px;" href="https://opensource.org/licenses/MIT">
|
||||||
<img src="https://img.shields.io/github/license/zjxxxxxxxxx/axios-miniprogram" alt="license"/>
|
<img src="https://img.shields.io/github/license/zjxxxxxxxxx/axios-miniprogram" alt="license"/>
|
||||||
</a>
|
</a>
|
||||||
<a style="display: inline-block;margin-left: 5px;" href="https://www.npmjs.org/package/axios-miniprogram">
|
<a style="margin-left:5px;" href="https://www.npmjs.org/package/axios-miniprogram">
|
||||||
<img src="https://img.shields.io/bundlephobia/min/axios-miniprogram" alt="npm bundle size"/>
|
<img src="https://img.shields.io/bundlephobia/min/axios-miniprogram" alt="npm bundle size"/>
|
||||||
</a>
|
</a>
|
||||||
<a style="display: inline-block;" href="https://www.npmjs.org/package/axios-miniprogram">
|
<a style="margin-left:5px;" href="https://www.npmjs.org/package/axios-miniprogram">
|
||||||
<img alt="npm" src="https://img.shields.io/npm/dt/axios-miniprogram"/>
|
<img alt="npm" src="https://img.shields.io/npm/dt/axios-miniprogram"/>
|
||||||
</a>
|
</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p style="text-align: center;" align="center">
|
<p align="center"><a href='https://axios-miniprogram.com'>中文文档</a></p>
|
||||||
<a href='https://axios-miniprogram.com'>中文文档</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
## axios-miniprogram 是什么?
|
## axios-miniprogram 是什么?
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { linkSync, unlinkSync } from 'node:fs';
|
import { linkSync } from 'node:fs';
|
||||||
import { resolve } from '../../../scripts/utils';
|
import { resolve } from '../../../scripts/utils';
|
||||||
|
|
||||||
const readmePath = resolve('README.md');
|
const readmePath = resolve('README.md');
|
||||||
|
@ -6,9 +6,6 @@ const introPath = resolve('docs/pages/guide/intro.md');
|
||||||
|
|
||||||
export function linkIntro() {
|
export function linkIntro() {
|
||||||
try {
|
try {
|
||||||
unlinkSync(introPath);
|
|
||||||
} catch {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
linkSync(readmePath, introPath);
|
linkSync(readmePath, introPath);
|
||||||
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,15 +9,15 @@ title: 开始
|
||||||
:::: code-group
|
:::: code-group
|
||||||
|
|
||||||
```bash [NPM]
|
```bash [NPM]
|
||||||
$ npm install axios-miniprogram
|
$ npm install -D axios-miniprogram
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash [YARN]
|
```bash [YARN]
|
||||||
$ yarn add axios-miniprogram
|
$ yarn add -D axios-miniprogram
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash [PNPM]
|
```bash [PNPM]
|
||||||
$ pnpm install axios-miniprogram
|
$ pnpm install -D axios-miniprogram
|
||||||
```
|
```
|
||||||
|
|
||||||
::::
|
::::
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "axios-miniprogram",
|
"name": "axios-miniprogram",
|
||||||
"version": "2.7.2",
|
"version": "2.7.1",
|
||||||
"description": "基于 Promise 的 HTTP 请求库,适用于各大小程序平台。",
|
"description": "基于 Promise 的 HTTP 请求库,适用于各大小程序平台。",
|
||||||
"main": "dist/axios-miniprogram.cjs.js",
|
"main": "dist/axios-miniprogram.cjs.js",
|
||||||
"module": "dist/axios-miniprogram.esm.js",
|
"module": "dist/axios-miniprogram.esm.js",
|
||||||
|
|
|
@ -354,16 +354,14 @@ export interface AxiosConstructor {
|
||||||
|
|
||||||
export default class Axios {
|
export default class Axios {
|
||||||
/**
|
/**
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* 父级实例
|
* 父级实例
|
||||||
*/
|
*/
|
||||||
private declare parent?: Axios;
|
#parent?: Axios;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认请求配置
|
* 默认请求配置
|
||||||
*/
|
*/
|
||||||
declare defaults: AxiosRequestConfig;
|
defaults: AxiosRequestConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拦截器
|
* 拦截器
|
||||||
|
@ -380,64 +378,63 @@ export default class Axios {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* 中间件
|
* 中间件
|
||||||
*/
|
*/
|
||||||
private middleware = new MiddlewareManager();
|
#middleware = new MiddlewareManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送 options 请求
|
* 发送 options 请求
|
||||||
*/
|
*/
|
||||||
declare options: AxiosRequestMethodFn;
|
options!: AxiosRequestMethodFn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送 get 请求
|
* 发送 get 请求
|
||||||
*/
|
*/
|
||||||
declare get: AxiosRequestMethodFnWithParams;
|
get!: AxiosRequestMethodFnWithParams;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送 head 请求
|
* 发送 head 请求
|
||||||
*/
|
*/
|
||||||
declare head: AxiosRequestMethodFnWithParams;
|
head!: AxiosRequestMethodFnWithParams;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送 post 请求
|
* 发送 post 请求
|
||||||
*/
|
*/
|
||||||
declare post: AxiosRequestMethodFnWithData;
|
post!: AxiosRequestMethodFnWithData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送 put 请求
|
* 发送 put 请求
|
||||||
*/
|
*/
|
||||||
declare put: AxiosRequestMethodFnWithData;
|
put!: AxiosRequestMethodFnWithData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送 patch 请求
|
* 发送 patch 请求
|
||||||
*/
|
*/
|
||||||
declare patch: AxiosRequestMethodFnWithData;
|
patch!: AxiosRequestMethodFnWithData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送 delete 请求
|
* 发送 delete 请求
|
||||||
*/
|
*/
|
||||||
declare delete: AxiosRequestMethodFnWithParams;
|
delete!: AxiosRequestMethodFnWithParams;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送 trace 请求
|
* 发送 trace 请求
|
||||||
*/
|
*/
|
||||||
declare trace: AxiosRequestMethodFn;
|
trace!: AxiosRequestMethodFn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送 connect 请求
|
* 发送 connect 请求
|
||||||
*/
|
*/
|
||||||
declare connect: AxiosRequestMethodFn;
|
connect!: AxiosRequestMethodFn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
* @param config 默认配置
|
* @param config 默认配置
|
||||||
* @param parent 父级实例
|
* @param parent 父级实例
|
||||||
*/
|
*/
|
||||||
constructor(config: AxiosRequestConfig, parent?: Axios) {
|
constructor(config: AxiosRequestConfig, parent?: Axios) {
|
||||||
this.defaults = config;
|
this.defaults = config;
|
||||||
this.parent = parent;
|
this.#parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -457,7 +454,7 @@ export default class Axios {
|
||||||
'get') as AxiosRequestMethod;
|
'get') as AxiosRequestMethod;
|
||||||
|
|
||||||
const requestHandler = {
|
const requestHandler = {
|
||||||
resolved: this.handleRequest,
|
resolved: this.#handleRequest,
|
||||||
};
|
};
|
||||||
const errorHandler = {
|
const errorHandler = {
|
||||||
rejected: config.errorHandler,
|
rejected: config.errorHandler,
|
||||||
|
@ -467,12 +464,12 @@ export default class Axios {
|
||||||
| Partial<Interceptor<AxiosResponse>>
|
| Partial<Interceptor<AxiosResponse>>
|
||||||
)[] = [];
|
)[] = [];
|
||||||
|
|
||||||
this.eachInterceptors('request', (interceptor) => {
|
this.#eachRequestInterceptors((requestInterceptor) => {
|
||||||
chain.unshift(interceptor);
|
chain.unshift(requestInterceptor);
|
||||||
});
|
});
|
||||||
chain.push(requestHandler);
|
chain.push(requestHandler);
|
||||||
this.eachInterceptors('response', (interceptor) => {
|
this.#eachResponseInterceptors((responseInterceptor) => {
|
||||||
chain.push(interceptor);
|
chain.push(responseInterceptor);
|
||||||
});
|
});
|
||||||
chain.push(errorHandler);
|
chain.push(errorHandler);
|
||||||
|
|
||||||
|
@ -487,19 +484,17 @@ export default class Axios {
|
||||||
) as Promise<AxiosResponse>;
|
) as Promise<AxiosResponse>;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
#eachRequestInterceptors(executor: InterceptorExecutor<AxiosRequestConfig>) {
|
||||||
* @internal
|
this.interceptors.request.forEach(executor);
|
||||||
*/
|
if (this.#parent) {
|
||||||
private eachInterceptors<T extends 'request' | 'response'>(
|
this.#parent.#eachRequestInterceptors(executor);
|
||||||
type: T,
|
}
|
||||||
executor: InterceptorExecutor<
|
}
|
||||||
T extends 'request' ? AxiosRequestConfig : AxiosResponse
|
|
||||||
>,
|
#eachResponseInterceptors(executor: InterceptorExecutor<AxiosResponse>) {
|
||||||
) {
|
this.interceptors.response.forEach(executor);
|
||||||
// @ts-ignore
|
if (this.#parent) {
|
||||||
this.interceptors[type].forEach(executor);
|
this.#parent.#eachResponseInterceptors(executor);
|
||||||
if (this.parent) {
|
|
||||||
this.parent.eachInterceptors(type, executor);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -531,37 +526,28 @@ export default class Axios {
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
use = (middleware: MiddlewareCallback) => {
|
use = (middleware: MiddlewareCallback) => {
|
||||||
this.middleware.use(middleware);
|
this.#middleware.use(middleware);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
#handleRequest = async (config: AxiosRequestConfig) => {
|
||||||
* @internal
|
const ctx = this.#middleware.createContext(config);
|
||||||
*/
|
await this.#run(ctx, this.#handleResponse);
|
||||||
private handleRequest = async (config: AxiosRequestConfig) => {
|
|
||||||
const ctx = this.middleware.createContext(config);
|
|
||||||
await this.run(ctx, this.handleResponse);
|
|
||||||
return ctx.res as AxiosResponse;
|
return ctx.res as AxiosResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
#handleResponse = async (ctx: MiddlewareContext) => {
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
private async handleResponse(ctx: MiddlewareContext) {
|
|
||||||
ctx.res = await dispatchRequest(ctx.req);
|
ctx.res = await dispatchRequest(ctx.req);
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
#run = (
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
private run = (
|
|
||||||
ctx: MiddlewareContext,
|
ctx: MiddlewareContext,
|
||||||
respond: MiddlewareCallback,
|
respond: MiddlewareCallback,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
if (!this.parent) {
|
if (!this.#parent) {
|
||||||
return this.middleware.run(ctx, respond);
|
return this.#middleware.run(ctx, respond);
|
||||||
}
|
}
|
||||||
return this.middleware.enhanceRun(this.parent.run)(ctx, respond);
|
return this.#middleware.enhanceRun(this.#parent.#run)(ctx, respond);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,18 +29,14 @@ export interface InterceptorExecutor<T = unknown> {
|
||||||
*/
|
*/
|
||||||
export default class InterceptorManager<T = unknown> {
|
export default class InterceptorManager<T = unknown> {
|
||||||
/**
|
/**
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* 生成拦截器标识符
|
* 生成拦截器标识符
|
||||||
*/
|
*/
|
||||||
private id = 0;
|
#id = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* 拦截器缓存池
|
* 拦截器缓存池
|
||||||
*/
|
*/
|
||||||
private interceptors = new Map<number, Interceptor<T>>();
|
#interceptors = new Map<number, Interceptor<T>>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
@ -48,7 +44,7 @@ export default class InterceptorManager<T = unknown> {
|
||||||
* 拦截器数量
|
* 拦截器数量
|
||||||
*/
|
*/
|
||||||
get size() {
|
get size() {
|
||||||
return this.interceptors.size;
|
return this.#interceptors.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,12 +58,12 @@ export default class InterceptorManager<T = unknown> {
|
||||||
resolved: InterceptorResolved<T>,
|
resolved: InterceptorResolved<T>,
|
||||||
rejected?: InterceptorRejected<T>,
|
rejected?: InterceptorRejected<T>,
|
||||||
): number {
|
): number {
|
||||||
this.interceptors.set(++this.id, {
|
this.#interceptors.set(++this.#id, {
|
||||||
resolved,
|
resolved,
|
||||||
rejected,
|
rejected,
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.id;
|
return this.#id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,14 +72,14 @@ export default class InterceptorManager<T = unknown> {
|
||||||
* @param id 拦截器标识符
|
* @param id 拦截器标识符
|
||||||
*/
|
*/
|
||||||
eject(id: number): boolean {
|
eject(id: number): boolean {
|
||||||
return this.interceptors.delete(id);
|
return this.#interceptors.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空拦截器
|
* 清空拦截器
|
||||||
*/
|
*/
|
||||||
clear() {
|
clear() {
|
||||||
this.interceptors.clear();
|
this.#interceptors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,6 +90,6 @@ export default class InterceptorManager<T = unknown> {
|
||||||
* @param executor 执行器
|
* @param executor 执行器
|
||||||
*/
|
*/
|
||||||
forEach(executor: InterceptorExecutor<T>): void {
|
forEach(executor: InterceptorExecutor<T>): void {
|
||||||
this.interceptors.forEach(executor);
|
this.#interceptors.forEach(executor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,18 +34,16 @@ export interface MiddlewareCallback {
|
||||||
*/
|
*/
|
||||||
export default class MiddlewareManager {
|
export default class MiddlewareManager {
|
||||||
/**
|
/**
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* 中间件缓存池
|
* 中间件缓存池
|
||||||
*/
|
*/
|
||||||
private middlewares: MiddlewareCallback[] = [];
|
#middlewares: MiddlewareCallback[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册中间件
|
* 注册中间件
|
||||||
*/
|
*/
|
||||||
use(middleware: MiddlewareCallback) {
|
use(middleware: MiddlewareCallback) {
|
||||||
assert(isFunction(middleware), 'middleware 不是一个 function');
|
assert(isFunction(middleware), 'middleware 不是一个 function');
|
||||||
this.middlewares.push(middleware);
|
this.#middlewares.push(middleware);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +67,7 @@ export default class MiddlewareManager {
|
||||||
* @param respond 目标函数
|
* @param respond 目标函数
|
||||||
*/
|
*/
|
||||||
run(ctx: MiddlewareContext, respond: MiddlewareCallback) {
|
run(ctx: MiddlewareContext, respond: MiddlewareCallback) {
|
||||||
const middlewares = [...this.middlewares, respond];
|
const middlewares = [...this.#middlewares, respond];
|
||||||
async function next() {
|
async function next() {
|
||||||
await middlewares.shift()!(ctx, next);
|
await middlewares.shift()!(ctx, next);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,10 +39,12 @@ export function mergeConfig(
|
||||||
}
|
}
|
||||||
// 深度合并 config1 和 config2 中的对象
|
// 深度合并 config1 和 config2 中的对象
|
||||||
else if (deepMergeConfigMap[key]) {
|
else if (deepMergeConfigMap[key]) {
|
||||||
if (isPlainObject(val1)) {
|
if (isPlainObject(val1) && isPlainObject(val2)) {
|
||||||
config[key] = deepMerge(val1, isPlainObject(val2) ? val2 : {});
|
config[key] = deepMerge(val1, val2);
|
||||||
} else if (isPlainObject(val2)) {
|
} else if (isPlainObject(val2)) {
|
||||||
config[key] = deepMerge(val2, {});
|
config[key] = val2;
|
||||||
|
} else if (isPlainObject(val1)) {
|
||||||
|
config[key] = val1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 优先从 config2 中取值,如果没有值就从 config1 中取值
|
// 优先从 config2 中取值,如果没有值就从 config1 中取值
|
||||||
|
|
|
@ -44,27 +44,24 @@ export function isCancel(value: unknown): value is Cancel {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CancelToken {
|
export class CancelToken {
|
||||||
/**
|
#reason?: Cancel;
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
private declare reason?: Cancel;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
declare onCancel: Promise<Cancel>['then'];
|
onCancel: Promise<Cancel>['then'];
|
||||||
|
|
||||||
constructor(executor: CancelExecutor) {
|
constructor(executor: CancelExecutor) {
|
||||||
let action!: CancelAction;
|
let action!: CancelAction;
|
||||||
const promise = new Promise<Cancel>((resolve) => {
|
const promise = new Promise<Cancel>((resolve) => {
|
||||||
action = (message) => {
|
action = (message) => {
|
||||||
if (this.reason) {
|
if (this.#reason) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.reason = new Cancel(message);
|
this.#reason = new Cancel(message);
|
||||||
|
|
||||||
resolve(this.reason);
|
resolve(this.#reason);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -89,8 +86,8 @@ export class CancelToken {
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
throwIfRequested(): void {
|
throwIfRequested(): void {
|
||||||
if (this.reason) {
|
if (this.#reason) {
|
||||||
throw this.reason;
|
throw this.#reason;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
export const version = '2.7.2';
|
export const version = '2.7.1';
|
||||||
|
|
|
@ -127,25 +127,6 @@ describe('src/core/mergeConfig.ts', () => {
|
||||||
expect(mergeConfig(c1 as any, c2 as any)).toEqual({});
|
expect(mergeConfig(c1 as any, c2 as any)).toEqual({});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('深度合并应该返回新的对象', () => {
|
|
||||||
const c1 = {
|
|
||||||
headers: { t: 1 },
|
|
||||||
params: {},
|
|
||||||
};
|
|
||||||
const c2 = {
|
|
||||||
headers: {},
|
|
||||||
params: { t: 1 },
|
|
||||||
};
|
|
||||||
const c3 = mergeConfig(c1 as any, c2 as any);
|
|
||||||
|
|
||||||
expect(c3.headers === c1.headers).toBeFalsy();
|
|
||||||
expect(c3.params === c1.params).toBeFalsy();
|
|
||||||
expect(c3.headers === c2.headers).toBeFalsy();
|
|
||||||
expect(c3.params === c2.params).toBeFalsy();
|
|
||||||
expect(c3.headers).toEqual(c1.headers);
|
|
||||||
expect(c3.params).toEqual(c2.params);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('应该优先取 config2', () => {
|
test('应该优先取 config2', () => {
|
||||||
const c1 = {
|
const c1 = {
|
||||||
adapter: vi.fn(),
|
adapter: vi.fn(),
|
||||||
|
|
Loading…
Reference in New Issue