mediawiki.api: Refactor to use server.respondImmediately
* Simplifies code a lot and removes the need to explicitly flush
and handle the request queue with respond().
This was especially annoying when a request spawned others as
they wouldn't be in the queue yet.
* Make tests more explicit and resilient by specifying what they
respond to instead of assigning to requests[i] directly.
This also makes the failure better if one request isn't made,
instead of throwing for accessing properties on undefined objects.
* Avoid relying on test order for badToken().
Follows-up
7b05096bcae0. Tests should be atomic and not rely on
order. This is already important as QUnit re-orders failed tests.
And in the future they may run concurrently.
Resolve using a unique name (like the other tests).
Also, the previous test wasn't asserting that badToken() works,
it was merely asserting that getToken() works and that it wasn't
yet cached. The new test will fetch and purge its own token.
Change-Id: I26d22ace6c5df19d7144779be1a625aede79749f