Skip to content

Commit

Permalink
chore(core): run yarn lint:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF committed Mar 11, 2024
1 parent 89ff4db commit 22b117b
Show file tree
Hide file tree
Showing 38 changed files with 116 additions and 69 deletions.
16 changes: 12 additions & 4 deletions packages/core/__tests__/BackgroundProcessManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Observable } from 'rxjs';

import { BackgroundProcessManager } from '../src/BackgroundProcessManager';
import { BackgroundProcessManagerState } from '../src/BackgroundProcessManager/types';

Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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!
Expand All @@ -392,6 +395,7 @@ describe('BackgroundProcessManager', () => {
};

onTerminate.then(unsubscribe);

return unsubscribe;
}).subscribe(() => count++);

Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/__tests__/Cache/utils/cacheUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/__tests__/ConsoleLogger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion packages/core/__tests__/Hub.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hub, AMPLIFY_SYMBOL } from '../src/Hub';
import { Hub } from '../src/Hub';
import { ConsoleLogger } from '../src';

describe('Hub', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/__tests__/JS-browser-runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand Down
28 changes: 20 additions & 8 deletions packages/core/__tests__/Mutex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,27 @@ describe('Mutex', function () {
test('runExclusive passes result (immediate)', function () {
return mutex
.runExclusive<number>(() => 10)
.then(value => expect(value).toBe(10));
.then(value => {
expect(value).toBe(10);
});
});

test('runExclusive passes result (promise)', function () {
return mutex
.runExclusive<number>(() => Promise.resolve(10))
.then(value => expect(value).toBe(10));
.then(value => {
expect(value).toBe(10);
});
});

test('runExclusive passes rejection', function () {
return mutex
.runExclusive<number>(() => Promise.reject('foo'))
.then(
() => Promise.reject('should have been rejected'),
value => expect(value).toBe('foo'),
value => {
expect(value).toBe('foo');
},
);
});

Expand All @@ -74,7 +80,9 @@ describe('Mutex', function () {
})
.then(
() => Promise.reject('should have been rejected'),
value => expect(value).toBe('foo'),
value => {
expect(value).toBe('foo');
},
);
});

Expand All @@ -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 () {
Expand All @@ -107,16 +117,18 @@ describe('Mutex', function () {
() => undefined,
);

return mutex.runExclusive(() => expect(flag).toBe(true));
return mutex.runExclusive(() => {
expect(flag).toBe(true);
});
});

test('new mutex is unlocked', function () {
expect(!mutex.isLocked()).toBe(true);
});

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);

Expand Down
4 changes: 2 additions & 2 deletions packages/core/__tests__/Platform/customUserAgent.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
Category,
AuthAction,
StorageAction,
Category,
SetCustomUserAgentInput,
StorageAction,
} from '../../src/Platform/types';

const MOCK_AUTH_UA_STATE: SetCustomUserAgentInput = {
Expand Down
13 changes: 4 additions & 9 deletions packages/core/__tests__/Platform/userAgent.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
6 changes: 4 additions & 2 deletions packages/core/__tests__/Retry.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
retry,
jitteredExponentialRetry,
NonRetryableError,
jitteredExponentialRetry,
retry,
} from '../src/utils/retry';
import { BackgroundProcessManager } from '../src/BackgroundProcessManager';

Expand Down Expand Up @@ -63,6 +63,7 @@ describe('retry', () => {
function delayFunction(attempt, args) {
receivedAttempt = attempt;
receivedArgs = args;

return 1;
}

Expand All @@ -83,6 +84,7 @@ describe('retry', () => {
return false;
}
count++;

return 1;
}

Expand Down
12 changes: 5 additions & 7 deletions packages/core/__tests__/ServiceWorker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
});
});
});
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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' }),
);
});
Expand Down
3 changes: 3 additions & 0 deletions packages/core/__tests__/Signer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -39,6 +40,7 @@ describe('Signer.sign', () => {
...signingOptions,
...options,
};

return [name, updatedRequest, updatedOptions, expectedAuthorization];
},
),
Expand Down Expand Up @@ -146,6 +148,7 @@ describe('Signer.signUrl', () => {
...signingOptions,
...options,
};

return [name, updatedRequest, updatedOptions, expectedUrl];
},
),
Expand Down
4 changes: 3 additions & 1 deletion packages/core/__tests__/StringUtils.test.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/__tests__/adapterCore/serverContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import {
createAmplifyServerContext,
getAmplifyServerContext,
destroyAmplifyServerContext,
getAmplifyServerContext,
} from '../../src/adapterCore';

const mockConfigure = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { fetchTransferHandler } from '../../../src/clients/handlers/fetch';
import {
getCredentialsForIdentity,
GetCredentialsForIdentityInput,
GetCredentialsForIdentityOutput,
getCredentialsForIdentity,
} from '../../../src/awsClients/cognitoIdentity';
import {
cognitoIdentityHandlerOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { fetchTransferHandler } from '../../../src/clients/handlers/fetch';
import {
getId,
GetIdInput,
GetIdOutput,
getId,
} from '../../../src/awsClients/cognitoIdentity';
import {
cognitoIdentityHandlerOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import { fetchTransferHandler } from '../../../src/clients/handlers/fetch';
import {
getInAppMessages,
GetInAppMessagesInput,
GetInAppMessagesOutput,
getInAppMessages,
} from '../../../src/awsClients/pinpoint';
import {
mockApplicationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import { fetchTransferHandler } from '../../../src/clients/handlers/fetch';
import {
putEvents,
PutEventsInput,
PutEventsOutput,
putEvents,
} from '../../../src/awsClients/pinpoint';
import {
mockApplicationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import { fetchTransferHandler } from '../../../src/clients/handlers/fetch';
import {
updateEndpoint,
UpdateEndpointInput,
UpdateEndpointOutput,
updateEndpoint,
} from '../../../src/awsClients/pinpoint';
import {
mockApplicationId,
Expand Down
1 change: 1 addition & 0 deletions packages/core/__tests__/awsClients/testUtils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 22b117b

Please sign in to comment.