Add unit tests.

Uses rewire for mocking private module members.
Add retrieveState API for debugging.
Extra scheduler commits that went missing.
Conflicts:
	package.json