Skip to content

Commit

Permalink
Refactoring getAdapter from Utils into its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
madicap committed Aug 4, 2018
1 parent 290253d commit 27b056a
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 17 deletions.
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

0 comments on commit 27b056a

Please sign in to comment.