Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Extend TypeScript example #464

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
docs: Add parameter to override PollyConfig in typescript examples, j…
…sdoc included
justsml committed Jun 8, 2022
commit 158fbe951a042063cf3a80a5c0b9d7f844d30631
52 changes: 48 additions & 4 deletions examples/typescript-jest-node-fetch/src/utils/auto-setup-polly.ts
Original file line number Diff line number Diff line change
@@ -23,11 +23,54 @@ switch (process.env.POLLY_MODE) {
break;
}

export default function autoSetupPolly() {
/**
/**
*
* ### Example: Ignoring headers (API Keys)
*
* ```ts
* import autoSetupPolly from '../utils/auto-setup-polly';
*
* describe('Group of tests', () => {
* const polly = autoSetupPolly({
* matchRequestsBy: {
* headers: { exclude: ['x-request-id', 'x-api-key'] },
* }
* });
*
* it('Api Request', async () => {
* // Polly will skip matching on the headers `x-request-id` and `x-api-key` in requests,
* // AND prevent the values being recorded!
* // ... test goes here ...
* })
* });
* ```
*
* ### Example: Ignoring generated data using a callback
*
* ```ts
*
* import autoSetupPolly from '../utils/auto-setup-polly';
*
* const polly = autoSetupPolly({
* matchRequestsBy: {
* body(body, req) {
* const json = JSON.parse(body);
*
* delete json.uuid;
* delete json.createdDate;
*
* return JSON.stringify(json);
* }
* });
*
* ```
*
* @param overrideConfig
* @returns
*/
export default function autoSetupPolly(overrideConfig: PollyConfig = {}) {
/*
* This persister can be adapted for both Node.js and Browser environments.
*
* TODO: Customize your config.
*/
return setupPolly({
// 🟡 Note: In node, most `fetch` like libraries use the http/https modules.
@@ -44,5 +87,6 @@ export default function autoSetupPolly() {
recordingsDir: path.resolve(__dirname, "../../__recordings__"),
},
},
...overrideConfig,
});
}