Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { recordingName, recordingId, config } = this.polly;
const orderedRecordUrl = order => `${this.recordUrl()}?order=${order}`;
await this.fetch(orderedRecordUrl(1));
await this.fetch(orderedRecordUrl(2));
await this.polly.persister.persist();
let har = await this.polly.persister.find(recordingId);
expect(har).to.be.an('object');
expect(har.log.entries).to.have.lengthOf(2);
await this.polly.stop();
this.polly = new Polly(recordingName, config);
this.polly.replay();
this.polly.configure({
persisterOptions: {
keepUnusedRequests: false
}
});
await this.fetch(orderedRecordUrl(1)); // -> Replay
await this.fetch(orderedRecordUrl(3)); // -> New recording
await this.polly.persister.persist();
har = await this.polly.persister.find(recordingId);
expect(har).to.be.an('object');
expect(har.log.entries).to.have.lengthOf(2);
expect(har.log.entries[0].request.url).to.include(orderedRecordUrl(1));
};
dictionaries: {
[dictionaryId: string]: Dictionary;
};
trackers: Array;
dataList: StreamAttributeMapResult;
dataSource: DataSourceType;
usersAndGroups: {
users: Array;
userGroupMemberships: Array;
};
}
// The server is created as a singular thing for the whole app
// Much easier to manage it this way
const polly = new Polly("Mock Stroom API");
polly.configure({
adapters: ["fetch"],
logging: true
});
const { server } = polly;
// The cache acts as a singular global object who's contents are replaced
export interface TestCache {
data?: TestData;
}
const testCache: TestCache = {};
const startTime = Date.now();
// Hot loading should pass through
const testConfig = {
authenticationServiceUrl: "/authService/authentication/v1",
authorisationServiceUrl: "/api/authorisation/v1",
stroomBaseServiceUrl: "/api",
authUsersUiUrl:
"auth/users/because/they/are/loaded/in/an/iframe/which/is/beyond/scope/of/these/tests",
authTokensUiUrl:
"auth/tokens/because/they/are/loaded/in/an/iframe/which/is/beyond/scope/of/these/tests",
advertisedUrl: "/",
appClientId: "stroom-ui"
};
// The server is created as a singular thing for the whole app
// Much easier to manage it this way
const polly = new Polly("Mock Stroom API");
polly.configure({
logging: true
});
const { server } = polly;
// The cache acts as a singular global object who's contents are replaced
const testCache = {
data: {}
};
const startTime = Date.now();
// Hot loading should pass through
server.get("*.hot-update.json").passthrough();
// This is normally deployed as part of the server
elements: ElementDefinitions;
elementProperties: ElementPropertiesByElementIdType;
xslt: {
[xsltId: string]: string;
};
dictionaries: {
[dictionaryId: string]: Dictionary;
};
trackers: Array;
dataList: StreamAttributeMapResult;
dataSource: DataSourceType;
}
// The server is created as a singular thing for the whole app
// Much easier to manage it this way
const polly = new Polly("Mock Stroom API");
polly.configure({
adapters: ["fetch"],
logging: true
});
const { server } = polly;
// The cache acts as a singular global object who's contents are replaced
export interface TestCache {
data?: TestData;
}
const testCache: TestCache = {};
const startTime = Date.now();
// This is normally deployed as part of the server
order: true,
url: {
protocol: true,
username: true,
password: true,
hostname: true,
port: true,
pathname: true,
query: true,
hash: false,
},
},
});
new Polly('test recording', {
mode: 'record',
expiryStrategy: 'warn',
recordFailedRequests: true,
adapters: ['xhr', 'fetch'],
adapterOptions: {
xhr: {
context: {},
},
fetch: {
context: {},
},
foo: {
bar: true,
},
},
persister: 'rest',
import { Polly, Timing, setupMocha, setupQunit } from '@pollyjs/core';
import { EXPIRY_STRATEGIES, MODES } from '@pollyjs/utils';
const polly = new Polly('test recording', {
mode: MODES.PASSTHROUGH,
recordFailedRequests: true,
adapters: ['xhr', 'fetch'],
persister: 'rest',
expiryStrategy: EXPIRY_STRATEGIES.ERROR,
timing: Timing.relative(3),
matchRequestsBy: {
method: true,
headers: true,
body: true,
order: true,
url: {
protocol: true,
username: true,
password: true,
export default function httpMockApi(routes, baseUri, options = {}) {
const polly = new Polly('Faked HTTP', {
adapters: ['xhr', 'fetch'],
recordIfMissing: false,
mode: 'passthrough',
});
const { server } = polly;
const normalizedBasedUri = baseUri.endsWith('/')
? baseUri.slice(0, -1)
: baseUri;
//Polly doesn't support intercept on .any(), so we have to run it on each method separately.
const handler = (req, res, interceptor) =>
handleIntercept(req, res, interceptor, routes, normalizedBasedUri, options);
server.get(`${normalizedBasedUri}/*`).intercept(handler);
server.put(`${normalizedBasedUri}/*`).intercept(handler);
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.setRequestInterception(true);
const polly = new Polly('puppeteer', {
adapters: ['puppeteer'],
adapterOptions: { puppeteer: { page } },
persister: 'fs',
persisterOptions: {
fs: {
recordingsDir: path.join(__dirname, 'recordings')
}
}
});
const { server } = polly;
server.host('http://localhost:3000', () => {
server.get('/favicon.ico').passthrough();
server.get('/sockjs-node/*').intercept((_, res) => res.sendStatus(200));
});
},
{
provide: AUTH_TOKEN_NAME,
useValue: apiUtilsConfig.authTokenName
},
{
provide: API_HTTP_DEFAULT_HEADERS,
useValue: apiUtilsConfig.defaultHeaders
},
{
provide: API_HTTP_AUTHORIZATION_HEADER_NAME,
useValue: apiUtilsConfig.authorizationHeaderName
}
]
});
polly = new Polly('ngx-api-utils', {
adapters: ['xhr', 'fetch']
});
localStorage.removeItem(apiUtilsConfig.authTokenName);
});