From dd10598d39e3d0959f6ef7ac07b63aaca5c7f75c Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Tue, 26 Nov 2019 17:25:03 +0200 Subject: [PATCH] Enable 'require-await' ESLint check --- .eslintrc.yml | 4 ++-- .../__tests__/mapAsyncIterator-test.js | 20 ++++++++++--------- src/subscription/__tests__/subscribe-test.js | 19 +++++++++--------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 10d6f0a21c..18cb39b43c 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -172,7 +172,7 @@ rules: prefer-promise-reject-errors: error prefer-regex-literals: error radix: error - require-await: off # TODO + require-await: error require-unicode-regexp: off vars-on-top: error yoda: [error, never, { exceptRange: true }] @@ -291,7 +291,7 @@ rules: prefer-rest-params: off # TODO prefer-spread: error prefer-template: off - require-yield: off + require-yield: error sort-imports: off symbol-description: off diff --git a/src/subscription/__tests__/mapAsyncIterator-test.js b/src/subscription/__tests__/mapAsyncIterator-test.js index 7ecfa3353f..7a837e44a5 100644 --- a/src/subscription/__tests__/mapAsyncIterator-test.js +++ b/src/subscription/__tests__/mapAsyncIterator-test.js @@ -1,5 +1,8 @@ // @flow strict +// FIXME temporary hack until https://github.com/eslint/eslint/pull/12484 is merged +/* eslint-disable require-await */ + import { expect } from 'chai'; import { describe, it } from 'mocha'; @@ -270,12 +273,11 @@ describe('mapAsyncIterator', () => { }); it('closes source if mapper rejects', async () => { - await testClosesSourceWithMapper(async x => { - if (x > 1) { - throw new Error('Cannot count to ' + x); - } - return x; - }); + await testClosesSourceWithMapper(x => + x > 1 + ? Promise.reject(new Error('Cannot count to ' + x)) + : Promise.resolve(x), + ); }); async function testClosesSourceWithRejectMapper(mapper) { @@ -313,8 +315,8 @@ describe('mapAsyncIterator', () => { }); it('closes source if mapper rejects', async () => { - await testClosesSourceWithRejectMapper(async error => { - throw new Error('Cannot count to ' + error.message); - }); + await testClosesSourceWithRejectMapper(error => + Promise.reject(new Error('Cannot count to ' + error.message)), + ); }); }); diff --git a/src/subscription/__tests__/subscribe-test.js b/src/subscription/__tests__/subscribe-test.js index 1136c76d05..ac139cfc1c 100644 --- a/src/subscription/__tests__/subscribe-test.js +++ b/src/subscription/__tests__/subscribe-test.js @@ -1,5 +1,8 @@ // @flow strict +// FIXME temporary hack until https://github.com/eslint/eslint/pull/12484 is merged +/* eslint-disable require-await */ + import EventEmitter from 'events'; import { expect } from 'chai'; @@ -401,16 +404,14 @@ describe('Subscription Initialization Phase', () => { await testReportsError(subscriptionThrowingErrorSchema); // Resolving to an error - const subscriptionResolvingErrorSchema = emailSchemaWithResolvers( - async () => new Error('test error'), + const subscriptionResolvingErrorSchema = emailSchemaWithResolvers(() => + Promise.resolve(new Error('test error')), ); await testReportsError(subscriptionResolvingErrorSchema); // Rejecting with an error - const subscriptionRejectingErrorSchema = emailSchemaWithResolvers( - async () => { - throw new Error('test error'); - }, + const subscriptionRejectingErrorSchema = emailSchemaWithResolvers(() => + Promise.reject(new Error('test error')), ); await testReportsError(subscriptionRejectingErrorSchema); @@ -457,10 +458,8 @@ describe('Subscription Initialization Phase', () => { await testReportsError(subscriptionResolvingErrorSchema); // Rejecting with an error - const subscriptionRejectingErrorSchema = emailSchemaWithResolvers( - async () => { - throw new Error('test error'); - }, + const subscriptionRejectingErrorSchema = emailSchemaWithResolvers(() => + Promise.reject(new Error('test error')), ); await testReportsError(subscriptionRejectingErrorSchema);