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

Refactoring getAdapter from Utils into its own file #1732

Merged
merged 1 commit into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/enzyme-test-suite/test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
ITERATOR_SYMBOL,
withSetStateAllowed,
sym,
getAdapter,
} from 'enzyme/build/Utils';
import getAdapter from 'enzyme/build/getAdapter';

import './_helpers/setupAdapters';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
ITERATOR_SYMBOL,
withSetStateAllowed,
sym,
getAdapter,
} from 'enzyme/build/Utils';
import getAdapter from 'enzyme/build/getAdapter';

import './_helpers/setupAdapters';
import { createClass, createContext } from './_helpers/react-compat';
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-test-suite/test/Utils-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
displayNameOfNode,
spyMethod,
nodeHasType,
getAdapter,
} from 'enzyme/build/Utils';
import getAdapter from 'enzyme/build/getAdapter';
import {
flatten,
mapNativeEventNames,
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme/src/Debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
propsOfNode,
childrenOfNode,
} from './RSTTraversal';
import { getAdapter } from './Utils';
import getAdapter from './getAdapter';

const booleanValue = Function.bind.call(Function.call, Boolean.prototype.valueOf);

Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme/src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
ITERATOR_SYMBOL,
nodeEqual,
nodeMatches,
getAdapter,
makeOptions,
sym,
privateSet,
cloneElement,
} from './Utils';
import getAdapter from './getAdapter';
import { debugNodes } from './Debug';
import {
propsOfNode,
Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import {
displayNameOfNode,
isCustomComponentElement,
ITERATOR_SYMBOL,
getAdapter,
makeOptions,
sym,
privateSet,
cloneElement,
spyMethod,
} from './Utils';
import getAdapter from './getAdapter';
import { debugNodes } from './Debug';
import {
propsOfNode,
Expand Down
13 changes: 4 additions & 9 deletions packages/enzyme/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ import has from 'has';
import flat from 'array.prototype.flat';

import { get } from './configuration';
import validateAdapter from './validateAdapter';
import { childrenOfNode } from './RSTTraversal';
import realGetAdapter from './getAdapter';

export const ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;

export function getAdapter(options = {}) {
if (options.adapter) {
validateAdapter(options.adapter);
return options.adapter;
}
const { adapter } = get();
validateAdapter(adapter);
return adapter;
console.warn('getAdapter from Utils is deprecated; please use ./getAdapter instead');
return realGetAdapter(options);
}

export function makeOptions(options) {
Expand Down Expand Up @@ -62,7 +57,7 @@ export function typeOfNode(node) {
export function nodeHasType(node, type) {
if (!type || !node) return false;

const adapter = getAdapter();
const adapter = realGetAdapter();
if (adapter.displayNameOfNode) {
const displayName = adapter.displayNameOfNode(node);
return displayName === type;
Expand Down
12 changes: 12 additions & 0 deletions packages/enzyme/src/getAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import validateAdapter from './validateAdapter';
import { get } from './configuration';

export default function getAdapter(options = {}) {
if (options.adapter) {
validateAdapter(options.adapter);
return options.adapter;
}
const { adapter } = get();
validateAdapter(adapter);
return adapter;
}
2 changes: 1 addition & 1 deletion packages/enzyme/src/render.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import cheerio from 'cheerio';
import { getAdapter } from './Utils';
import getAdapter from './getAdapter';

/**
* Renders a react component into static HTML and provides a cheerio wrapper around it. This is
Expand Down
3 changes: 2 additions & 1 deletion packages/enzyme/src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
childrenOfNode,
hasClassName,
} from './RSTTraversal';
import { getAdapter, nodeHasType, propsOfNode } from './Utils';
import { nodeHasType, propsOfNode } from './Utils';
import getAdapter from './getAdapter';
// our CSS selector parser instance
const parser = createParser();

Expand Down