Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,12 @@
import { mount } from 'enzyme';
export interface MountOptions {
mount: typeof mount;
}
export default function createMount(
options?: Partial<MountOptions>
): typeof mount & {
attachTo: HTMLElement;
cleanUp: Function;
};

View File

@@ -0,0 +1,34 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
// weak
import { unmountComponentAtNode } from 'react-dom';
import { mount as enzymeMount } from 'enzyme';
// Generate an enhanced mount function.
export default function createMount(options1 = {}) {
const { mount = enzymeMount } = options1,
other1 = _objectWithoutProperties(options1, ['mount']);
const attachTo = window.document.createElement('div');
attachTo.className = 'app';
attachTo.setAttribute('id', 'app');
window.document.body.insertBefore(attachTo, window.document.body.firstChild);
const mountWithContext = function mountWithContext(node, options2 = {}) {
return mount(node, _extends({
attachTo
}, other1, options2));
};
mountWithContext.attachTo = attachTo;
mountWithContext.cleanUp = () => {
unmountComponentAtNode(attachTo);
attachTo.parentNode.removeChild(attachTo);
};
return mountWithContext;
}

View File

@@ -0,0 +1,9 @@
import { render } from 'enzyme';
export interface RenderOptions {
render: typeof render;
}
export default function createRender(
options?: Partial<RenderOptions>
): typeof render & { cleanUp: Function };

View File

@@ -0,0 +1,18 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import { render as enzymeRender } from 'enzyme';
// Generate a render to string function.
export default function createRender(options1 = {}) {
const { render = enzymeRender } = options1,
other1 = _objectWithoutProperties(options1, ['render']);
const renderWithContext = function renderWithContext(node, options2 = {}) {
return render(node, _extends({}, other1, options2));
};
return renderWithContext;
}

View File

@@ -0,0 +1,12 @@
import { shallow, EnzymeSelector } from 'enzyme';
export interface ShallowOptions {
shallow: typeof shallow;
otherContext: Object;
dive: boolean;
untilSelector: EnzymeSelector;
}
export default function createShallow(
options?: Partial<ShallowOptions>
): typeof shallow;

View File

@@ -0,0 +1,35 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
// weak
import { shallow as enzymeShallow } from 'enzyme';
import until from './until';
// Generate an enhanced shallow function.
export default function createShallow(options1 = {}) {
const { shallow = enzymeShallow, dive = false, untilSelector = false } = options1,
other1 = _objectWithoutProperties(options1, ['shallow', 'dive', 'untilSelector']);
const shallowWithContext = function shallowWithContext(node, options2 = {}) {
const options = _extends({}, other1, options2, {
context: _extends({}, other1.context, options2.context)
});
const wrapper = shallow(node, options);
if (dive) {
return wrapper.dive();
}
if (untilSelector) {
return until.call(wrapper, untilSelector, options);
}
return wrapper;
};
return shallowWithContext;
}

View File

@@ -0,0 +1,4 @@
export default function getClasses<T = { [name: string]: string }>(
element: React.ReactElement<any>,
options?: Partial<{ withTheme: boolean }>
): T;

View File

@@ -0,0 +1,22 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
import * as ns from 'react-jss/lib/ns';
import { SheetsRegistry } from 'jss';
import createShallow from './createShallow';
import { sheetsManager } from '../styles/withStyles';
const shallow = createShallow();
// Helper function to extract the classes from a styleSheet.
export default function getClasses(element, options = {}) {
const sheetsRegistry = new SheetsRegistry();
sheetsManager.clear();
shallow(element, _extends({}, options, {
context: _extends({
[ns.sheetsRegistry]: sheetsRegistry
}, options.context)
}));
return sheetsRegistry.registry[0].classes;
}

View File

@@ -0,0 +1,4 @@
export { default as createShallow } from './createShallow';
export { default as createMount } from './createMount';
export { default as createRender } from './createRender';
export { default as getClasses } from './getClasses';

View File

@@ -0,0 +1,5 @@
export { default as createShallow } from './createShallow';
export { default as createMount } from './createMount';
export { default as createRender } from './createRender';
export { default as getClasses } from './getClasses';
export { default as unwrap } from './unwrap';

View File

@@ -0,0 +1,6 @@
import { CommonWrapper } from 'enzyme';
export default function until<P = any, S = any>(
selector: string,
options: { context: Object }
): CommonWrapper<P, S>;

View File

@@ -0,0 +1,34 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
// weak
function shallowRecursively(wrapper, selector, _ref) {
let { context } = _ref,
other = _objectWithoutProperties(_ref, ['context']);
if (wrapper.isEmptyRender() || typeof wrapper.getElement().type === 'string') {
return wrapper;
}
let newContext = context;
const instance = wrapper.root().instance();
// The instance can be null with a stateless functional component and react >= 16.
if (instance && instance.getChildContext) {
newContext = _extends({}, context, instance.getChildContext());
}
const nextWrapper = wrapper.shallow(_extends({ context: newContext }, other));
if (selector && wrapper.is(selector)) {
return nextWrapper;
}
return shallowRecursively(nextWrapper, selector, { context: newContext });
}
export default function until(selector, options = {}) {
return this.single('until', () => shallowRecursively(this, selector, options));
}

View File

@@ -0,0 +1,3 @@
export default function unwrap(
element: React.ReactElement<any>
): React.ReactElement<any>

View File

@@ -0,0 +1,5 @@
// weak
export default function unwrap(component) {
return component.Naked ? unwrap(component.Naked) : component;
}