當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript core.Polly類代碼示例

本文整理匯總了TypeScript中@pollyjs/core.Polly的典型用法代碼示例。如果您正苦於以下問題:TypeScript Polly類的具體用法?TypeScript Polly怎麽用?TypeScript Polly使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Polly類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Polly

import FetchAdapter from '@pollyjs/adapter-fetch';
import { Polly } from '@pollyjs/core';

Polly.register(FetchAdapter);

new Polly('<recording>', {
	adapters: ['xhr', FetchAdapter]
});
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:8,代碼來源:pollyjs__adapter-fetch-tests.ts

示例2: Polly

import FSPersister from '@pollyjs/persister-fs';
import { Polly } from '@pollyjs/core';

Polly.register(FSPersister);

new Polly('<recording>', {
    persister: FSPersister
});
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:8,代碼來源:pollyjs__persister-fs-tests.ts

示例3: Polly

import HttpAdapter from '@pollyjs/adapter-node-http';
import { Polly } from '@pollyjs/core';

Polly.register(HttpAdapter);

new Polly('<recording>', {
	adapters: ['node-http', HttpAdapter]
});
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:8,代碼來源:pollyjs__adapter-node-http-tests.ts

示例4: test

async function test() {
	polly.pause();
	polly.play();
	const { server } = polly;
	server.get('/session').on('request', req => {
		req.headers['X-AUTH'] = '<ACCESS_TOKEN>';
		req.query.email = 'test@app.com';
	});
	server.get('/session').on('beforeResponse', (req, res) => {
		res.setHeader('X-AUTH', '<ACCESS_TOKEN>');
	});
	server.get('/session').on('response', (req, res) => {
		log(`${req.url} took ${req.responseTime}ms with a status of ${res.statusCode}.`);
	});

	polly.configure({
		adapterOptions: {
			fetch: {
				context: null
			}
		}
	});

	server
		.get('/session')
		.once('request', req => {
			req.headers['X-AUTH'] = '<ACCESS_TOKEN>';
			req.query.email = 'test@app.com';
		})
		.once('request', () => {
			/* Do something else */
		});

	/* Intercept all Google Analytic requests and respond with a 200 */
	server.get('/google-analytics/*path').intercept((req, res, intercept) => {
		if (req.pathname === 'test') {
			intercept.abort();
		} else {
			res.sendStatus(200);
		}
	});

	/* Pass-through all GET requests to /coverage */
	server.get('/coverage')
		.configure({ expiresIn: '5d' })
		.passthrough();

	await polly.flush();
}
開發者ID:geirsagberg,項目名稱:DefinitelyTyped,代碼行數:49,代碼來源:pollyjs__core-tests.ts

示例5: test

async function test() {
	polly.pause();
	polly.play();
	const { server } = polly;
	server.get('/session').on('request', req => {
		req.headers['X-AUTH'] = '<ACCESS_TOKEN>';
		req.query.email = 'test@app.com';
	});
	server.get('/session').on('beforeResponse', (req, res) => {
		res.setHeader('X-AUTH', '<ACCESS_TOKEN>');
	});
	server.get('/session').on('response', (req, res) => {
		log(`${req.url} took ${req.responseTime}ms with a status of ${res.statusCode}.`);
	});

	polly.configure({
		adapterOptions: {
			fetch: {
				context: null
			}
		}
	});

	server
		.get('/session')
		.once('request', req => {
			req.headers['X-AUTH'] = '<ACCESS_TOKEN>';
			req.query.email = 'test@app.com';
		})
		.once('request', () => {
			/* Do something else */
		});

		server
			.get('/users/:id')
			.filter(req => req.params.id === '1')
			.filter(req => req.params.id !== '2')
			.recordingName('test')
			.recordingName()
			.intercept((_req, res) => {
				res.status(200).json({ email: 'user1@test.com' });
			});

	/* Intercept all Google Analytic requests and respond with a 200 */
	server.get('/google-analytics/*path').intercept((req, res, intercept) => {
		if (req.pathname === 'test') {
			intercept.abort();
		} else {
			res.sendStatus(200);
		}
	});

	/* Pass-through all GET requests to /coverage */
	server.get('/coverage')
		.configure({ expiresIn: '5d' })
		.passthrough();

	server.any().on('error', (req, error) => {
		req
			.setHeader('Content-Length', '2344')
			.setHeaders({
				'Content-Type': 'application/json',
				'Content-Length': '42'
			})
			.removeHeader('Content-Length')
			.removeHeaders(['Content-Type', 'Content-Length']);

		req.removeHeaders(['Content-Type', 'Content-Length']);
		log(req.pathname + JSON.stringify(error));
	});

	await polly.flush();
}
開發者ID:CNBoland,項目名稱:DefinitelyTyped,代碼行數:73,代碼來源:pollyjs__core-tests.ts


注:本文中的@pollyjs/core.Polly類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。