Skip to content

Commit

Permalink
feat(core): Add overrideRecordingName and configure to public API (
Browse files Browse the repository at this point in the history
  • Loading branch information
offirgolan authored Dec 12, 2020
1 parent 6c35fd3 commit cdbf513
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
32 changes: 32 additions & 0 deletions docs/server/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,35 @@ A shortcut method that calls JSON.parse on the request's body.
```js
req.jsonBody();
```

### overrideRecordingName

Override the recording name for the request.

| Param | Type | Description |
| ------------- | -------- | ---------------------- |
| recordingName | `String` | The new recording name |

**Example**

```js
req.overrideRecordingName(req.hostname);
```

### configure

Override configuration options for the request.

| Param | Type | Description |
| ------ | -------- | ------------------------------------- |
| config | `Object` | [Configuration](configuration) object |

**Example**

```js
req.configure({ recordFailedRequests: true });

req.configure({ timing: Timing.relative(3.0) });

req.configure({ logging: true });
```
8 changes: 4 additions & 4 deletions packages/@pollyjs/core/src/-private/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ export default class PollyRequest extends HTTPBase {
this[ROUTE].applyFiltersWithArgs(this);

// Handle config overrides defined by the route
this._configure(this[ROUTE].config());
this.configure(this[ROUTE].config());

// Handle recording name override defined by the route
const recordingName = this[ROUTE].recordingName();

if (recordingName) {
this._overrideRecordingName(recordingName);
this.overrideRecordingName(recordingName);
}
}

Expand Down Expand Up @@ -219,13 +219,13 @@ export default class PollyRequest extends HTTPBase {
this.aborted = true;
}

_overrideRecordingName(recordingName) {
overrideRecordingName(recordingName) {
validateRecordingName(recordingName);
this.recordingName = recordingName;
this.recordingId = guidForRecording(recordingName);
}

_configure(config) {
configure(config) {
validateRequestConfig(config);
this.config = mergeConfigs(this[POLLY].config, this.config || {}, config);
}
Expand Down

0 comments on commit cdbf513

Please sign in to comment.