public-transport / hafas-client

JavaScript client for HAFAS public transport APIs.
ISC License
275 stars 53 forks source link

Consider using nock for e2e tests #148

Closed simlu closed 4 years ago

simlu commented 4 years ago

Consider using nockBack for e2e test. We a very convenient wrapper for mocha called node-tdd.

The way this would work:

  1. Run tests against external apis as necessary, nockBack / node-tdd automatically captures requests and stores them in cassettes
  2. Re-running the tests will not make external requests. Instead the request is intercepted and the recording is returned. So if the external service is temporarily unavailable or slow, this wont impact test success. No external requests should ever be made when test are run as part of a suite
  3. When a service changes their API, delete the recordings for the relevant tests and re-run the tests (fix code as necessary). Then commit the new cassettes

This is a solid approach when dealing with external APIs and considered best practice.

derhuerst commented 4 years ago

Consider using nockBack for e2e test.

Sounds great! I agree that this will make the E2E tests more meaningful and reliable.

Keep in mind that we will have to use the lodash/matches variant when matching the request.

We a very convenient wrapper for mocha called node-tdd.

I'm not really a fan of mocha, sorry. I think we can use tape-nock though.

No external requests should ever be made when test are run as part of a suite

The HAFAS APIs change so often that it still makes sense to have an "isolated" CI run that checks if they still match. Sort of like a monitoring system.

derhuerst commented 4 years ago

In ~#148~ #177, I ended up using replayed, because I didn't like the way tape-nock grouped recorded requests by test name.

Having made the E2E more deterministic, it now works well!