@wixc3/testing
TypeScript icon, indicating that this package has built-in type declarations

17.1.1 • Public • Published

npm version @wixc3/testing on Github

Home > @wixc3/testing

testing package

Utils for making mocha + chai testing easy and fun

Remarks

Env variables

  • DEBUG=true/positive number env variable will set test timeouts and time scale to infinity so tests (that don't explicitly override timeout) will not time out on breakpoints

  • TIMEOUT_MULTIPLIER=number env variable will multiply all test timeouts by the given number

Test timeout manipulation

  • scaleTimeout() multiplies timeouts when debugging or running on slow CI machines, based on TIMEOUT_MULTIPLIER and DEBUG env variables

  • adjusts current test timeout (for use in non step async actions)

  • locatorTimeout() creates a locator timeout and adjust the current test

Steps

Steps are a convenient way to craft async tests. A step has a timeout and a description, making test timeouts easy to understand and debug. Each step timeout auto increases the test timeout, assuring the step will time out before the test

Available steps:

Functions

Function Description
adjustCurrentTestTimeout(ms) Add ms to current test timeout
adjustTestsTimeouts() Adjust tests timeouts based on DEBUG and TIMEOUT_MULTIPLIER environment variables
allWithTimeout(actions)

Limits the time a list of promises can take

- Note: useable only within a mocha test/hook. The total test timeout will be adjusted to make sure the test will not time out waiting for this step

chaiRetryPlugin(_, { flag, inspect }) Plugin that allows to re-run function passed to expect, in order to achieve that use new retry method, retrying would be performed until the result will pass the chained assertion or timeout exceeded or retries limit reached. Should be applied through Chai.use function, for example:
createDisposalGroup(name, constraints) Creates a new disposal group
createTestDisposables(disposeHook) Creates a disposable group that will be disposed after the test is done
debugSafeTimeout(ms, rest) Creates an object with scaled timeout and adjust the current test timeout accordingly
defaults() default values for steps of the current test
disposeAfter(disposable, options)
getTimeoutScale()
initAndDisposeAfter(target, options, args)
isDebugMode()
locatorTimeout(ms)
mochaCtx() Active mocha context
overrideDebugMode(value) override the DEBUG environment variable for the current test
overrideTimeoutScale(scale) Overrides the TIMEOUT_MULTIPLIER for the current test
randomizeTestsOrder(shouldRandomize)

Randomizes tests order

To avoid confusion, it can only be set once, before the testing begins (i.e. not in a running test)

scaleTimeout(timeout) Scales a timeout based on the TIMEOUT_MULTIPLIER and DEBUG environment variable
sleep(ms) Resolves after ms milliseconds
step(action)

Adds a step description to a promise if it's rejected

* - Note: useable only within a mocha test/hook. The total test timeout will be adjusted to make sure the test will not time out waiting for this step

useSafeFakeTimers() Makes it easy to safely use fake timers
waitForSpyCall(scope, method) Spies on an object method, waiting until it's called. The spy is removed once called
waitForStubCall(action, waitForAction) Creates a stub, then waits for it to be called
withTimeout(action)

Limits the time a promise can take

- Note: useable only within a mocha test/hook. The total test timeout will be adjusted to make sure the test will not time out waiting for this step

Interfaces

Interface Description
Info Step info base, added step errors
PollDefaults Defaults for poll steps
PromiseStep
PromiseWithTimeout WithTimeout API
StepBase Common step props
StepsDefaults Test step defaults
TimeoutDefaults Step timeout defaults

Variables

Variable Description
codeMatchers
DEFAULT_DISPOSAL_GROUP

Type Aliases

Type Alias Description
Description Sets step description
Predicate

A predicate function

Any return value other than **false** or throwing is considered as satisfying the predicate

RetryOptions

The retry options for the chaiRetryPlugin.

{Object} RetryOptions {number} [timeout] - The maximum duration in milliseconds to wait before failing the retry operation. {number} [retries] - The number of times to retry the function before failing. {number} [delay] - The delay in milliseconds between retries.

Stub A generated stub
Timeout Sets step timeout

Readme

Keywords

none

Package Sidebar

Install

npm i @wixc3/testing

Weekly Downloads

286

Version

17.1.1

License

MIT

Unpacked Size

318 kB

Total Files

236

Last publish

Collaborators

  • dorza
  • vladba-wix
  • danielgovrin
  • yurimorkovnik
  • ranberko91
  • 0xrezaa
  • gregdamsky
  • alissawix
  • ekaterinaza
  • noammu
  • buchenpilar
  • oleksiiletushev
  • alisalachman
  • vladyslav-baliuk
  • yuriin
  • ilyakwix
  • matang
  • daomry
  • noama
  • shakederin
  • dlvhdr
  • plisovyi
  • pijusn
  • shireewill
  • haryelp
  • iuriikowix
  • itaywix
  • thealmightycrumb
  • devex-infra
  • olehr
  • tomrav
  • avi.vahl
  • alexswix
  • omerk
  • talga
  • cijoe
  • wix-ci
  • wixnpm
  • baraki
  • interal
  • alisey
  • danieleww
  • idoros
  • nadavwix
  • rashellek
  • wtfil
  • denysdovhan
  • vkobeliatskyi
  • pistolpete_
  • nettaru
  • igalh
  • netanelgilad
  • anatfenn
  • erezshasha
  • zemlanin
  • arnonkehat
  • ariki
  • itpurchases
  • danalevy
  • serhiiz
  • oleksandraab
  • idango10
  • mikanadel
  • tetiana0611
  • vladkar
  • yurii-v
  • elig-wix
  • nadav.a
  • vladyslavgoloshchapov