mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-11-29 09:41:45 +00:00
[@pollyjs/core] updates for 1.3 config options
This commit is contained in:
Vendored
+15
-13
@@ -1,4 +1,4 @@
|
||||
// Type definitions for @pollyjs/core 1.2
|
||||
// Type definitions for @pollyjs/core 1.3
|
||||
// Project: https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/core
|
||||
// Definitions by: feinoujc <https://github.com/feinoujc>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@@ -12,8 +12,10 @@ export const Timing: {
|
||||
fixed(ms: number): () => Promise<void>;
|
||||
relative(ratio: number): (ms: number) => Promise<void>;
|
||||
};
|
||||
|
||||
export type MatchBy<T = string, R = T> = (input: T) => R;
|
||||
export interface PollyConfig {
|
||||
mode?: MODES;
|
||||
mode?: MODES | string;
|
||||
|
||||
adapters?: Array<string | typeof Adapter>;
|
||||
adapterOptions?: any;
|
||||
@@ -34,20 +36,20 @@ export interface PollyConfig {
|
||||
timing?: ((ms: number) => Promise<void>) | (() => Promise<void>);
|
||||
|
||||
matchRequestsBy?: {
|
||||
method?: boolean;
|
||||
headers?: any;
|
||||
body?: boolean;
|
||||
method?: boolean | MatchBy;
|
||||
headers?: boolean | { exclude: string[] } | MatchBy<Record<string, string>>;
|
||||
body?: boolean | MatchBy<any>;
|
||||
order?: boolean;
|
||||
|
||||
url?: {
|
||||
protocol?: boolean;
|
||||
username?: boolean;
|
||||
password?: boolean;
|
||||
hostname?: boolean;
|
||||
port?: boolean;
|
||||
pathname?: boolean;
|
||||
query?: boolean;
|
||||
hash?: boolean;
|
||||
protocol?: boolean | MatchBy;
|
||||
username?: boolean | MatchBy;
|
||||
password?: boolean | MatchBy;
|
||||
hostname?: boolean | MatchBy;
|
||||
port?: boolean | MatchBy<number>;
|
||||
pathname?: boolean | MatchBy;
|
||||
query?: boolean | MatchBy<any>;
|
||||
hash?: boolean | MatchBy;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,74 @@ const polly = new Polly('test recording', {
|
||||
recordFailedRequests: true,
|
||||
adapters: ['xhr', 'fetch'],
|
||||
persister: 'rest',
|
||||
timing: Timing.relative(3)
|
||||
timing: Timing.relative(3),
|
||||
matchRequestsBy: {
|
||||
method: true,
|
||||
headers: true,
|
||||
body: true,
|
||||
order: true,
|
||||
|
||||
url: {
|
||||
protocol: true,
|
||||
username: true,
|
||||
password: true,
|
||||
hostname: true,
|
||||
port: true,
|
||||
pathname: true,
|
||||
query: true,
|
||||
hash: false
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
new Polly('test recording', {
|
||||
mode: 'replay',
|
||||
recordFailedRequests: true,
|
||||
adapters: ['xhr', 'fetch'],
|
||||
persister: 'rest',
|
||||
timing: Timing.relative(3),
|
||||
matchRequestsBy: {
|
||||
method(method) {
|
||||
return method.toLowerCase();
|
||||
},
|
||||
headers: 1 === 1 ? { exclude: ['X-Auth'] } : (headers) => {
|
||||
delete headers['X-Auth'];
|
||||
return headers;
|
||||
},
|
||||
body(body) {
|
||||
const json = JSON.parse(body);
|
||||
|
||||
delete json.email;
|
||||
return JSON.stringify(json);
|
||||
},
|
||||
|
||||
url: {
|
||||
protocol(protocol) {
|
||||
return protocol === 'http' ? 'https:' : protocol;
|
||||
},
|
||||
username(username) {
|
||||
return username === 'johndoe' ? 'username' : username;
|
||||
},
|
||||
password(password) {
|
||||
return password || 'password';
|
||||
},
|
||||
hostname(hostname) {
|
||||
return hostname.replace('.com', '.net');
|
||||
},
|
||||
port(port) {
|
||||
return port > 80 ? 3000 : 433;
|
||||
},
|
||||
pathname(pathname) {
|
||||
return pathname.replace('/api/v1', '/api');
|
||||
},
|
||||
query(query) {
|
||||
return { ...query, token: '' };
|
||||
},
|
||||
hash(hash) {
|
||||
return hash.replace(/token=[0-9]+/, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function log(_: string) {
|
||||
|
||||
Reference in New Issue
Block a user