@mighty-justice/tester
Advanced tools
Comparing version 1.4.0 to 2.0.0-0
@@ -1,3 +0,2 @@ | ||
import Tester from './tester'; | ||
import { IConfig, IHook, IProfile, ITesterClass } from './interfaces'; | ||
import { IConfig, IHook, ITesterClass } from './interfaces'; | ||
declare class ConfigurationClass { | ||
@@ -8,13 +7,8 @@ enzyme: any; | ||
}; | ||
profiles: { | ||
[key: string]: IProfile; | ||
}; | ||
Tester: ITesterClass; | ||
constructor(argTester: ITesterClass); | ||
configure(enzyme: any, config: IConfig): ITesterClass; | ||
createShortcuts(): void; | ||
registerHook(hook: IHook): void; | ||
registerProfile(profile: IProfile): void; | ||
getValidHooks(tester: Tester, hookProp: string): IHook[]; | ||
getValidHooks(hookProp: string): IHook[]; | ||
} | ||
export default ConfigurationClass; |
import Tester from './tester'; | ||
import ConfigurationClass from './ConfigurationClass'; | ||
declare const TesterConfig: ConfigurationClass; | ||
export { Tester, TesterConfig, }; | ||
export { Tester, TesterConfig }; |
@@ -1,5 +0,4 @@ | ||
import React, { Component } from 'react'; | ||
import React, { ComponentType } from 'react'; | ||
import Tester from './tester'; | ||
import ConfigurationClass from './ConfigurationClass'; | ||
export declare type ComponentClass = React.FC | (new (props: any) => Component<any>); | ||
export interface IMountOps { | ||
@@ -10,2 +9,3 @@ async?: boolean; | ||
export declare type IOnInit = (tester: Tester) => void; | ||
export declare type IProps = object | ((tester: Tester) => Promise<object>); | ||
export interface IBaseHook { | ||
@@ -21,14 +21,9 @@ [key: string]: any; | ||
export interface IWrapper extends IBaseHook { | ||
component: ComponentClass; | ||
props?: object | (() => void); | ||
component: ComponentType; | ||
props?: IProps; | ||
renderChildren?: boolean; | ||
} | ||
export declare type IHook = IBaseHook | IWrapper; | ||
export interface IProfile { | ||
[key: string]: boolean | string; | ||
name: string; | ||
} | ||
export interface IConfig { | ||
hooks: IHook[]; | ||
profiles: IProfile[]; | ||
} | ||
@@ -38,6 +33,4 @@ export interface ITesterOpts { | ||
onBeforeMount?: (tester: Tester) => Promise<void>; | ||
profile?: IProfile; | ||
props?: object; | ||
shallow?: boolean; | ||
TestedComponent?: ComponentClass; | ||
props?: IProps; | ||
TestedComponent?: ComponentType; | ||
} | ||
@@ -44,0 +37,0 @@ export declare type IBaseTesterClass = typeof Tester; |
@@ -1,4 +0,4 @@ | ||
import React from 'react'; | ||
import React, { ComponentType } from 'react'; | ||
import ConfigurationClass from './ConfigurationClass'; | ||
import { IProfile, ITesterOpts, IWrapper, ComponentClass } from './interfaces'; | ||
import { ITesterOpts, IWrapper, IProps } from './interfaces'; | ||
declare type ISelectArg = string | { | ||
@@ -16,16 +16,13 @@ simulate: (event: string) => void; | ||
onBeforeMount?: (tester: Tester) => Promise<void>; | ||
profile: IProfile; | ||
props: object; | ||
TestedComponent: ComponentClass; | ||
AppState: any; | ||
shallow: any; | ||
props: IProps; | ||
TestedComponent: ComponentType; | ||
wrapper: any; | ||
constructor(TestedComponent: ComponentClass, opts?: ITesterOpts); | ||
constructor(TestedComponent: ComponentType, opts?: ITesterOpts); | ||
getWrappers(): IWrapper[]; | ||
readonly instance: any; | ||
readonly component: any; | ||
get instance(): any; | ||
get component(): any; | ||
debug(): void; | ||
html(): any; | ||
text(): any; | ||
find(selector: string | ComponentClass): any; | ||
find(selector: string | ComponentType): any; | ||
update(): any; | ||
@@ -39,3 +36,2 @@ sleep(ms?: number): Promise<void>; | ||
submit(selector?: ISelectArg): Promise<void>; | ||
createShallowWrapper(): void; | ||
mount(mountOpts?: { | ||
@@ -42,0 +38,0 @@ async?: boolean; |
@@ -39,8 +39,2 @@ import React, { Fragment } from 'react'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
function _defineProperties(target, props) { | ||
@@ -62,4 +56,67 @@ for (var i = 0; i < props.length; i++) { | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { | ||
var it; | ||
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
return function () { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
it = o[Symbol.iterator](); | ||
return it.next.bind(it); | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var runtime_1 = createCommonjsModule(function (module) { | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
var runtime = (function (exports) { | ||
var Op = Object.prototype; | ||
var hasOwn = Op.hasOwnProperty; | ||
var undefined$1; // More compressible than void 0. | ||
var $Symbol = typeof Symbol === "function" ? Symbol : {}; | ||
var iteratorSymbol = $Symbol.iterator || "@@iterator"; | ||
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; | ||
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
function define(obj, key, value) { | ||
Object.defineProperty(obj, key, { | ||
@@ -71,45 +128,726 @@ value: value, | ||
}); | ||
} else { | ||
obj[key] = value; | ||
return obj[key]; | ||
} | ||
try { | ||
// IE 8 has a broken Object.defineProperty that only works on DOM objects. | ||
define({}, ""); | ||
} catch (err) { | ||
define = function(obj, key, value) { | ||
return obj[key] = value; | ||
}; | ||
} | ||
return obj; | ||
} | ||
function wrap(innerFn, outerFn, self, tryLocsList) { | ||
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator. | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; | ||
var generator = Object.create(protoGenerator.prototype); | ||
var context = new Context(tryLocsList || []); | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
// The ._invoke method unifies the implementations of the .next, | ||
// .throw, and .return methods. | ||
generator._invoke = makeInvokeMethod(innerFn, self, context); | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
return generator; | ||
} | ||
exports.wrap = wrap; | ||
// Try/catch helper to minimize deoptimizations. Returns a completion | ||
// record like context.tryEntries[i].completion. This interface could | ||
// have been (and was previously) designed to take a closure to be | ||
// invoked without arguments, but in all the cases we care about we | ||
// already have an existing method we want to call, so there's no need | ||
// to create a new function object. We can even get away with assuming | ||
// the method takes exactly one argument, since that happens to be true | ||
// in every case, so we don't have to touch the arguments object. The | ||
// only additional allocation required is the completion record, which | ||
// has a stable shape and so hopefully should be cheap to allocate. | ||
function tryCatch(fn, obj, arg) { | ||
try { | ||
return { type: "normal", arg: fn.call(obj, arg) }; | ||
} catch (err) { | ||
return { type: "throw", arg: err }; | ||
} | ||
} | ||
var GenStateSuspendedStart = "suspendedStart"; | ||
var GenStateSuspendedYield = "suspendedYield"; | ||
var GenStateExecuting = "executing"; | ||
var GenStateCompleted = "completed"; | ||
// Returning this object from the innerFn has the same effect as | ||
// breaking out of the dispatch switch statement. | ||
var ContinueSentinel = {}; | ||
// Dummy constructor functions that we use as the .constructor and | ||
// .constructor.prototype properties for functions that return Generator | ||
// objects. For full spec compliance, you may wish to configure your | ||
// minifier not to mangle the names of these two functions. | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} | ||
// This is a polyfill for %IteratorPrototype% for environments that | ||
// don't natively support it. | ||
var IteratorPrototype = {}; | ||
IteratorPrototype[iteratorSymbol] = function () { | ||
return this; | ||
}; | ||
var getProto = Object.getPrototypeOf; | ||
var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
if (NativeIteratorPrototype && | ||
NativeIteratorPrototype !== Op && | ||
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { | ||
// This environment has a native %IteratorPrototype%; use it instead | ||
// of the polyfill. | ||
IteratorPrototype = NativeIteratorPrototype; | ||
} | ||
var Gp = GeneratorFunctionPrototype.prototype = | ||
Generator.prototype = Object.create(IteratorPrototype); | ||
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype; | ||
GeneratorFunctionPrototype.constructor = GeneratorFunction; | ||
GeneratorFunction.displayName = define( | ||
GeneratorFunctionPrototype, | ||
toStringTagSymbol, | ||
"GeneratorFunction" | ||
); | ||
// Helper for defining the .next, .throw, and .return methods of the | ||
// Iterator interface in terms of a single ._invoke method. | ||
function defineIteratorMethods(prototype) { | ||
["next", "throw", "return"].forEach(function(method) { | ||
define(prototype, method, function(arg) { | ||
return this._invoke(method, arg); | ||
}); | ||
}); | ||
} | ||
exports.isGeneratorFunction = function(genFun) { | ||
var ctor = typeof genFun === "function" && genFun.constructor; | ||
return ctor | ||
? ctor === GeneratorFunction || | ||
// For the native GeneratorFunction constructor, the best we can | ||
// do is to check its .name property. | ||
(ctor.displayName || ctor.name) === "GeneratorFunction" | ||
: false; | ||
}; | ||
exports.mark = function(genFun) { | ||
if (Object.setPrototypeOf) { | ||
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); | ||
} else { | ||
genFun.__proto__ = GeneratorFunctionPrototype; | ||
define(genFun, toStringTagSymbol, "GeneratorFunction"); | ||
} | ||
genFun.prototype = Object.create(Gp); | ||
return genFun; | ||
}; | ||
// Within the body of any async function, `await x` is transformed to | ||
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test | ||
// `hasOwn.call(value, "__await")` to determine if the yielded value is | ||
// meant to be awaited. | ||
exports.awrap = function(arg) { | ||
return { __await: arg }; | ||
}; | ||
function AsyncIterator(generator, PromiseImpl) { | ||
function invoke(method, arg, resolve, reject) { | ||
var record = tryCatch(generator[method], generator, arg); | ||
if (record.type === "throw") { | ||
reject(record.arg); | ||
} else { | ||
var result = record.arg; | ||
var value = result.value; | ||
if (value && | ||
typeof value === "object" && | ||
hasOwn.call(value, "__await")) { | ||
return PromiseImpl.resolve(value.__await).then(function(value) { | ||
invoke("next", value, resolve, reject); | ||
}, function(err) { | ||
invoke("throw", err, resolve, reject); | ||
}); | ||
} | ||
return PromiseImpl.resolve(value).then(function(unwrapped) { | ||
// When a yielded Promise is resolved, its final value becomes | ||
// the .value of the Promise<{value,done}> result for the | ||
// current iteration. | ||
result.value = unwrapped; | ||
resolve(result); | ||
}, function(error) { | ||
// If a rejected Promise was yielded, throw the rejection back | ||
// into the async generator function so it can be handled there. | ||
return invoke("throw", error, resolve, reject); | ||
}); | ||
} | ||
} | ||
return target; | ||
var previousPromise; | ||
function enqueue(method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function(resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
} | ||
return previousPromise = | ||
// If enqueue has been called before, then we want to wait until | ||
// all previous Promises have been resolved before calling invoke, | ||
// so that results are always delivered in the correct order. If | ||
// enqueue has not been called before, then it is important to | ||
// call invoke immediately, without waiting on a callback to fire, | ||
// so that the async generator function has the opportunity to do | ||
// any necessary setup in a predictable way. This predictability | ||
// is why the Promise constructor synchronously invokes its | ||
// executor callback, and why async functions synchronously | ||
// execute code before the first await. Since we implement simple | ||
// async functions in terms of async generators, it is especially | ||
// important to get this right, even though it requires care. | ||
previousPromise ? previousPromise.then( | ||
callInvokeWithMethodAndArg, | ||
// Avoid propagating failures to Promises returned by later | ||
// invocations of the iterator. | ||
callInvokeWithMethodAndArg | ||
) : callInvokeWithMethodAndArg(); | ||
} | ||
// Define the unified helper method that is used to implement .next, | ||
// .throw, and .return (see defineIteratorMethods). | ||
this._invoke = enqueue; | ||
} | ||
defineIteratorMethods(AsyncIterator.prototype); | ||
AsyncIterator.prototype[asyncIteratorSymbol] = function () { | ||
return this; | ||
}; | ||
exports.AsyncIterator = AsyncIterator; | ||
return _extends.apply(this, arguments); | ||
} | ||
// Note that simple async functions are implemented on top of | ||
// AsyncIterator objects; they just return a Promise for the value of | ||
// the final result produced by the iterator. | ||
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) { | ||
if (PromiseImpl === void 0) PromiseImpl = Promise; | ||
function _objectSpread(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var ownKeys = Object.keys(source); | ||
var iter = new AsyncIterator( | ||
wrap(innerFn, outerFn, self, tryLocsList), | ||
PromiseImpl | ||
); | ||
if (typeof Object.getOwnPropertySymbols === 'function') { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
return exports.isGeneratorFunction(outerFn) | ||
? iter // If outerFn is a generator, return the full iterator. | ||
: iter.next().then(function(result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}; | ||
function makeInvokeMethod(innerFn, self, context) { | ||
var state = GenStateSuspendedStart; | ||
return function invoke(method, arg) { | ||
if (state === GenStateExecuting) { | ||
throw new Error("Generator is already running"); | ||
} | ||
if (state === GenStateCompleted) { | ||
if (method === "throw") { | ||
throw arg; | ||
} | ||
// Be forgiving, per 25.3.3.3.3 of the spec: | ||
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume | ||
return doneResult(); | ||
} | ||
context.method = method; | ||
context.arg = arg; | ||
while (true) { | ||
var delegate = context.delegate; | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
if (context.method === "next") { | ||
// Setting context._sent for legacy support of Babel's | ||
// function.sent implementation. | ||
context.sent = context._sent = context.arg; | ||
} else if (context.method === "throw") { | ||
if (state === GenStateSuspendedStart) { | ||
state = GenStateCompleted; | ||
throw context.arg; | ||
} | ||
context.dispatchException(context.arg); | ||
} else if (context.method === "return") { | ||
context.abrupt("return", context.arg); | ||
} | ||
state = GenStateExecuting; | ||
var record = tryCatch(innerFn, self, context); | ||
if (record.type === "normal") { | ||
// If an exception is thrown from innerFn, we leave state === | ||
// GenStateExecuting and loop back for another invocation. | ||
state = context.done | ||
? GenStateCompleted | ||
: GenStateSuspendedYield; | ||
if (record.arg === ContinueSentinel) { | ||
continue; | ||
} | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} else if (record.type === "throw") { | ||
state = GenStateCompleted; | ||
// Dispatch the exception by looping back around to the | ||
// context.dispatchException(context.arg) call above. | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
} | ||
} | ||
}; | ||
} | ||
// Call delegate.iterator[context.method](context.arg) and handle the | ||
// result, either by returning a { value, done } result from the | ||
// delegate iterator, or by modifying context.method and context.arg, | ||
// setting context.delegate to null, and returning the ContinueSentinel. | ||
function maybeInvokeDelegate(delegate, context) { | ||
var method = delegate.iterator[context.method]; | ||
if (method === undefined$1) { | ||
// A .throw or .return when the delegate iterator has no .throw | ||
// method always terminates the yield* loop. | ||
context.delegate = null; | ||
if (context.method === "throw") { | ||
// Note: ["return"] must be used for ES3 parsing compatibility. | ||
if (delegate.iterator["return"]) { | ||
// If the delegate iterator has a return method, give it a | ||
// chance to clean up. | ||
context.method = "return"; | ||
context.arg = undefined$1; | ||
maybeInvokeDelegate(delegate, context); | ||
if (context.method === "throw") { | ||
// If maybeInvokeDelegate(context) changed context.method from | ||
// "return" to "throw", let that override the TypeError below. | ||
return ContinueSentinel; | ||
} | ||
} | ||
context.method = "throw"; | ||
context.arg = new TypeError( | ||
"The iterator does not provide a 'throw' method"); | ||
} | ||
return ContinueSentinel; | ||
} | ||
ownKeys.forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
if (record.type === "throw") { | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
var info = record.arg; | ||
if (! info) { | ||
context.method = "throw"; | ||
context.arg = new TypeError("iterator result is not an object"); | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
if (info.done) { | ||
// Assign the result of the finished delegate to the temporary | ||
// variable specified by delegate.resultName (see delegateYield). | ||
context[delegate.resultName] = info.value; | ||
// Resume execution at the desired location (see delegateYield). | ||
context.next = delegate.nextLoc; | ||
// If context.method was "throw" but the delegate handled the | ||
// exception, let the outer generator proceed normally. If | ||
// context.method was "next", forget context.arg since it has been | ||
// "consumed" by the delegate iterator. If context.method was | ||
// "return", allow the original .return call to continue in the | ||
// outer generator. | ||
if (context.method !== "return") { | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
} else { | ||
// Re-yield the result returned by the delegate method. | ||
return info; | ||
} | ||
// The delegate iterator is finished, so forget it and continue with | ||
// the outer generator. | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
return target; | ||
// Define Generator.prototype.{next,throw,return} in terms of the | ||
// unified ._invoke helper method. | ||
defineIteratorMethods(Gp); | ||
define(Gp, toStringTagSymbol, "Generator"); | ||
// A Generator should always return itself as the iterator object when the | ||
// @@iterator function is called on it. Some browsers' implementations of the | ||
// iterator prototype chain incorrectly implement this, causing the Generator | ||
// object to not be returned from this call. This ensures that doesn't happen. | ||
// See https://github.com/facebook/regenerator/issues/274 for more details. | ||
Gp[iteratorSymbol] = function() { | ||
return this; | ||
}; | ||
Gp.toString = function() { | ||
return "[object Generator]"; | ||
}; | ||
function pushTryEntry(locs) { | ||
var entry = { tryLoc: locs[0] }; | ||
if (1 in locs) { | ||
entry.catchLoc = locs[1]; | ||
} | ||
if (2 in locs) { | ||
entry.finallyLoc = locs[2]; | ||
entry.afterLoc = locs[3]; | ||
} | ||
this.tryEntries.push(entry); | ||
} | ||
function resetTryEntry(entry) { | ||
var record = entry.completion || {}; | ||
record.type = "normal"; | ||
delete record.arg; | ||
entry.completion = record; | ||
} | ||
function Context(tryLocsList) { | ||
// The root entry object (effectively a try statement without a catch | ||
// or a finally block) gives us a place to store values thrown from | ||
// locations where there is no enclosing try statement. | ||
this.tryEntries = [{ tryLoc: "root" }]; | ||
tryLocsList.forEach(pushTryEntry, this); | ||
this.reset(true); | ||
} | ||
exports.keys = function(object) { | ||
var keys = []; | ||
for (var key in object) { | ||
keys.push(key); | ||
} | ||
keys.reverse(); | ||
// Rather than returning an object with a next method, we keep | ||
// things simple and return the next function itself. | ||
return function next() { | ||
while (keys.length) { | ||
var key = keys.pop(); | ||
if (key in object) { | ||
next.value = key; | ||
next.done = false; | ||
return next; | ||
} | ||
} | ||
// To avoid creating an additional object, we just hang the .value | ||
// and .done properties off the next function object itself. This | ||
// also ensures that the minifier will not anonymize the function. | ||
next.done = true; | ||
return next; | ||
}; | ||
}; | ||
function values(iterable) { | ||
if (iterable) { | ||
var iteratorMethod = iterable[iteratorSymbol]; | ||
if (iteratorMethod) { | ||
return iteratorMethod.call(iterable); | ||
} | ||
if (typeof iterable.next === "function") { | ||
return iterable; | ||
} | ||
if (!isNaN(iterable.length)) { | ||
var i = -1, next = function next() { | ||
while (++i < iterable.length) { | ||
if (hasOwn.call(iterable, i)) { | ||
next.value = iterable[i]; | ||
next.done = false; | ||
return next; | ||
} | ||
} | ||
next.value = undefined$1; | ||
next.done = true; | ||
return next; | ||
}; | ||
return next.next = next; | ||
} | ||
} | ||
// Return an iterator with no values. | ||
return { next: doneResult }; | ||
} | ||
exports.values = values; | ||
function doneResult() { | ||
return { value: undefined$1, done: true }; | ||
} | ||
Context.prototype = { | ||
constructor: Context, | ||
reset: function(skipTempReset) { | ||
this.prev = 0; | ||
this.next = 0; | ||
// Resetting context._sent for legacy support of Babel's | ||
// function.sent implementation. | ||
this.sent = this._sent = undefined$1; | ||
this.done = false; | ||
this.delegate = null; | ||
this.method = "next"; | ||
this.arg = undefined$1; | ||
this.tryEntries.forEach(resetTryEntry); | ||
if (!skipTempReset) { | ||
for (var name in this) { | ||
// Not sure about the optimal order of these conditions: | ||
if (name.charAt(0) === "t" && | ||
hasOwn.call(this, name) && | ||
!isNaN(+name.slice(1))) { | ||
this[name] = undefined$1; | ||
} | ||
} | ||
} | ||
}, | ||
stop: function() { | ||
this.done = true; | ||
var rootEntry = this.tryEntries[0]; | ||
var rootRecord = rootEntry.completion; | ||
if (rootRecord.type === "throw") { | ||
throw rootRecord.arg; | ||
} | ||
return this.rval; | ||
}, | ||
dispatchException: function(exception) { | ||
if (this.done) { | ||
throw exception; | ||
} | ||
var context = this; | ||
function handle(loc, caught) { | ||
record.type = "throw"; | ||
record.arg = exception; | ||
context.next = loc; | ||
if (caught) { | ||
// If the dispatched exception was caught by a catch block, | ||
// then let that catch block handle the exception normally. | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
return !! caught; | ||
} | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
var record = entry.completion; | ||
if (entry.tryLoc === "root") { | ||
// Exception thrown outside of any try block that could handle | ||
// it, so set the completion value of the entire function to | ||
// throw the exception. | ||
return handle("end"); | ||
} | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"); | ||
var hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
if (hasCatch && hasFinally) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} else if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
} else if (hasCatch) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} | ||
} else if (hasFinally) { | ||
if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
} else { | ||
throw new Error("try statement without catch or finally"); | ||
} | ||
} | ||
} | ||
}, | ||
abrupt: function(type, arg) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc <= this.prev && | ||
hasOwn.call(entry, "finallyLoc") && | ||
this.prev < entry.finallyLoc) { | ||
var finallyEntry = entry; | ||
break; | ||
} | ||
} | ||
if (finallyEntry && | ||
(type === "break" || | ||
type === "continue") && | ||
finallyEntry.tryLoc <= arg && | ||
arg <= finallyEntry.finallyLoc) { | ||
// Ignore the finally entry if control is not jumping to a | ||
// location outside the try/catch block. | ||
finallyEntry = null; | ||
} | ||
var record = finallyEntry ? finallyEntry.completion : {}; | ||
record.type = type; | ||
record.arg = arg; | ||
if (finallyEntry) { | ||
this.method = "next"; | ||
this.next = finallyEntry.finallyLoc; | ||
return ContinueSentinel; | ||
} | ||
return this.complete(record); | ||
}, | ||
complete: function(record, afterLoc) { | ||
if (record.type === "throw") { | ||
throw record.arg; | ||
} | ||
if (record.type === "break" || | ||
record.type === "continue") { | ||
this.next = record.arg; | ||
} else if (record.type === "return") { | ||
this.rval = this.arg = record.arg; | ||
this.method = "return"; | ||
this.next = "end"; | ||
} else if (record.type === "normal" && afterLoc) { | ||
this.next = afterLoc; | ||
} | ||
return ContinueSentinel; | ||
}, | ||
finish: function(finallyLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.finallyLoc === finallyLoc) { | ||
this.complete(entry.completion, entry.afterLoc); | ||
resetTryEntry(entry); | ||
return ContinueSentinel; | ||
} | ||
} | ||
}, | ||
"catch": function(tryLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc === tryLoc) { | ||
var record = entry.completion; | ||
if (record.type === "throw") { | ||
var thrown = record.arg; | ||
resetTryEntry(entry); | ||
} | ||
return thrown; | ||
} | ||
} | ||
// The context.catch method must only be called with a location | ||
// argument that corresponds to a known catch block. | ||
throw new Error("illegal catch attempt"); | ||
}, | ||
delegateYield: function(iterable, resultName, nextLoc) { | ||
this.delegate = { | ||
iterator: values(iterable), | ||
resultName: resultName, | ||
nextLoc: nextLoc | ||
}; | ||
if (this.method === "next") { | ||
// Deliberately forget the last sent value so that we don't | ||
// accidentally pass it on to the delegate. | ||
this.arg = undefined$1; | ||
} | ||
return ContinueSentinel; | ||
} | ||
}; | ||
// Regardless of whether this script is executing as a CommonJS module | ||
// or not, return the runtime object so that we can declare the variable | ||
// regeneratorRuntime in the outer scope, which allows this module to be | ||
// injected easily by `bin/regenerator --include-runtime script.js`. | ||
return exports; | ||
}( | ||
// If this script is executing as a CommonJS module, use module.exports | ||
// as the regeneratorRuntime namespace. Otherwise create a new empty | ||
// object. Either way, the resulting object will be used to initialize | ||
// the regeneratorRuntime variable at the top of this file. | ||
module.exports | ||
)); | ||
try { | ||
regeneratorRuntime = runtime; | ||
} catch (accidentalStrictMode) { | ||
// This module should not be running in strict mode, so the above | ||
// assignment should always work unless something is misconfigured. Just | ||
// in case runtime.js accidentally runs in strict mode, we can escape | ||
// strict mode using a global Function call. This could conceivably fail | ||
// if a Content Security Policy forbids using Function, but in that case | ||
// the proper solution is to fix the accidental strict mode problem. If | ||
// you've misconfigured your bundler to force strict mode and applied a | ||
// CSP to forbid Function, and you're not willing to fix either of those | ||
// problems, please detail your unique predicament in a GitHub issue. | ||
Function("r", "regeneratorRuntime = r")(runtime); | ||
} | ||
}); | ||
@@ -123,6 +861,42 @@ /* | ||
} | ||
function getValue(tester, value) { | ||
return typeof value === 'function' ? value(tester) : value; | ||
function getValue(_x, _x2) { | ||
return _getValue.apply(this, arguments); | ||
} | ||
function sleep() { | ||
function _getValue() { | ||
_getValue = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(tester, value) { | ||
return runtime_1.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!(typeof value === 'function')) { | ||
_context.next = 6; | ||
break; | ||
} | ||
_context.next = 3; | ||
return value(tester); | ||
case 3: | ||
_context.t0 = _context.sent; | ||
_context.next = 7; | ||
break; | ||
case 6: | ||
_context.t0 = value; | ||
case 7: | ||
return _context.abrupt("return", _context.t0); | ||
case 8: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _getValue.apply(this, arguments); | ||
} | ||
function sleep(_x3) { | ||
return _sleep.apply(this, arguments); | ||
@@ -132,13 +906,12 @@ } | ||
function _sleep() { | ||
_sleep = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee() { | ||
var ms, | ||
_args = arguments; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
_sleep = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(ms) { | ||
return runtime_1.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
ms = _args.length > 0 && _args[0] !== undefined ? _args[0] : 0; | ||
return _context.abrupt("return", new Promise(function (resolve) { | ||
if (ms === void 0) { | ||
ms = 0; | ||
} | ||
return _context2.abrupt("return", new Promise(function (resolve) { | ||
return setTimeout(resolve, ms); | ||
@@ -149,6 +922,6 @@ })); | ||
case "end": | ||
return _context.stop(); | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
}, _callee2); | ||
})); | ||
@@ -158,5 +931,2 @@ return _sleep.apply(this, arguments); | ||
function capitalize(string) { | ||
return string.charAt(0).toUpperCase() + string.slice(1); | ||
} | ||
function isString(value) { | ||
@@ -170,10 +940,8 @@ return typeof value === 'string' || value instanceof String; | ||
function _flushPromises() { | ||
_flushPromises = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee2() { | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
_flushPromises = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() { | ||
return runtime_1.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
return _context2.abrupt("return", new Promise(function (resolve, _reject) { | ||
return _context3.abrupt("return", new Promise(function (resolve, _reject) { | ||
return setImmediate(resolve); | ||
@@ -184,6 +952,6 @@ })); | ||
case "end": | ||
return _context2.stop(); | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
}, _callee3); | ||
})); | ||
@@ -194,3 +962,3 @@ return _flushPromises.apply(this, arguments); | ||
var NullComponent = function NullComponent(props) { | ||
return React.createElement(Fragment, props); | ||
return React.createElement(Fragment, Object.assign({}, props)); | ||
}; | ||
@@ -216,8 +984,2 @@ /* | ||
const tester = await new Tester(MyComponent).mount(); | ||
// opts.shallow is an experimental feature that allows you to test the TestedComponent instance behaviors. | ||
// Please only use it when necessary. | ||
const tester = await new Tester(MyComponent, { shallow: true }).mount(); | ||
tester.shallow.wrapper // equals to shallow(<TestedComponent {...this.props} {...this.AppState} />) | ||
tester.shallow.instance // equals to tester.shallow.instance() | ||
*/ | ||
@@ -230,22 +992,10 @@ | ||
var Tester = | ||
/*#__PURE__*/ | ||
function () { | ||
function Tester(TestedComponent) { | ||
var Tester = /*#__PURE__*/function () { | ||
function Tester(TestedComponent, opts) { | ||
var _this = this; | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
_classCallCheck(this, Tester); | ||
this.opts = void 0; | ||
this.config = void 0; | ||
this.initialMount = void 0; | ||
this.onBeforeMount = void 0; | ||
this.profile = void 0; | ||
this.props = void 0; | ||
this.TestedComponent = void 0; | ||
this.AppState = void 0; | ||
this.shallow = void 0; | ||
this.wrapper = void 0; | ||
this.config = Tester.Configuration; | ||
@@ -255,3 +1005,2 @@ this.initialMount = opts.mount; | ||
this.opts = opts; | ||
this.profile = _objectSpread({}, this.config.profiles.Default, opts.profile); | ||
this.props = opts.props || {}; | ||
@@ -266,3 +1015,3 @@ this.TestedComponent = TestedComponent; // Allow testing without a main TestedComponent. This require an initialMount. | ||
var validHooks = this.config.getValidHooks(this, 'onInit'); | ||
var validHooks = this.config.getValidHooks('onInit'); | ||
validHooks.forEach(function (hook) { | ||
@@ -273,323 +1022,254 @@ return hook.onInit(_this); | ||
_createClass(Tester, [{ | ||
key: "getWrappers", | ||
value: function getWrappers() { | ||
var _this2 = this; | ||
var _proto = Tester.prototype; | ||
var wrappers = []; | ||
this.config.getValidHooks(this, 'component').forEach(function (hook) { | ||
wrappers.push({ | ||
component: hook.component, | ||
name: hook.name, | ||
props: getValue(_this2, hook.props) | ||
}); | ||
_proto.getWrappers = function getWrappers() { | ||
var _this2 = this; | ||
var wrappers = []; | ||
this.config.getValidHooks('component').forEach(function (hook) { | ||
wrappers.push({ | ||
component: hook.component, | ||
name: hook.name, | ||
props: getValue(_this2, hook.props) | ||
}); | ||
return wrappers; | ||
} | ||
}, { | ||
key: "debug", | ||
value: function debug() { | ||
// tslint:disable-next-line:no-console | ||
console.log(this.wrapper.debug()); | ||
} | ||
}, { | ||
key: "html", | ||
value: function html() { | ||
return this.component.html(); | ||
} | ||
}, { | ||
key: "text", | ||
value: function text() { | ||
return this.component.text(); | ||
} | ||
}, { | ||
key: "find", | ||
value: function find(selector) { | ||
return this.wrapper.find(selector); | ||
} | ||
}, { | ||
key: "update", | ||
value: function update() { | ||
return this.wrapper.update(); | ||
} | ||
}, { | ||
key: "sleep", | ||
value: function () { | ||
var _sleep2 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(ms) { | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return sleep(ms); | ||
}); | ||
return wrappers; | ||
}; | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
_proto.debug = function debug() { | ||
// tslint:disable-next-line:no-console | ||
console.log(this.wrapper.debug()); | ||
}; | ||
function sleep$$1(_x) { | ||
return _sleep2.apply(this, arguments); | ||
} | ||
_proto.html = function html() { | ||
return this.component.html(); | ||
}; | ||
return sleep$$1; | ||
}() | ||
}, { | ||
key: "refresh", | ||
value: function () { | ||
var _refresh = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee2(ms) { | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return sleep(ms); | ||
_proto.text = function text() { | ||
return this.component.text(); | ||
}; | ||
case 2: | ||
this.update(); | ||
_proto.find = function find(selector) { | ||
return this.wrapper.find(selector); | ||
}; | ||
case 3: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
_proto.update = function update() { | ||
return this.wrapper.update(); | ||
}; | ||
function refresh(_x2) { | ||
return _refresh.apply(this, arguments); | ||
} | ||
_proto.sleep = /*#__PURE__*/function () { | ||
var _sleep2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(ms) { | ||
return runtime_1.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return sleep(ms); | ||
return refresh; | ||
}() | ||
}, { | ||
key: "getComponent", | ||
value: function getComponent(selector) { | ||
return isString(selector) ? this.find(selector).first() : selector; | ||
} | ||
}, { | ||
key: "changeInput", | ||
value: function changeInput(selector, value) { | ||
var component = this.getComponent(selector); | ||
component.simulate('focus'); | ||
component.simulate('change', { | ||
target: { | ||
value: value | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}); | ||
component.simulate('blur'); | ||
}, _callee); | ||
})); | ||
function sleep$1(_x) { | ||
return _sleep2.apply(this, arguments); | ||
} | ||
}, { | ||
key: "checkBox", | ||
value: function checkBox(selector) { | ||
var checked = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
var component = this.getComponent(selector); | ||
component.simulate('change', { | ||
target: { | ||
checked: checked | ||
return sleep$1; | ||
}(); | ||
_proto.refresh = /*#__PURE__*/function () { | ||
var _refresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(ms) { | ||
return runtime_1.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return sleep(ms); | ||
case 2: | ||
this.update(); | ||
case 3: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}); | ||
}, _callee2, this); | ||
})); | ||
function refresh(_x2) { | ||
return _refresh.apply(this, arguments); | ||
} | ||
}, { | ||
key: "click", | ||
value: function click(selector) { | ||
var component = this.getComponent(selector); | ||
component.simulate('click'); | ||
} | ||
}, { | ||
key: "submit", | ||
value: function () { | ||
var _submit = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee3() { | ||
var selector, | ||
component, | ||
_args3 = arguments; | ||
return regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
selector = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : 'form'; | ||
component = this.getComponent(selector); | ||
component.simulate('submit'); | ||
_context3.next = 5; | ||
return this.refresh(); | ||
case 5: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, this); | ||
})); | ||
return refresh; | ||
}(); | ||
function submit() { | ||
return _submit.apply(this, arguments); | ||
_proto.getComponent = function getComponent(selector) { | ||
return isString(selector) ? this.find(selector).first() : selector; | ||
}; | ||
_proto.changeInput = function changeInput(selector, value) { | ||
var component = this.getComponent(selector); | ||
component.simulate('focus'); | ||
component.simulate('change', { | ||
target: { | ||
value: value | ||
} | ||
}); | ||
component.simulate('blur'); | ||
}; | ||
return submit; | ||
}() | ||
}, { | ||
key: "createShallowWrapper", | ||
value: function createShallowWrapper() { | ||
this.shallow = {}; | ||
var WrappedComponent = this.TestedComponent.wrappedComponent; | ||
this.shallow.wrapper = this.config.enzyme.mount(React.createElement(WrappedComponent, _extends({}, this.props, this.AppState))); | ||
this.shallow.instance = getInstance(this.shallow.wrapper); | ||
_proto.checkBox = function checkBox(selector, checked) { | ||
if (checked === void 0) { | ||
checked = true; | ||
} | ||
}, { | ||
key: "mount", | ||
value: function () { | ||
var _mount = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee4() { | ||
var mountOpts, | ||
validHooks, | ||
_iteratorNormalCompletion, | ||
_didIteratorError, | ||
_iteratorError, | ||
_iterator, | ||
_step, | ||
hook, | ||
initialMount, | ||
WrapperTree, | ||
_args4 = arguments; | ||
return regeneratorRuntime.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
mountOpts = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {}; | ||
validHooks = this.config.getValidHooks(this, 'onBeforeMount'); | ||
_iteratorNormalCompletion = true; | ||
_didIteratorError = false; | ||
_iteratorError = undefined; | ||
_context4.prev = 5; | ||
_iterator = validHooks[Symbol.iterator](); | ||
var component = this.getComponent(selector); | ||
component.simulate('change', { | ||
target: { | ||
checked: checked | ||
} | ||
}); | ||
}; | ||
case 7: | ||
if (_iteratorNormalCompletion = (_step = _iterator.next()).done) { | ||
_context4.next = 14; | ||
break; | ||
} | ||
_proto.click = function click(selector) { | ||
var component = this.getComponent(selector); | ||
component.simulate('click'); | ||
}; | ||
hook = _step.value; | ||
_context4.next = 11; | ||
return hook.onBeforeMount(this, mountOpts); | ||
_proto.submit = /*#__PURE__*/function () { | ||
var _submit = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(selector) { | ||
var component; | ||
return runtime_1.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
if (selector === void 0) { | ||
selector = 'form'; | ||
} | ||
case 11: | ||
_iteratorNormalCompletion = true; | ||
_context4.next = 7; | ||
break; | ||
component = this.getComponent(selector); | ||
component.simulate('submit'); | ||
_context3.next = 5; | ||
return this.refresh(); | ||
case 14: | ||
_context4.next = 20; | ||
break; | ||
case 5: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, this); | ||
})); | ||
case 16: | ||
_context4.prev = 16; | ||
_context4.t0 = _context4["catch"](5); | ||
_didIteratorError = true; | ||
_iteratorError = _context4.t0; | ||
function submit(_x3) { | ||
return _submit.apply(this, arguments); | ||
} | ||
case 20: | ||
_context4.prev = 20; | ||
_context4.prev = 21; | ||
return submit; | ||
}(); | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
_proto.mount = /*#__PURE__*/function () { | ||
var _mount = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(mountOpts) { | ||
var validHooks, _iterator, _step, hook, props, initialMount, WrapperTree; | ||
case 23: | ||
_context4.prev = 23; | ||
return runtime_1.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
if (mountOpts === void 0) { | ||
mountOpts = {}; | ||
} | ||
if (!_didIteratorError) { | ||
_context4.next = 26; | ||
break; | ||
} | ||
validHooks = this.config.getValidHooks('onBeforeMount'); | ||
_iterator = _createForOfIteratorHelperLoose(validHooks); | ||
throw _iteratorError; | ||
case 3: | ||
if ((_step = _iterator()).done) { | ||
_context4.next = 9; | ||
break; | ||
} | ||
case 26: | ||
return _context4.finish(23); | ||
hook = _step.value; | ||
_context4.next = 7; | ||
return hook.onBeforeMount(this, mountOpts); | ||
case 27: | ||
return _context4.finish(20); | ||
case 7: | ||
_context4.next = 3; | ||
break; | ||
case 28: | ||
if (!this.onBeforeMount) { | ||
_context4.next = 31; | ||
break; | ||
} | ||
case 9: | ||
if (!this.onBeforeMount) { | ||
_context4.next = 12; | ||
break; | ||
} | ||
_context4.next = 31; | ||
return this.onBeforeMount(this); | ||
_context4.next = 12; | ||
return this.onBeforeMount(this); | ||
case 31: | ||
initialMount = this.initialMount || React.createElement(this.TestedComponent, this.props); | ||
WrapperTree = this.getWrappers().reduce(function (Tree, wrapper) { | ||
var wrapperChildren = wrapper.renderChildren !== false && Tree; | ||
case 12: | ||
_context4.next = 14; | ||
return getValue(this, this.props); | ||
if (wrapper.props) { | ||
return React.createElement(wrapper.component, wrapper.props, wrapperChildren); | ||
} | ||
case 14: | ||
props = _context4.sent; | ||
initialMount = this.initialMount || React.createElement(this.TestedComponent, Object.assign({}, props)); | ||
WrapperTree = this.getWrappers().reduce(function (Tree, wrapper) { | ||
var wrapperChildren = wrapper.renderChildren !== false && Tree; | ||
return Tree; | ||
}, initialMount); | ||
_context4.next = 35; | ||
return this.config.enzyme.mount(WrapperTree); | ||
if (wrapper.props) { | ||
return React.createElement(wrapper.component, Object.assign({}, wrapper.props), wrapperChildren); | ||
} | ||
case 35: | ||
this.wrapper = _context4.sent; | ||
return Tree; | ||
}, initialMount); | ||
_context4.next = 19; | ||
return this.config.enzyme.mount(WrapperTree); | ||
if (this.opts.shallow) { | ||
this.createShallowWrapper(); | ||
} | ||
case 19: | ||
this.wrapper = _context4.sent; | ||
if (!(mountOpts.async !== false)) { | ||
_context4.next = 45; | ||
break; | ||
} | ||
if (!(mountOpts.async !== false)) { | ||
_context4.next = 28; | ||
break; | ||
} | ||
if (!this.instance) { | ||
_context4.next = 41; | ||
break; | ||
} | ||
if (!this.instance) { | ||
_context4.next = 24; | ||
break; | ||
} | ||
_context4.next = 41; | ||
return this.instance.componentDidMount(); | ||
_context4.next = 24; | ||
return this.instance.componentDidMount(); | ||
case 41: | ||
_context4.next = 43; | ||
return flushPromises(); | ||
case 24: | ||
_context4.next = 26; | ||
return flushPromises(); | ||
case 43: | ||
_context4.next = 45; | ||
return this.refresh(); | ||
case 26: | ||
_context4.next = 28; | ||
return this.refresh(); | ||
case 45: | ||
return _context4.abrupt("return", this); | ||
case 28: | ||
return _context4.abrupt("return", this); | ||
case 46: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
case 29: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
}, _callee4, this, [[5, 16, 20, 28], [21,, 23, 27]]); | ||
})); | ||
} | ||
}, _callee4, this); | ||
})); | ||
function mount() { | ||
return _mount.apply(this, arguments); | ||
} | ||
function mount(_x4) { | ||
return _mount.apply(this, arguments); | ||
} | ||
return mount; | ||
}() | ||
}, { | ||
return mount; | ||
}(); | ||
_createClass(Tester, [{ | ||
key: "instance", | ||
@@ -609,20 +1289,8 @@ get: function get() { | ||
Tester.Configuration = void 0; | ||
/* | ||
Tester Configuration Class | ||
*/ | ||
var ConfigurationClass = | ||
/*#__PURE__*/ | ||
function () { | ||
var ConfigurationClass = /*#__PURE__*/function () { | ||
function ConfigurationClass(argTester) { | ||
_classCallCheck(this, ConfigurationClass); | ||
this.enzyme = void 0; | ||
this.hooks = {}; | ||
this.profiles = { | ||
// Default profile, each of it's properties can be overwritten. | ||
Default: {} | ||
}; | ||
this.Tester = void 0; | ||
this.Tester = argTester; | ||
@@ -632,127 +1300,67 @@ argTester.Configuration = this; | ||
_createClass(ConfigurationClass, [{ | ||
key: "configure", | ||
value: function configure(enzyme, config) { | ||
var _this = this; | ||
var _proto = ConfigurationClass.prototype; | ||
this.enzyme = enzyme; | ||
_proto.configure = function configure(enzyme, config) { | ||
var _this = this; | ||
if (config.hooks) { | ||
config.hooks.forEach(function (hook) { | ||
_this.registerHook(hook); | ||
}); | ||
} | ||
this.enzyme = enzyme; | ||
if (config.profiles) { | ||
config.profiles.forEach(function (profile) { | ||
_this.registerProfile(profile); | ||
}); | ||
} | ||
this.createShortcuts(); | ||
return this.Tester; | ||
if (config.hooks) { | ||
config.hooks.forEach(function (hook) { | ||
_this.registerHook(hook); | ||
}); | ||
} | ||
/* | ||
Create shortcuts for each global profiles | ||
Tester shortcuts allows you to use a specific global profile without having to pass it in in the options. | ||
E.g. | ||
Using a new Tester.Light(MyComponent) allows you to skip the initialization of | ||
Transport, localStorage + Session and AppState. | ||
*/ | ||
}, { | ||
key: "createShortcuts", | ||
value: function createShortcuts() { | ||
var _this2 = this; | ||
Object.keys(this.profiles).forEach(function (profileKey) { | ||
_this2.Tester[profileKey] = function (TestedComponent) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new _this2.Tester(TestedComponent, _objectSpread({}, opts, { | ||
profile: _this2.profiles[profileKey] | ||
})); | ||
}; | ||
}); | ||
return this.Tester; | ||
} | ||
/* | ||
Hooks, | ||
{ | ||
name: string, | ||
component: React.Component, | ||
props: object || fn(), // fn() allows this.AppState to be set for e.g | ||
onInit: fn(), | ||
onBeforeMount: fn(), | ||
shortCuts: {shortCutName: fn()}, | ||
wrapper: fn() => { Component: React.Component, name: string, props: object } | ||
} | ||
/* | ||
Hooks, | ||
{ | ||
name: string, | ||
component: React.Component, | ||
props: object || fn(), // fn() allows this.AppState to be set for e.g | ||
onInit: fn(), | ||
onBeforeMount: fn(), | ||
shortCuts: {shortCutName: fn()}, | ||
wrapper: fn() => { Component: React.Component, name: string, props: object } | ||
} | ||
Note: Order is important! | ||
*/ | ||
*/ | ||
; | ||
}, { | ||
key: "registerHook", | ||
value: function registerHook(hook) { | ||
if (!hook.name) { | ||
throw new Error('Tester.registerHook() : A hooks must have a name.'); | ||
} | ||
if (this.hooks[hook.name]) { | ||
throw new Error("Tester.registerHook() : A hook named \"".concat(hook.name, "\" already exist.")); | ||
} // Validate hook properties here. | ||
this.hooks[hook.name] = hook; | ||
_proto.registerHook = function registerHook(hook) { | ||
if (!hook.name) { | ||
throw new Error('Tester.registerHook() : A hooks must have a name.'); | ||
} | ||
/* | ||
Profiles, | ||
{ | ||
// Profile keys must be hook names. | ||
} | ||
*/ | ||
}, { | ||
key: "registerProfile", | ||
value: function registerProfile(profile) { | ||
if (!profile.name) { | ||
throw new Error('Tester.registerHook() : A hooks must have a name.'); | ||
} | ||
if (this.hooks[hook.name]) { | ||
throw new Error("Tester.registerHook() : A hook named \"" + hook.name + "\" already exist."); | ||
} // Validate hook properties here. | ||
var capitalizedName = capitalize(profile.name); | ||
if (this.profiles[capitalizedName] && capitalizedName !== 'Default') { | ||
throw new Error("Tester.registerProfile() : A profile named \"".concat(capitalizedName, "\" already exist.")); | ||
} // Validate profile properties here. | ||
// - Does every key or the profile is a hook ? | ||
this.hooks[hook.name] = hook; | ||
}; | ||
_proto.getValidHooks = function getValidHooks(hookProp) { | ||
var hooks = []; | ||
Object.values(this.hooks).forEach(function (hook) { | ||
var valid = true; | ||
this.profiles[capitalizedName] = profile; | ||
} | ||
}, { | ||
key: "getValidHooks", | ||
value: function getValidHooks(tester, hookProp) { | ||
var hooks = []; | ||
Object.values(this.hooks).forEach(function (hook) { | ||
var valid = true; | ||
if (hookProp && !hook[hookProp]) { | ||
valid = false; | ||
} | ||
if (!tester.profile[hook.name]) { | ||
valid = false; | ||
} | ||
if (valid) { | ||
hooks.push(hook); | ||
} | ||
}); | ||
return hooks; | ||
}; | ||
if (hookProp && !hook[hookProp]) { | ||
valid = false; | ||
} | ||
if (valid) { | ||
hooks.push(hook); | ||
} | ||
}); | ||
return hooks; | ||
} | ||
}]); | ||
return ConfigurationClass; | ||
}(); | ||
var TesterConfig = new ConfigurationClass(Tester); | ||
var TesterConfig = /*#__PURE__*/new ConfigurationClass(Tester); | ||
export { Tester, TesterConfig }; | ||
//# sourceMappingURL=tester.esm.js.map |
export declare function getInstance(component: any): any; | ||
export declare function getValue(tester: any, value: unknown): any; | ||
export declare function getValue(tester: any, value: unknown): Promise<any>; | ||
export declare function sleep(ms?: number): Promise<void>; | ||
export declare function capitalize(string: string): string; | ||
export declare function isString(value: unknown): value is string; | ||
export declare function flushPromises(): Promise<void>; |
119
package.json
{ | ||
"name": "@mighty-justice/tester", | ||
"version": "1.4.0", | ||
"version": "2.0.0-0", | ||
"description": "Bootstrap your tests!", | ||
"main": "dist/tester.cjs.js", | ||
"main": "dist/index.js", | ||
"module": "dist/tester.esm.js", | ||
"browser": "dist/tester.umd.js", | ||
"typings": "dist/index.d.ts", | ||
"types": "dist/index.d.ts", | ||
@@ -13,19 +13,11 @@ "publishConfig": { | ||
"scripts": { | ||
"build": "npm run build:clean && npm run build:types && npm run build:js", | ||
"build:clean": "rm -r dist/* || true", | ||
"build:js": "rollup -c", | ||
"build:types": "tsc --emitDeclarationOnly", | ||
"build": "tsdx build", | ||
"deploy": "np", | ||
"dev": "rollup -c -w", | ||
"docs:build": "npm run docs:prepare && gitbook build", | ||
"docs:deploy": "gh-pages -d _book", | ||
"docs:prepare": "gitbook install", | ||
"docs:watch": "npm run docs:prepare && gitbook serve", | ||
"lint": "tslint --project .", | ||
"postpublish": "npm run docs:build && npm run docs:deploy", | ||
"format": "tsdx lint --fix", | ||
"lint": "tsdx lint", | ||
"prepublishOnly": "tsdx build", | ||
"preversion": "npm run lint", | ||
"test": "jest", | ||
"test:watch": "npm run -w", | ||
"version": "npm run build && git add dist", | ||
"view-source-map": "source-map-explorer --html dist/tester.esm.js dist/tester.esm.js.map > source.html && open source.html" | ||
"start": "tsdx watch", | ||
"test": "tsdx test", | ||
"version": "npm run build && git add dist" | ||
}, | ||
@@ -36,15 +28,4 @@ "repository": { | ||
}, | ||
"keywords": [ | ||
"javascript", | ||
"test", | ||
"reactjs", | ||
"react", | ||
"jest", | ||
"enzyme", | ||
"test", | ||
"utils", | ||
"bootstrap", | ||
"configuration" | ||
], | ||
"author": "Keven Bouchard <keven@mighty.com>", | ||
"keywords": [], | ||
"author": "Mighty <tech@mighty.com>", | ||
"license": "MIT", | ||
@@ -55,19 +36,18 @@ "bugs": { | ||
"homepage": "https://mighty-justice.github.io/tester/", | ||
"prettier": { | ||
"printWidth": 120, | ||
"proseWrap": "always", | ||
"semi": true, | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
}, | ||
"jest": { | ||
"testPathIgnorePatterns": [ | ||
"/node_modules/" | ||
"collectCoverage": true, | ||
"collectCoverageFrom": [ | ||
"src/**/*.tsx", | ||
"src/**/*.ts" | ||
], | ||
"transform": { | ||
"^.+\\.(js|jsx|ts|tsx)$": "babel-jest" | ||
}, | ||
"moduleFileExtensions": [ | ||
"js", | ||
"jsx", | ||
"ts", | ||
"tsx" | ||
], | ||
"setupFilesAfterEnv": [ | ||
"./test/setup.tsx" | ||
], | ||
"testURL": "http://localhost/" | ||
"./setupTests.tsx" | ||
] | ||
}, | ||
@@ -84,40 +64,17 @@ "files": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.2.2", | ||
"@babel/plugin-proposal-class-properties": "^7.2.1", | ||
"@babel/plugin-proposal-export-default-from": "^7.2.0", | ||
"@babel/plugin-proposal-optional-chaining": "^7.2.0", | ||
"@babel/polyfill": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@babel/preset-react": "^7.0.0", | ||
"@babel/preset-typescript": "^7.1.0", | ||
"@mighty-justice/tslint-config": "^0.3.0", | ||
"@types/enzyme": "^3.1.18", | ||
"@types/enzyme-adapter-react-16": "^1.0.4", | ||
"@types/jest": "^24.0.5", | ||
"@types/react": "^16.8.3", | ||
"babel-core": "7.0.0-bridge.0", | ||
"babelrc-rollup": "^3.0.0", | ||
"coveralls": "^3.0.2", | ||
"enzyme": "^3.8.0", | ||
"enzyme-adapter-react-16": "^1.6.0", | ||
"gh-pages": "^2.0.1", | ||
"gitbook-cli": "^2.3.2", | ||
"gitbook-plugin-anchorjs": "^2.1.0", | ||
"gitbook-plugin-search-plus": "^1.0.4-alpha-3", | ||
"jest": "^24.1.0", | ||
"jest-environment-jsdom": "^24.0.0", | ||
"np": "^4.0.2", | ||
"react": "^16.6.3", | ||
"react-dom": ">=16", | ||
"react-proptypes": "^1.0.0", | ||
"regenerator-runtime": "^0.13.1", | ||
"rollup": "^1.1.2", | ||
"rollup-plugin-babel": "^4.1.0", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-node-resolve": "^4.0.0", | ||
"source-map-explorer": "^1.6.0", | ||
"tslint": "^5.12.1", | ||
"typescript": "^3.3.3" | ||
"@types/enzyme": "^3.10.7", | ||
"@types/enzyme-adapter-react-16": "^1.0.6", | ||
"@types/jest": "^26.0.14", | ||
"@types/react": "^16.9.49", | ||
"babel-jest": "^26.3.0", | ||
"coveralls": "^3.1.0", | ||
"enzyme": "^3.11.0", | ||
"enzyme-adapter-react-16": "^1.15.5", | ||
"np": "^5.0.0", | ||
"react": "^16.13.1", | ||
"react-dom": ">=16.13.1", | ||
"tsdx": "^0.14.0", | ||
"typescript": "^4.0.3" | ||
}, | ||
"dependencies": {} | ||
} |
# Tester | ||
![Tester](/tester_logo_200w.png?raw=true "Tester") | ||
![Tester](/docs/tester_logo_200w.png?raw=true "Tester") | ||
@@ -24,3 +24,3 @@ [![npm Version](https://img.shields.io/npm/v/@mighty-justice/tester.svg)](https://www.npmjs.com/package/@mighty-justice/tester) [![Build Status](https://travis-ci.org/mighty-justice/tester.svg?branch=master)](https://travis-ci.org/mighty-justice/tester) [![Coverage Status](https://coveralls.io/repos/github/mighty-justice/tester/badge.svg?branch=master)](https://coveralls.io/github/mighty-justice/tester?branch=master) | ||
In this example, we'll create a Transport hook to mock our API calls, default to a Profile that uses that hook and test it. We will also create a Light profile that allow us to test without the custom hook when needed. | ||
In this example, we'll create a Transport hook to mock our API calls and test it. | ||
@@ -62,12 +62,2 @@ ### Configuration | ||
], | ||
profiles: [ | ||
{ | ||
name: 'Default', // Using Default overwrites the default profile. | ||
Transport: true, // These properties MUST match hooks name for them to trigger. | ||
}, | ||
{ | ||
name: 'Light', // This creates a Tester.Light | ||
Transport: false, // Disable the hook | ||
}, | ||
], | ||
}); | ||
@@ -95,11 +85,2 @@ ``` | ||
}); | ||
/* | ||
Here, we don't need any Api calls so we use the Light profile | ||
which doesn't initialize the Transport. | ||
*/ | ||
it('Button triggers API call', async () => { | ||
const tester = await new Tester.Light(Button, { props: { children: 'child string' } }).mount(); | ||
expect(tester.text()).toContain('child string'); | ||
}); | ||
}); | ||
@@ -106,0 +87,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
272602
13
15
2407
2
104
1
4