diff --git a/packages/core/__tests__/BackgroundProcessManager.test.ts b/packages/core/__tests__/BackgroundProcessManager.test.ts index c06cccc6d46..71f893d56f5 100644 --- a/packages/core/__tests__/BackgroundProcessManager.test.ts +++ b/packages/core/__tests__/BackgroundProcessManager.test.ts @@ -1,4 +1,5 @@ import { Observable } from 'rxjs'; + import { BackgroundProcessManager } from '../src/BackgroundProcessManager'; import { BackgroundProcessManagerState } from '../src/BackgroundProcessManager/types'; @@ -287,7 +288,7 @@ describe('BackgroundProcessManager', () => { test('can send termination signals to jobs that support termination, with reject', async () => { let completed = false; - let thrown = undefined; + let thrown; const manager = new BackgroundProcessManager(); const resultPromise = manager.add(async onTerminate => { @@ -383,7 +384,9 @@ describe('BackgroundProcessManager', () => { // that the observable constructor can manage it like a hook. new Observable(observer => { const { resolve, onTerminate } = manager.add(); - const interval = setInterval(() => observer.next({}), 10); + const interval = setInterval(() => { + observer.next({}); + }, 10); const unsubscribe = () => { resolve(); // always remember to resolve/reject! @@ -392,6 +395,7 @@ describe('BackgroundProcessManager', () => { }; onTerminate.then(unsubscribe); + return unsubscribe; }).subscribe(() => count++); @@ -415,7 +419,9 @@ describe('BackgroundProcessManager', () => { let count = 0; const subscription = new Observable(observer => { - const interval = setInterval(() => observer.next({}), 10); + const interval = setInterval(() => { + observer.next({}); + }, 10); // LOOK: here's the magic. (tada!) return manager.addCleaner(async () => { @@ -443,7 +449,9 @@ describe('BackgroundProcessManager', () => { let count = 0; const subscription = new Observable(observer => { - const interval = setInterval(() => observer.next({}), 10); + const interval = setInterval(() => { + observer.next({}); + }, 10); // LOOK: here's the magic. (tada!) return manager.addCleaner(async () => { diff --git a/packages/core/__tests__/Cache/utils/cacheUtils.test.ts b/packages/core/__tests__/Cache/utils/cacheUtils.test.ts index 4c99645a352..ad46e477d52 100644 --- a/packages/core/__tests__/Cache/utils/cacheUtils.test.ts +++ b/packages/core/__tests__/Cache/utils/cacheUtils.test.ts @@ -3,7 +3,7 @@ import { getByteLength } from '../../../src/Cache/utils/cacheHelpers'; describe('cacheHelpers', () => { describe('getByteLength()', () => { test('happy case', () => { - const str: string = 'abc'; + const str = 'abc'; expect(getByteLength(str)).toBe(3); const str2: string = String.fromCharCode(0x80); diff --git a/packages/core/__tests__/ConsoleLogger.test.ts b/packages/core/__tests__/ConsoleLogger.test.ts index c52039cbc03..f0ed669a26e 100644 --- a/packages/core/__tests__/ConsoleLogger.test.ts +++ b/packages/core/__tests__/ConsoleLogger.test.ts @@ -3,7 +3,7 @@ import { LoggingProvider } from '../src/Logger/types'; describe('ConsoleLogger', () => { describe('pluggables', () => { - /*it('should store pluggables correctly when addPluggable is called', () => { + /* it('should store pluggables correctly when addPluggable is called', () => { const provider = new AWSCloudWatchProvider(); const logger = new Logger('name'); logger.addPluggable(provider); @@ -13,7 +13,7 @@ describe('ConsoleLogger', () => { expect(pluggables[0].getProviderName()).toEqual( AWS_CLOUDWATCH_PROVIDER_NAME ); - });*/ + }); */ it('should do nothing when no plugin is provided to addPluggable', () => { const logger = new ConsoleLogger('name'); diff --git a/packages/core/__tests__/Hub.test.ts b/packages/core/__tests__/Hub.test.ts index 141ebbed16f..216730b5254 100644 --- a/packages/core/__tests__/Hub.test.ts +++ b/packages/core/__tests__/Hub.test.ts @@ -1,4 +1,4 @@ -import { Hub, AMPLIFY_SYMBOL } from '../src/Hub'; +import { Hub } from '../src/Hub'; import { ConsoleLogger } from '../src'; describe('Hub', () => { diff --git a/packages/core/__tests__/JS-browser-runtime.test.ts b/packages/core/__tests__/JS-browser-runtime.test.ts index 7050481bb5c..372b902f10c 100644 --- a/packages/core/__tests__/JS-browser-runtime.test.ts +++ b/packages/core/__tests__/JS-browser-runtime.test.ts @@ -9,12 +9,12 @@ describe('isBrowser build test', () => { // testing the Node.js process. const originalVersions = process.versions; beforeEach(() => { - //@ts-ignore + // @ts-ignore delete global.process.versions; }); afterEach(() => { - //@ts-ignore + // @ts-ignore global.process.versions = originalVersions; }); diff --git a/packages/core/__tests__/Mutex.test.ts b/packages/core/__tests__/Mutex.test.ts index e7335f292e5..6a47360a6a8 100644 --- a/packages/core/__tests__/Mutex.test.ts +++ b/packages/core/__tests__/Mutex.test.ts @@ -49,13 +49,17 @@ describe('Mutex', function () { test('runExclusive passes result (immediate)', function () { return mutex .runExclusive(() => 10) - .then(value => expect(value).toBe(10)); + .then(value => { + expect(value).toBe(10); + }); }); test('runExclusive passes result (promise)', function () { return mutex .runExclusive(() => Promise.resolve(10)) - .then(value => expect(value).toBe(10)); + .then(value => { + expect(value).toBe(10); + }); }); test('runExclusive passes rejection', function () { @@ -63,7 +67,9 @@ describe('Mutex', function () { .runExclusive(() => Promise.reject('foo')) .then( () => Promise.reject('should have been rejected'), - value => expect(value).toBe('foo'), + value => { + expect(value).toBe('foo'); + }, ); }); @@ -74,7 +80,9 @@ describe('Mutex', function () { }) .then( () => Promise.reject('should have been rejected'), - value => expect(value).toBe('foo'), + value => { + expect(value).toBe('foo'); + }, ); }); @@ -91,7 +99,9 @@ describe('Mutex', function () { ), ); - return mutex.runExclusive(() => expect(flag).toBe(true)); + return mutex.runExclusive(() => { + expect(flag).toBe(true); + }); }); test('exceptions during runExclusive do not leave mutex locked', function () { @@ -107,7 +117,9 @@ describe('Mutex', function () { () => undefined, ); - return mutex.runExclusive(() => expect(flag).toBe(true)); + return mutex.runExclusive(() => { + expect(flag).toBe(true); + }); }); test('new mutex is unlocked', function () { @@ -115,8 +127,8 @@ describe('Mutex', function () { }); test('isLocked reflects the mutex state', async function () { - const lock1 = mutex.acquire(), - lock2 = mutex.acquire(); + const lock1 = mutex.acquire(); + const lock2 = mutex.acquire(); expect(mutex.isLocked()).toBe(true); diff --git a/packages/core/__tests__/Platform/customUserAgent.test.ts b/packages/core/__tests__/Platform/customUserAgent.test.ts index 6ce8a3a2684..707f1faf227 100644 --- a/packages/core/__tests__/Platform/customUserAgent.test.ts +++ b/packages/core/__tests__/Platform/customUserAgent.test.ts @@ -1,8 +1,8 @@ import { - Category, AuthAction, - StorageAction, + Category, SetCustomUserAgentInput, + StorageAction, } from '../../src/Platform/types'; const MOCK_AUTH_UA_STATE: SetCustomUserAgentInput = { diff --git a/packages/core/__tests__/Platform/userAgent.test.ts b/packages/core/__tests__/Platform/userAgent.test.ts index 88174e3d75f..383b92486f0 100644 --- a/packages/core/__tests__/Platform/userAgent.test.ts +++ b/packages/core/__tests__/Platform/userAgent.test.ts @@ -1,18 +1,13 @@ import { - getAmplifyUserAgentObject, - getAmplifyUserAgent, Platform, + getAmplifyUserAgent, + getAmplifyUserAgentObject, } from '../../src/Platform'; import { version } from '../../src/Platform/version'; +import { AuthAction, Category, Framework } from '../../src/Platform/types'; import { - ApiAction, - AuthAction, - Category, - Framework, -} from '../../src/Platform/types'; -import { - detectFramework, clearCache, + detectFramework, } from '../../src/Platform/detectFramework'; import * as detection from '../../src/Platform/detection'; import { getCustomUserAgent } from '../../src/Platform/customUserAgent'; diff --git a/packages/core/__tests__/Retry.test.ts b/packages/core/__tests__/Retry.test.ts index a7389237985..561865b7bc7 100644 --- a/packages/core/__tests__/Retry.test.ts +++ b/packages/core/__tests__/Retry.test.ts @@ -1,7 +1,7 @@ import { - retry, - jitteredExponentialRetry, NonRetryableError, + jitteredExponentialRetry, + retry, } from '../src/utils/retry'; import { BackgroundProcessManager } from '../src/BackgroundProcessManager'; @@ -63,6 +63,7 @@ describe('retry', () => { function delayFunction(attempt, args) { receivedAttempt = attempt; receivedArgs = args; + return 1; } @@ -83,6 +84,7 @@ describe('retry', () => { return false; } count++; + return 1; } diff --git a/packages/core/__tests__/ServiceWorker.test.ts b/packages/core/__tests__/ServiceWorker.test.ts index f63e07aeed5..0e575ed5293 100644 --- a/packages/core/__tests__/ServiceWorker.test.ts +++ b/packages/core/__tests__/ServiceWorker.test.ts @@ -17,7 +17,7 @@ describe('ServiceWorker test', () => { serviceWorker.enablePush('publicKey'); }; - return expect(enablePush).toThrow(AmplifyError); + expect(enablePush).toThrow(AmplifyError); }); test('fails when registering', async () => { (global as any).navigator.serviceWorker = { @@ -62,7 +62,7 @@ describe('ServiceWorker test', () => { const serviceWorker = new ServiceWorker(); await serviceWorker.register(); - return expect(bla[status].addEventListener).toHaveBeenCalledTimes(2); + expect(bla[status].addEventListener).toHaveBeenCalledTimes(2); }); }); }); @@ -80,7 +80,7 @@ describe('ServiceWorker test', () => { serviceWorker.send('A message'); - return expect(bla.installing.postMessage).toHaveBeenCalledTimes(0); + expect(bla.installing.postMessage).toHaveBeenCalledTimes(0); }); test('can send string message after registration', async () => { const bla = { @@ -96,9 +96,7 @@ describe('ServiceWorker test', () => { serviceWorker.send('A message'); - return expect(bla.installing.postMessage).toHaveBeenCalledWith( - 'A message', - ); + expect(bla.installing.postMessage).toHaveBeenCalledWith('A message'); }); test('can send object message after registration', async () => { const bla = { @@ -114,7 +112,7 @@ describe('ServiceWorker test', () => { serviceWorker.send({ property: 'value' }); - return expect(bla.installing.postMessage).toHaveBeenCalledWith( + expect(bla.installing.postMessage).toHaveBeenCalledWith( JSON.stringify({ property: 'value' }), ); }); diff --git a/packages/core/__tests__/Signer.test.ts b/packages/core/__tests__/Signer.test.ts index 4e15f008282..9453703c2ca 100644 --- a/packages/core/__tests__/Signer.test.ts +++ b/packages/core/__tests__/Signer.test.ts @@ -5,6 +5,7 @@ import { SignRequestOptions } from '../src/clients/middleware/signing/signer/sig import { Signer } from '../src/Signer'; import { DateUtils } from '../src/Signer/DateUtils'; import * as getSignatureModule from '../src/clients/middleware/signing/signer/signatureV4/utils/getSignature'; + import { credentials, credentialsWithToken, @@ -39,6 +40,7 @@ describe('Signer.sign', () => { ...signingOptions, ...options, }; + return [name, updatedRequest, updatedOptions, expectedAuthorization]; }, ), @@ -146,6 +148,7 @@ describe('Signer.signUrl', () => { ...signingOptions, ...options, }; + return [name, updatedRequest, updatedOptions, expectedUrl]; }, ), diff --git a/packages/core/__tests__/StringUtils.test.ts b/packages/core/__tests__/StringUtils.test.ts index 8fa74b7236d..e8bfaabff98 100644 --- a/packages/core/__tests__/StringUtils.test.ts +++ b/packages/core/__tests__/StringUtils.test.ts @@ -1,5 +1,7 @@ -import { urlSafeEncode, urlSafeDecode } from '../src/utils'; import { TextDecoder, TextEncoder } from 'util'; + +import { urlSafeDecode, urlSafeEncode } from '../src/utils'; + (global as any).TextEncoder = TextEncoder; (global as any).TextDecoder = TextDecoder; diff --git a/packages/core/__tests__/adapterCore/serverContext.test.ts b/packages/core/__tests__/adapterCore/serverContext.test.ts index ea6e2a55f1b..3f401e38aa2 100644 --- a/packages/core/__tests__/adapterCore/serverContext.test.ts +++ b/packages/core/__tests__/adapterCore/serverContext.test.ts @@ -3,8 +3,8 @@ import { createAmplifyServerContext, - getAmplifyServerContext, destroyAmplifyServerContext, + getAmplifyServerContext, } from '../../src/adapterCore'; const mockConfigure = jest.fn(); diff --git a/packages/core/__tests__/awsClients/cognitoIdentity/getCredentialsForIdentity.test.ts b/packages/core/__tests__/awsClients/cognitoIdentity/getCredentialsForIdentity.test.ts index 8125a212b7d..e7f820549e2 100644 --- a/packages/core/__tests__/awsClients/cognitoIdentity/getCredentialsForIdentity.test.ts +++ b/packages/core/__tests__/awsClients/cognitoIdentity/getCredentialsForIdentity.test.ts @@ -1,8 +1,8 @@ import { fetchTransferHandler } from '../../../src/clients/handlers/fetch'; import { - getCredentialsForIdentity, GetCredentialsForIdentityInput, GetCredentialsForIdentityOutput, + getCredentialsForIdentity, } from '../../../src/awsClients/cognitoIdentity'; import { cognitoIdentityHandlerOptions, diff --git a/packages/core/__tests__/awsClients/cognitoIdentity/getId.test.ts b/packages/core/__tests__/awsClients/cognitoIdentity/getId.test.ts index 4268cb73fe3..fceb0508ad7 100644 --- a/packages/core/__tests__/awsClients/cognitoIdentity/getId.test.ts +++ b/packages/core/__tests__/awsClients/cognitoIdentity/getId.test.ts @@ -1,8 +1,8 @@ import { fetchTransferHandler } from '../../../src/clients/handlers/fetch'; import { - getId, GetIdInput, GetIdOutput, + getId, } from '../../../src/awsClients/cognitoIdentity'; import { cognitoIdentityHandlerOptions, diff --git a/packages/core/__tests__/awsClients/pinpoint/getInAppMessages.test.ts b/packages/core/__tests__/awsClients/pinpoint/getInAppMessages.test.ts index 826254af149..9bebbf61c03 100644 --- a/packages/core/__tests__/awsClients/pinpoint/getInAppMessages.test.ts +++ b/packages/core/__tests__/awsClients/pinpoint/getInAppMessages.test.ts @@ -3,9 +3,9 @@ import { fetchTransferHandler } from '../../../src/clients/handlers/fetch'; import { - getInAppMessages, GetInAppMessagesInput, GetInAppMessagesOutput, + getInAppMessages, } from '../../../src/awsClients/pinpoint'; import { mockApplicationId, diff --git a/packages/core/__tests__/awsClients/pinpoint/putEvents.test.ts b/packages/core/__tests__/awsClients/pinpoint/putEvents.test.ts index f39335eaf60..192a1d6af1e 100644 --- a/packages/core/__tests__/awsClients/pinpoint/putEvents.test.ts +++ b/packages/core/__tests__/awsClients/pinpoint/putEvents.test.ts @@ -3,9 +3,9 @@ import { fetchTransferHandler } from '../../../src/clients/handlers/fetch'; import { - putEvents, PutEventsInput, PutEventsOutput, + putEvents, } from '../../../src/awsClients/pinpoint'; import { mockApplicationId, diff --git a/packages/core/__tests__/awsClients/pinpoint/updateEndpoint.test.ts b/packages/core/__tests__/awsClients/pinpoint/updateEndpoint.test.ts index 3927c202a27..99eaed5fdc8 100644 --- a/packages/core/__tests__/awsClients/pinpoint/updateEndpoint.test.ts +++ b/packages/core/__tests__/awsClients/pinpoint/updateEndpoint.test.ts @@ -3,9 +3,9 @@ import { fetchTransferHandler } from '../../../src/clients/handlers/fetch'; import { - updateEndpoint, UpdateEndpointInput, UpdateEndpointOutput, + updateEndpoint, } from '../../../src/awsClients/pinpoint'; import { mockApplicationId, diff --git a/packages/core/__tests__/awsClients/testUtils/data.ts b/packages/core/__tests__/awsClients/testUtils/data.ts index 9227c964aac..6d107c9e660 100644 --- a/packages/core/__tests__/awsClients/testUtils/data.ts +++ b/packages/core/__tests__/awsClients/testUtils/data.ts @@ -20,6 +20,7 @@ export const mockJsonResponse = ({ blob: async () => fail('blob() should not be called'), text: async () => fail('text() should not be called'), } as HttpResponse['body']; + return { statusCode: status, headers, diff --git a/packages/core/__tests__/clients/composeTransferHandler.test.ts b/packages/core/__tests__/clients/composeTransferHandler.test.ts index de7976c339d..6fd3e109945 100644 --- a/packages/core/__tests__/clients/composeTransferHandler.test.ts +++ b/packages/core/__tests__/clients/composeTransferHandler.test.ts @@ -11,7 +11,9 @@ import { describe(composeTransferHandler.name, () => { test('should call core handler', async () => { - type HandlerOptions = { foo: string }; + interface HandlerOptions { + foo: string; + } const coreHandler: TransferHandler = jest .fn() .mockResolvedValue({ body: 'Response' } as Response); @@ -25,13 +27,16 @@ describe(composeTransferHandler.name, () => { }); test('should call execute middleware in order', async () => { - type OptionsType = { mockFnInOptions: (calledFrom: string) => void }; + interface OptionsType { + mockFnInOptions(calledFrom: string): void; + } const middlewareA: Middleware = (options: OptionsType) => (next, context) => async request => { request.body += 'A'; options.mockFnInOptions('A'); const resp = await next(request); resp.body += 'A'; + return resp; }; const middlewareB: Middleware = @@ -40,6 +45,7 @@ describe(composeTransferHandler.name, () => { options.mockFnInOptions('B'); const resp = await next(request); resp.body += 'B'; + return resp; }; const coreHandler: TransferHandler = jest diff --git a/packages/core/__tests__/clients/fetch.test.ts b/packages/core/__tests__/clients/fetch.test.ts index db72190c826..1ef0e2d8863 100644 --- a/packages/core/__tests__/clients/fetch.test.ts +++ b/packages/core/__tests__/clients/fetch.test.ts @@ -23,7 +23,7 @@ describe(fetchTransferHandler.name, () => { const mockFetch = jest.fn(); beforeAll(() => { - global['fetch'] = mockFetch; + global.fetch = mockFetch; }); beforeEach(() => { @@ -32,7 +32,7 @@ describe(fetchTransferHandler.name, () => { }); it('should support abort signal', async () => { - const signal = new AbortController().signal; + const { signal } = new AbortController(); await fetchTransferHandler(mockRequest, { abortSignal: signal }); expect(mockFetch).toHaveBeenCalledTimes(1); expect(mockFetch.mock.calls[0][1]).toEqual( diff --git a/packages/core/__tests__/clients/middleware/retry/middleware.test.ts b/packages/core/__tests__/clients/middleware/retry/middleware.test.ts index f17c422d37b..34ead22315d 100644 --- a/packages/core/__tests__/clients/middleware/retry/middleware.test.ts +++ b/packages/core/__tests__/clients/middleware/retry/middleware.test.ts @@ -4,8 +4,8 @@ import { HttpResponse, MiddlewareHandler } from '../../../../src/clients/types'; import { composeTransferHandler } from '../../../../src/clients/internal/composeTransferHandler'; import { - retryMiddlewareFactory, RetryOptions, + retryMiddlewareFactory, } from '../../../../src/clients/middleware/retry'; jest.spyOn(global, 'setTimeout'); @@ -155,8 +155,11 @@ describe(`${retryMiddlewareFactory.name} middleware`, () => { const retryDecider = async () => true; const computeDelay = jest.fn().mockImplementation(attempt => { if (attempt === 1) { - setTimeout(() => controller.abort(), 100); + setTimeout(() => { + controller.abort(); + }, 100); } + return 200; }); try { @@ -186,6 +189,7 @@ describe(`${retryMiddlewareFactory.name} middleware`, () => { const betweenRetryMiddleware = () => (next: any, context: any) => async (args: any) => { await betweenRetryFunction(args, context); + return next(args); }; @@ -201,6 +205,7 @@ describe(`${retryMiddlewareFactory.name} middleware`, () => { .fn() .mockImplementation((response, error: Error) => { if (error && error.message.endsWith('RetryableError')) return true; + return false; }); const computeDelay = jest.fn().mockReturnValue(0); diff --git a/packages/core/__tests__/clients/middleware/signing/middleware.test.ts b/packages/core/__tests__/clients/middleware/signing/middleware.test.ts index 6c481ecc34c..a3183ebcdb5 100644 --- a/packages/core/__tests__/clients/middleware/signing/middleware.test.ts +++ b/packages/core/__tests__/clients/middleware/signing/middleware.test.ts @@ -3,8 +3,8 @@ import { composeTransferHandler } from '../../../../src/clients/internal/composeTransferHandler'; import { - signingMiddlewareFactory, SigningOptions, + signingMiddlewareFactory, } from '../../../../src/clients/middleware/signing'; import { getSkewCorrectedDate } from '../../../../src/clients/middleware/signing/utils/getSkewCorrectedDate'; import { getUpdatedSystemClockOffset } from '../../../../src/clients/middleware/signing/utils/getUpdatedSystemClockOffset'; @@ -13,6 +13,7 @@ import { HttpResponse, MiddlewareHandler, } from '../../../../src/clients/types'; + import { credentials, signingDate, diff --git a/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/presignUrl.test.ts b/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/presignUrl.test.ts index c27b1bdb6a8..279fc50beea 100644 --- a/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/presignUrl.test.ts +++ b/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/presignUrl.test.ts @@ -3,14 +3,15 @@ import { presignUrl } from '../../../../../../src/clients/middleware/signing/signer/signatureV4/presignUrl'; import { HttpRequest } from '../../../../../../src/clients/types'; +import { PresignUrlOptions } from '../../../../../../src/clients/middleware/signing/signer/signatureV4/types'; +import { getSignature } from '../../../../../../src/clients/middleware/signing/signer/signatureV4/utils/getSignature'; + import { signingTestTable } from './testUtils/signingTestTable'; import { formattedDates, getDefaultRequest, signingOptions, } from './testUtils/data'; -import { PresignUrlOptions } from '../../../../../../src/clients/middleware/signing/signer/signatureV4/types'; -import { getSignature } from '../../../../../../src/clients/middleware/signing/signer/signatureV4/utils/getSignature'; jest.mock( '../../../../../../src/clients/middleware/signing/signer/signatureV4/utils/getSignature', @@ -40,6 +41,7 @@ describe('presignUrl', () => { ...signingOptions, ...options, }; + return [name, updatedRequest, updatedOptions, expectedUrl]; }, ), diff --git a/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/signRequest.test.ts b/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/signRequest.test.ts index 857f56a310b..ef8089b6aea 100644 --- a/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/signRequest.test.ts +++ b/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/signRequest.test.ts @@ -3,14 +3,15 @@ import { signRequest } from '../../../../../../src/clients/middleware/signing/signer/signatureV4/signRequest'; import { HttpRequest } from '../../../../../../src/clients/types'; +import { SignRequestOptions } from '../../../../../../src/clients/middleware/signing/signer/signatureV4/types'; +import { getSignature } from '../../../../../../src/clients/middleware/signing/signer/signatureV4/utils/getSignature'; + import { signingTestTable } from './testUtils/signingTestTable'; import { formattedDates, getDefaultRequest, signingOptions, } from './testUtils/data'; -import { SignRequestOptions } from '../../../../../../src/clients/middleware/signing/signer/signatureV4/types'; -import { getSignature } from '../../../../../../src/clients/middleware/signing/signer/signatureV4/utils/getSignature'; jest.mock( '../../../../../../src/clients/middleware/signing/signer/signatureV4/utils/getSignature', @@ -40,6 +41,7 @@ describe('signRequest', () => { ...signingOptions, ...options, }; + return [name, updatedRequest, updatedOptions, expectedAuthorization]; }, ), diff --git a/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/testUtils/signingTestTable.ts b/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/testUtils/signingTestTable.ts index 575ce159b21..37ff662abd2 100644 --- a/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/testUtils/signingTestTable.ts +++ b/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/testUtils/signingTestTable.ts @@ -3,6 +3,7 @@ import { SignRequestOptions } from '../../../../../../../src/clients/middleware/signing/signer/signatureV4/types'; import { HttpRequest } from '../../../../../../../src/clients/types'; + import { credentialsWithToken, signingOptions, url } from './data'; interface TestCase { diff --git a/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/utils/getSignature.test.ts b/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/utils/getSignature.test.ts index 1a796e7bd2e..8ccc5e5283e 100644 --- a/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/utils/getSignature.test.ts +++ b/packages/core/__tests__/clients/middleware/signing/signer/signatureV4/utils/getSignature.test.ts @@ -2,8 +2,8 @@ // SPDX-License-Identifier: Apache-2.0 import { - credentials, credentialScope, + credentials, formattedDates, getDefaultRequest, signingRegion, diff --git a/packages/core/__tests__/parseAWSExports.test.ts b/packages/core/__tests__/parseAWSExports.test.ts index a194ef25528..4e26fc34b2d 100644 --- a/packages/core/__tests__/parseAWSExports.test.ts +++ b/packages/core/__tests__/parseAWSExports.test.ts @@ -243,7 +243,7 @@ describe('parseAWSExports', () => { signUpVerificationMethod: undefined, userAttributes: {}, userPoolClientId: undefined, - userPoolId: userPoolId, + userPoolId, }, }, }); diff --git a/packages/core/__tests__/providers/pinpoint/apis/flushEvents.test.ts b/packages/core/__tests__/providers/pinpoint/apis/flushEvents.test.ts index 367773b2be0..242389e0090 100644 --- a/packages/core/__tests__/providers/pinpoint/apis/flushEvents.test.ts +++ b/packages/core/__tests__/providers/pinpoint/apis/flushEvents.test.ts @@ -3,7 +3,7 @@ import { getEventBuffer } from '../../../../src/providers/pinpoint/utils/getEventBuffer'; import { flushEvents } from '../../../../src/providers/pinpoint'; -import { appId, region, credentials, identityId } from '../testUtils/data'; +import { appId, credentials, identityId, region } from '../testUtils/data'; import { BUFFER_SIZE, FLUSH_INTERVAL, diff --git a/packages/core/__tests__/providers/pinpoint/apis/record.test.ts b/packages/core/__tests__/providers/pinpoint/apis/record.test.ts index fc17952a8c8..0767effeee1 100644 --- a/packages/core/__tests__/providers/pinpoint/apis/record.test.ts +++ b/packages/core/__tests__/providers/pinpoint/apis/record.test.ts @@ -1,4 +1,5 @@ import { v4 } from 'uuid'; + import { putEvents as clientPutEvents } from '../../../../src/awsClients/pinpoint'; import { record } from '../../../../src/providers/pinpoint/apis'; import { updateEndpoint } from '../../../../src/providers/pinpoint/apis/updateEndpoint'; @@ -8,9 +9,9 @@ import { category, credentials, endpointId, - region, - identityId, event, + identityId, + region, uuid, } from '../testUtils/data'; import { getEventBuffer } from '../../../../src/providers/pinpoint/utils/getEventBuffer'; diff --git a/packages/core/__tests__/providers/pinpoint/apis/testUtils/getExpectedPutEventsInput.ts b/packages/core/__tests__/providers/pinpoint/apis/testUtils/getExpectedPutEventsInput.ts index 0101631ce78..ee7ce356a60 100644 --- a/packages/core/__tests__/providers/pinpoint/apis/testUtils/getExpectedPutEventsInput.ts +++ b/packages/core/__tests__/providers/pinpoint/apis/testUtils/getExpectedPutEventsInput.ts @@ -4,8 +4,8 @@ import { appId, endpointId as defaultEndpointId, - uuid, event as defaultEvent, + uuid, } from '../../testUtils/data'; export const getExpectedPutEventsInput = ({ diff --git a/packages/core/__tests__/providers/pinpoint/apis/updateEndpoint.test.ts b/packages/core/__tests__/providers/pinpoint/apis/updateEndpoint.test.ts index 5fa35dd912b..6ad4e718955 100644 --- a/packages/core/__tests__/providers/pinpoint/apis/updateEndpoint.test.ts +++ b/packages/core/__tests__/providers/pinpoint/apis/updateEndpoint.test.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { v4 } from 'uuid'; + import { getClientInfo } from '../../../../src/utils/getClientInfo'; import { updateEndpoint as clientUpdateEndpoint } from '../../../../src/awsClients/pinpoint'; import { cacheEndpointId } from '../../../../src/providers/pinpoint/utils/cacheEndpointId'; @@ -18,6 +19,7 @@ import { userProfile, uuid, } from '../testUtils/data'; + import { getExpectedInput } from './testUtils/getExpectedInput'; jest.mock('uuid'); diff --git a/packages/core/__tests__/singleton/Singleton.test.ts b/packages/core/__tests__/singleton/Singleton.test.ts index 0b12a8e9bac..0d0751bfdd9 100644 --- a/packages/core/__tests__/singleton/Singleton.test.ts +++ b/packages/core/__tests__/singleton/Singleton.test.ts @@ -1,10 +1,12 @@ +import { TextDecoder, TextEncoder } from 'util'; + import { Amplify } from '../../src/singleton'; -import { Hub, AMPLIFY_SYMBOL } from '../../src/Hub'; +import { AMPLIFY_SYMBOL, Hub } from '../../src/Hub'; import { AuthClass as Auth } from '../../src/singleton/Auth'; import { decodeJWT } from '../../src/singleton/Auth/utils'; import { CredentialsAndIdentityId } from '../../src/singleton/Auth/types'; -import { TextEncoder, TextDecoder } from 'util'; -import { fetchAuthSession, ResourcesConfig } from '../../src'; +import { ResourcesConfig, fetchAuthSession } from '../../src'; + Object.assign(global, { TextDecoder, TextEncoder }); jest.mock('../../src/Hub', () => ({ @@ -521,6 +523,7 @@ describe('Session tests', () => { const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE3MTAyOTMxMzB9.YzDpgJsrB3z-ZU1XxMcXSQsMbgCzwH_e-_76rnfehh0'; const mockToken = decodeJWT(token); + return { accessToken: mockToken, }; diff --git a/packages/core/__tests__/storage/CookieStorage.test.ts b/packages/core/__tests__/storage/CookieStorage.test.ts index 75ef343691c..d3093ec7e94 100644 --- a/packages/core/__tests__/storage/CookieStorage.test.ts +++ b/packages/core/__tests__/storage/CookieStorage.test.ts @@ -3,7 +3,7 @@ import { CookieStorage } from '../../src/storage/CookieStorage'; const cookieStorageDomain = 'https://testdomain.com'; describe('CookieStorage', () => { - //defining a DOM to attach a cookie to + // defining a DOM to attach a cookie to Object.defineProperty(document, 'cookie', { writable: true }); describe('Constructor methods', () => { diff --git a/packages/core/__tests__/utils.test.ts b/packages/core/__tests__/utils.test.ts index 09be22a39da..1968709f609 100644 --- a/packages/core/__tests__/utils.test.ts +++ b/packages/core/__tests__/utils.test.ts @@ -1,8 +1,8 @@ 'use strict'; import { - jitteredExponentialRetry, NonRetryableError, + jitteredExponentialRetry, urlSafeDecode, urlSafeEncode, } from '../src/utils'; diff --git a/packages/core/__tests__/utils/generateRandomString.test.ts b/packages/core/__tests__/utils/generateRandomString.test.ts index 2717e3a3743..d17cb37c9d7 100644 --- a/packages/core/__tests__/utils/generateRandomString.test.ts +++ b/packages/core/__tests__/utils/generateRandomString.test.ts @@ -17,6 +17,7 @@ describe('generateRandomString()', () => { mathRandomSpy.mockImplementation(() => { const returnValue = counter; counter += 5; + return parseFloat(`0.${returnValue}`); }); diff --git a/packages/core/__tests__/utils/globalHelpers/globalHelpers.native.test.ts b/packages/core/__tests__/utils/globalHelpers/globalHelpers.native.test.ts index 131199c3e84..fe0b5cea7b4 100644 --- a/packages/core/__tests__/utils/globalHelpers/globalHelpers.native.test.ts +++ b/packages/core/__tests__/utils/globalHelpers/globalHelpers.native.test.ts @@ -1,15 +1,16 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -const mockCrypto = { getRandomValues: jest.fn() }; +import { loadBase64, loadGetRandomValues } from '@aws-amplify/react-native'; -import { loadGetRandomValues, loadBase64 } from '@aws-amplify/react-native'; import { getAtob, getBtoa, getCrypto, } from '../../../src/utils/globalHelpers/index.native'; +const mockCrypto = { getRandomValues: jest.fn() }; + jest.mock('react-native'); jest.mock('@aws-amplify/react-native', () => ({ loadGetRandomValues: jest.fn(() => { diff --git a/packages/core/__tests__/utils/queuedStorage/queuedStorage.native.test.ts b/packages/core/__tests__/utils/queuedStorage/queuedStorage.native.test.ts index a3eef512e09..8dae69b5342 100644 --- a/packages/core/__tests__/utils/queuedStorage/queuedStorage.native.test.ts +++ b/packages/core/__tests__/utils/queuedStorage/queuedStorage.native.test.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { loadAsyncStorage } from '@aws-amplify/react-native'; + import { createQueuedStorage, keyPrefix,