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

Custom Persister Support #21

Closed
indieisaconcept opened this issue Jun 15, 2018 · 1 comment
Closed

Custom Persister Support #21

indieisaconcept opened this issue Jun 15, 2018 · 1 comment
Assignees
Labels
enhancement ✨ New feature or request

Comments

@indieisaconcept
Copy link

indieisaconcept commented Jun 15, 2018

Hi pollyjs team,

I'd like to suggest adding support for specifying a custom persister in a similar fashion to adapters.

{
    persister: ['<myCustomPersisterName>', myCustomPersister],
}

I've managed to get this working and was wondering if you would be open to accepting a PR for this.

It would require a minor change to @pollyjs/core to support registering custom persisters with the container and ideally @pollyjs/core/src/persisters/persister would be promoted to its own package so that it is more accessible i.e @pollyjs/persister similar to adapters.

const persisterConfig = this.config.persister;
let persisterName = persisterConfig;

if(isArray(persisterConfig)) {
    const [, PersisterType] = persisterConfig;
    persisterName = persisterConfig[0];
    this._container.set(`persister:${persisterName}`, PersisterType);
}

this.persister = new (this._container.get(
  `persister:${persisterName}`
))(this);

The context for this suggestion is that with these minor changes its possible for pollyjs to support recording within Node directly meaning I can use pollyjs for both my client & server tests.

I've this working end-to-end and plan on polishing it further.

Cheers,

Jon

@jasonmit
Copy link
Contributor

I've managed to get this working and was wondering if you would be open to accepting a PR for this.

It would require a minor change to @pollyjs/core to support registering custom persisters with the container and ideally @pollyjs/core/src/persisters/persister would be promoted to its own package so that it is more accessible i.e @pollyjs/persister similar to adapters.

Absolutely! Would appreciate this contribution.

@offirgolan offirgolan self-assigned this Jun 15, 2018
@offirgolan offirgolan added the enhancement ✨ New feature or request label Jun 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants