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

Deprecates adapter & persister name in favor of id #310

Merged
merged 3 commits into from
Feb 21, 2020

Conversation

jasonmit
Copy link
Contributor

@jasonmit jasonmit commented Feb 20, 2020

Done in a backwards compatible way. In the next major we can remove the deprecations.

Fixes #309

@@ -228,7 +228,8 @@ export default function adapterTests() {
expect(resolved).to.have.members([1, 2, 3]);
});

it('should work with CORS requests', async function() {
// NOTE: test very unstable because of typicode.com being down
it.skip('should work with CORS requests', async function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has been failing off and on for a couple months now, disabling.

return 'rest';
}

static get name() {
Copy link
Contributor Author

@jasonmit jasonmit Feb 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these name getter proxies need to sit on the persister/adapter classes instead of base classes, reason:

class Foo {
  static get name() {
    return 'foo';
  }
}

class Bar extends Foo {}

// "foo" not "Foo"
Foo.name;

// "Bar" not "foo" - always the class/fn `name`, never super's `name`
Bar.name;

this.polly.pause();
await this.fetchRecord({ method: 'DELETE' });
this.polly.play();
if (this.polly) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible for test suite to fail before this.polly is set and made the stderr annoying to scroll through since we always assume it was.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to add an inline comment about this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jasonmit jasonmit changed the title Deprecates name in favor of id Deprecates adapter & persister name in favor of id Feb 20, 2020
@@ -3,7 +3,7 @@ import { MODES, assert } from '@pollyjs/utils';
import { version } from '../package.json';

import Logger from './-private/logger';
import Container from './-private/container';
import Container, { nameOfFactory } from './-private/container';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc rollup has had issues supporting default and named exports. Might need to switch them both to a named export.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and our tests still pass with this issue?

@@ -1,7 +1,19 @@
import { assert } from '@pollyjs/utils';

export function nameOfFactory(Factory) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be idOfFactory or factoryId?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

static get name() {
// NOTE: deprecated in 4.1.0 but proxying since it's possible "core" is behind
// and therefore still referencing `name`. Remove in 5.0.0
return this.id;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just release a new major version instead of having to deal with all of these deprecations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a minor change imo and will help anyone with custom adapters to migrate without reading docs.

this.polly.pause();
await this.fetchRecord({ method: 'DELETE' });
this.polly.play();
if (this.polly) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to add an inline comment about this.

@@ -262,7 +262,7 @@ export default class Polly {

if (typeof nameOrFactory === 'function') {
container.register(nameOrFactory);
adapterName = nameOrFactory.name;
adapterName = nameOfFactory(nameOrFactory);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adapterId

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@jasonmit jasonmit merged commit 41dd093 into master Feb 21, 2020
@jasonmit jasonmit deleted the u/jasonmit/deprecate-name branch February 21, 2020 22:13
geigerzaehler pushed a commit to geigerzaehler/pollyjs that referenced this pull request Apr 19, 2020
The replacement of the static `name` getter for `Adapter` and
`Persister` in Netflix#310 broke custom implementations of these classes
because `id` needed to be overridden. To retain backwards compatibility
we remove the requirement for `id` to be overridden. Instead we delegate
to `name` by default. This does not affect the in-tree implementations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

issue with name property when creating a custom adapter in TS
2 participants