Let Jasmine handle async test results (#619)
authorRaphael von der Grün <raphinesse@gmail.com>
Fri, 22 Jun 2018 13:33:01 +0000 (15:33 +0200)
committerGitHub <noreply@github.com>
Fri, 22 Jun 2018 13:33:01 +0000 (15:33 +0200)
commitda4b4b371203777d1f951ee9580c1348ddb36659
treed6f56cb97cfde591719b3646e6f1967fc077359e
parentb42ccc6cbc52a9fc02c2d9eb6ab983d802825853
Let Jasmine handle async test results (#619)

There was a lot of sub-optimal error handling in the tests.

Instead of handling Promise rejection and resolution ourselves, we now
just return them from the test functions and let Jasmine handle them.

Moreover, this also fixes tons of negative tests that looked something like this:

    f().then(function () {
        expect('foo').toBe('bar');
    }).catch(function (err) {
        expect('' + err).toMatch('some message');
    });

Problems being:
- `expect('foo').toBe('bar')` is less obvious than `fail(...)`
- catches its own Error from the `.then` only to fail because `err` is missing
- Does not check that err is an Error and that the message is in `.message`

So these were normalized to look like this:

    f().then(function () {
        fail('Expected promise to be rejected');
    }).catch(function (err) {
        expect(err).toEqual(jasmine.any(Error));
        expect(err.message).toMatch('some message');
    });

All in all, this commit has the following benefits:
- Removes 700 LOC w/out removing any testing
- Improves output when async tests fail
- Should make async tests less error prone
- Reduces Q-API usage to prepare for removal of Q (CB-14159)
33 files changed:
integration-tests/HooksRunner.spec.js
integration-tests/fetch.spec.js
integration-tests/pkgJson-restore.spec.js
integration-tests/pkgJson.spec.js
integration-tests/platform.spec.js
integration-tests/plugin.spec.js
integration-tests/plugin_fetch.spec.js
integration-tests/plugman_fetch.spec.js
integration-tests/plugman_uninstall.spec.js
spec/cordova/build.spec.js
spec/cordova/compile.spec.js
spec/cordova/create.spec.js
spec/cordova/emulate.spec.js
spec/cordova/platform/addHelper.spec.js
spec/cordova/platform/check.spec.js
spec/cordova/platform/getPlatformDetailsFromDir.spec.js
spec/cordova/platform/index.spec.js
spec/cordova/platform/list.spec.js
spec/cordova/platform/platform.spec.js
spec/cordova/platform/remove.spec.js
spec/cordova/plugin/add.spec.js
spec/cordova/plugin/index.spec.js
spec/cordova/plugin/list.spec.js
spec/cordova/plugin/remove.spec.js
spec/cordova/plugin/save.spec.js
spec/cordova/plugin/search.spec.js
spec/cordova/prepare.spec.js
spec/cordova/project-metadata-apis.spec.js
spec/cordova/run.spec.js
spec/cordova/util.spec.js
spec/plugman/add_platform.spec.js
spec/plugman/create.spec.js
spec/plugman/install.spec.js