Evented/Timed test helpers #121

Closed
johnbender opened this Issue Jul 4, 2011 · 3 comments

Comments

2 participants
@johnbender

Evented testing

DISCLAIMER: most of the ideas here may be project specific but appear, at least from where I'm standing, to be useful in a myriad of scenarios when testing event based functionality.

Timing and event based tests in QUnit and other frameworks tend to be fragile and even dependent on execution order in practice. There are few test helpers that we've found to be invaluable in working with events and time dependent functionality.

sequence( functions, timeout )

Many tests that require a set of timeouts to verify functionality can be cleaned up by abstracting multiple calls to setTimeout into a single helper. This is just as brittle as using the timeouts themselves but at least results in cleaner code where no event is provided to guarantee the behavior.

Example:

https://github.com/jquery/jquery-mobile/blob/master/tests/unit/navigation/navigation_core.js#L49

eventSequence( event, functions )

The event sequence helper executes a list of functions based on a series of the same event firing to trigger each. The most obvious use case where jQuery Mobile is concerned is page transitions which fire the changepage event upon completion.

An example from the event tests:

https://github.com/jquery/jquery-mobile/blob/master/tests/unit/event/event_core.js#L425

An example from the navigation tests. pageSequence is just a wrapper around eventSequence that specifies changepage event as the first argument to eventSequence:

https://github.com/jquery/jquery-mobile/blob/master/tests/unit/navigation/navigation_core.js#L300

eventCascade( event, function, event, function ... )

We haven't stumbled upon a use case here yet but it seems likely that a more flexible form of the eventSequence function would be valuable. In fact this should encourage a more pluggable design since events will be the preferred way to guarantee states of execution in the code being tested!

waitFor

Jasmine has a nice helper in the form of waitFor. It holds the test suite execution until the callback returns a truthy value. Mind you this is dependent on the serialization of all the code in the tests through the run function. More information can be found at their wiki down on the bottom:

https://github.com/pivotal/jasmine/wiki/Asynchronous-specs

@jzaefferer

This comment has been minimized.

Show comment
Hide comment
@jzaefferer

jzaefferer Aug 5, 2011

Member

I wonder if this somewhat overlaps with #99

Member

jzaefferer commented Aug 5, 2011

I wonder if this somewhat overlaps with #99

@jzaefferer

This comment has been minimized.

Show comment
Hide comment
@jzaefferer

jzaefferer Feb 15, 2012

Member

Hey @johnbender - you still interested in this?

Member

jzaefferer commented Feb 15, 2012

Hey @johnbender - you still interested in this?

@jzaefferer

This comment has been minimized.

Show comment
Hide comment
@jzaefferer

jzaefferer Mar 1, 2012

Member

Closing this, as the linked-to source is outdated. @johnbender will put together an update in a new ticket, working with @rwldrn to get his Popcorn.js perspective involved.

Member

jzaefferer commented Mar 1, 2012

Closing this, as the linked-to source is outdated. @johnbender will put together an update in a new ticket, working with @rwldrn to get his Popcorn.js perspective involved.

@jzaefferer jzaefferer closed this Mar 1, 2012

stefanpenner added a commit to stefanpenner/qunit that referenced this issue Jun 6, 2018

[fixes #121] chokidar -> sane
I think chokidar is great, but the ergonomics around native dependencies today in node really painful. Although chokidar pre-builds, users switching nodes, or failed pre-build downloads, or behind firewall usages cause a fallback to requiring a working compiler toolchain. Requiring that, very much increases the barrier of entry, and support load for tooling/cli maintainers

stefanpenner added a commit to stefanpenner/qunit that referenced this issue Jun 6, 2018

[fixes #121] chokidar -> sane
I think chokidar is great, but the ergonomics around native dependencies today in node really painful. Although chokidar pre-builds, users switching nodes, or failed pre-build downloads, or behind firewall usages cause a fallback to requiring a working compiler toolchain. Requiring that, very much increases the barrier of entry, and support load for tooling/cli maintainers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment