Skip to content

Commit

Permalink
chore: Fix test suite linter warnings (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
adebayor123 committed May 24, 2022
1 parent 3269b13 commit ae60f2a
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 142 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"build:dev": "npm-run-all -s build build:webpack:dev",
"release": "npm run build",
"version": "standard-version",
"lint": "npx tslint --config ./tslint.json --project ./tsconfig.webpack.json --format verbose",
"lint": "npx tslint --config ./tslint.json --project ./tsconfig.json --format verbose",
"lint:fix": "npm run lint -- --fix",
"prettier": "npx prettier --check .",
"prettier:fix": "npm run prettier -- --write",
Expand Down
2 changes: 1 addition & 1 deletion src/__integ__/cookiesDisabled.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('when cookies are disabled, no session start event is dispatched', async (t

const json = JSON.parse(await REQUEST_BODY.textContent);
const sessionStartEvents = json.RumEvents.filter(
(e) => e.eventType == SESSION_START_EVENT_TYPE
(e) => e.eventType === SESSION_START_EVENT_TYPE
);

await t.expect(sessionStartEvents.length).eql(0);
Expand Down
6 changes: 3 additions & 3 deletions src/__integ__/cookiesEnabled.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('when page is re-loaded with cookies enabled, session start is not dispatch

const jsonA = JSON.parse(await REQUEST_BODY.textContent);
const sessionStartEventsA = jsonA.RumEvents.filter(
(e) => e.type == SESSION_START_EVENT_TYPE
(e) => e.type === SESSION_START_EVENT_TYPE
);

await t
Expand All @@ -35,7 +35,7 @@ test('when page is re-loaded with cookies enabled, session start is not dispatch

const jsonB = JSON.parse(await REQUEST_BODY.textContent);
const sessionStartEventsB = jsonB.RumEvents.filter(
(e) => e.type == SESSION_START_EVENT_TYPE
(e) => e.type === SESSION_START_EVENT_TYPE
);

await t.expect(sessionStartEventsB.length).eql(0);
Expand All @@ -52,7 +52,7 @@ test('when page is loaded with cookies enabled, session start includes meta data

const json = JSON.parse(await REQUEST_BODY.textContent);
const sessionStartEvents = json.RumEvents.filter(
(e) => e.type == SESSION_START_EVENT_TYPE
(e) => e.type === SESSION_START_EVENT_TYPE
);

const metaData = JSON.parse(sessionStartEvents[0].metadata);
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/CommandQueue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('CommandQueue tests', () => {
expect.objectContaining({
dispatchInterval: 10 * 1000,
sessionSampleRate: 0.8,
enableRumClient: false //prefer snippet config
enableRumClient: false // prefer snippet config
})
);
});
Expand Down
8 changes: 1 addition & 7 deletions src/dispatch/__tests__/Authentication.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable:max-line-length
import { Authentication } from '../Authentication';
import { CRED_KEY } from '../../utils/constants';
import { DEFAULT_CONFIG } from '../../test-utils/test-utils';
Expand Down Expand Up @@ -44,7 +45,6 @@ describe('Authentication tests', () => {
localStorage.removeItem(CRED_KEY);
});

// tslint:disable-next-line:max-line-length
test('when credential is in localStorage then authentication chain retrieves credential from localStorage', async () => {
// Init
const expiration = new Date(Date.now() + 3600 * 1000);
Expand Down Expand Up @@ -80,7 +80,6 @@ describe('Authentication tests', () => {
);
});

// tslint:disable-next-line:max-line-length
test('when credential is corrupt then authentication chain retrieves credential from basic authflow', async () => {
// Init
const config = {
Expand All @@ -107,7 +106,6 @@ describe('Authentication tests', () => {
);
});

// tslint:disable-next-line:max-line-length
test('when credential is not in localStorage then authentication chain retrieves credential from basic authflow', async () => {
// Init
const auth = new Authentication({
Expand All @@ -131,7 +129,6 @@ describe('Authentication tests', () => {
);
});

// tslint:disable-next-line:max-line-length
test('when credential expires then authentication chain retrieves credential from basic authflow', async () => {
// Init
const expiration = new Date(0);
Expand Down Expand Up @@ -168,7 +165,6 @@ describe('Authentication tests', () => {
);
});

// tslint:disable-next-line:max-line-length
test('when credential is retrieved from basic auth then next credential is retrieved from localStorage', async () => {
// Init
const expiration = new Date(Date.now() + 3600 * 1000);
Expand Down Expand Up @@ -267,7 +263,6 @@ describe('Authentication tests', () => {
expect(auth.ChainAnonymousCredentialsProvider()).rejects.toEqual(e);
});

// tslint:disable-next-line:max-line-length
test('when credential is in member then authentication chain retrieves credential from member', async () => {
// Init
const expiration = new Date(Date.now() + 3600 * 1000);
Expand Down Expand Up @@ -305,7 +300,6 @@ describe('Authentication tests', () => {
);
});

// tslint:disable-next-line:max-line-length
test('when credentials expire in member variable then authentication chain retrieves credential from basic auth flow', async () => {
// Init
assumeRole
Expand Down
3 changes: 2 additions & 1 deletion src/dispatch/__tests__/DataPlaneClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable:max-line-length
import * as Utils from '../../test-utils/test-utils';
import { BeaconHttpHandler } from '../BeaconHttpHandler';
import { FetchHttpHandler } from '@aws-sdk/fetch-http-handler';
Expand Down Expand Up @@ -76,7 +77,7 @@ describe('DataPlaneClient tests', () => {
expect(signedRequest.headers['X-Amz-Content-Sha256']).toEqual(
'57bbd361f5c5ab66d7dafb33d6c8bf714bbb140300fad06145b8d66c388b5d43'
);
expect(signedRequest.headers['authorization']).toEqual(
expect(signedRequest.headers.authorization).toEqual(
'AWS4-HMAC-SHA256 Credential=abc123/19700101/us-west-2/rum/aws4_request, SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date, Signature=bf3acf587b119ab12f0f8a86bf12acf7c460eb037584feb0ab5574f297def947'
);
});
Expand Down
16 changes: 7 additions & 9 deletions src/dispatch/__tests__/EnhancedAuthentication.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable:max-line-length
import { CRED_KEY } from '../../utils/constants';
import { Credentials } from '@aws-sdk/types';
import { EnhancedAuthentication } from '../EnhancedAuthentication';
Expand Down Expand Up @@ -46,7 +47,6 @@ describe('EnhancedAuthentication tests', () => {
localStorage.removeItem(CRED_KEY);
});

// tslint:disable-next-line:max-line-length
test('when credential is in localStorage then authentication chain retrieves credential from localStorage', async () => {
// Init
const expiration = new Date(Date.now() + 3600 * 1000);
Expand Down Expand Up @@ -82,7 +82,6 @@ describe('EnhancedAuthentication tests', () => {
);
});

// tslint:disable-next-line:max-line-length
test('when credential is corrupt then authentication chain retrieves credential from basic authflow', async () => {
// Init
const config = {
Expand Down Expand Up @@ -110,7 +109,6 @@ describe('EnhancedAuthentication tests', () => {
);
});

// tslint:disable-next-line:max-line-length
test('when credential is not in the store authentication chain retrieves credential from basic authflow', async () => {
// Init
const auth = new EnhancedAuthentication({
Expand All @@ -133,7 +131,6 @@ describe('EnhancedAuthentication tests', () => {
);
});

// tslint:disable-next-line:max-line-length
test('when credential expires then authentication chain retrieves credentials from basic authflow', async () => {
// Init
const expiration = new Date(0);
Expand Down Expand Up @@ -170,7 +167,6 @@ describe('EnhancedAuthentication tests', () => {
);
});

// tslint:disable-next-line:max-line-length
test('when credential is retrieved from basic auth then next credential is retrieved from localStorage', async () => {
// Init
const expiration = new Date(Date.now() + 3600 * 1000);
Expand Down Expand Up @@ -236,7 +232,9 @@ describe('EnhancedAuthentication tests', () => {
});

// Assert
expect(auth.ChainAnonymousCredentialsProvider()).toThrowError;
expect((auth: EnhancedAuthentication) => {
auth.ChainAnonymousCredentialsProvider();
}).toThrowError();
});

test('when getId fails then throw an error', async () => {
Expand All @@ -254,10 +252,11 @@ describe('EnhancedAuthentication tests', () => {
});

// Assert
expect(auth.ChainAnonymousCredentialsProvider()).toThrowError;
expect((auth: EnhancedAuthentication) => {
auth.ChainAnonymousCredentialsProvider();
}).toThrowError();
});

// tslint:disable-next-line:max-line-length
test('when credential is in member then authentication chain retrieves credential from member', async () => {
// Init
const expiration = new Date(Date.now() + 3600 * 1000);
Expand Down Expand Up @@ -295,7 +294,6 @@ describe('EnhancedAuthentication tests', () => {
);
});

// tslint:disable-next-line:max-line-length
test('when credentials expire in member variable then authentication chain retrieves credential from basic auth flow', async () => {
// Init
getCredentials
Expand Down
9 changes: 3 additions & 6 deletions src/event-cache/__tests__/EventCache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getSession = jest.fn(() => ({
eventCount: 1
}));
const getUserId = jest.fn(() => 'b');
const getAttributes = jest.fn(() => {});
const getAttributes = jest.fn();
const incrementSessionEventCount = jest.fn();
jest.mock('../../sessions/SessionManager', () => ({
SessionManager: jest.fn().mockImplementation(() => ({
Expand Down Expand Up @@ -304,7 +304,6 @@ describe('EventCache tests', () => {
eventCount: 1
}));
const getUserId = jest.fn(() => 'b');
const getAttributes = jest.fn(() => {});
const incrementSessionEventCount = jest.fn();
(SessionManager as any).mockImplementation(() => ({
getSession,
Expand Down Expand Up @@ -332,11 +331,10 @@ describe('EventCache tests', () => {
return {
sessionId: 'a',
record: true,
eventCount: eventCount
eventCount
};
});
const getUserId = jest.fn(() => 'b');
const getAttributes = jest.fn(() => {});
const incrementSessionEventCount = jest.fn();
(SessionManager as any).mockImplementation(() => ({
getSession,
Expand Down Expand Up @@ -364,10 +362,9 @@ describe('EventCache tests', () => {

test('when event limit is zero then recordEvent records all events', async () => {
// Init
let eventCount = 0;
const eventCount = 0;
const getSession = jest.fn(() => ({ sessionId: 'a', record: true }));
const getUserId = jest.fn(() => 'b');
const getAttributes = jest.fn(() => {});
const incrementSessionEventCount = jest.fn();
(SessionManager as any).mockImplementation(() => ({
getSession,
Expand Down
11 changes: 6 additions & 5 deletions src/orchestration/__tests__/Orchestration.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable:max-line-length
import { Orchestration } from '../Orchestration';
import { Dispatch } from '../../dispatch/Dispatch';
import { EventCache } from '../../event-cache/EventCache';
Expand Down Expand Up @@ -26,7 +27,7 @@ jest.mock('../../event-cache/EventCache', () => ({
EventCache: jest.fn().mockImplementation(() => ({
enable: enableEventCache,
disable: disableEventCache,
recordPageView: recordPageView
recordPageView
}))
}));

Expand All @@ -38,10 +39,10 @@ const disablePlugins = jest.fn();

jest.mock('../../plugins/PluginManager', () => ({
PluginManager: jest.fn().mockImplementation(() => ({
addPlugin: addPlugin,
addPlugin,
enable: enablePlugins,
disable: disablePlugins,
updatePlugin: updatePlugin
updatePlugin
}))
}));

Expand Down Expand Up @@ -186,7 +187,7 @@ describe('Orchestration tests', () => {

test('data collection defaults to only page views', async () => {
// Init
new Orchestration('a', 'c', 'us-east-1', {});
const orchestration = new Orchestration('a', 'c', 'us-east-1', {});
const expected = ['com.amazonaws.rum.page-view'];
const actual = [];

Expand Down Expand Up @@ -224,7 +225,7 @@ describe('Orchestration tests', () => {

test('when a config is passed to the http data collection then the config is added as a constructor arg', async () => {
// Init
new Orchestration('a', 'c', 'us-east-1', {
const orchestration = new Orchestration('a', 'c', 'us-east-1', {
telemetries: [['http', { trace: true }]]
});

Expand Down
Loading

0 comments on commit ae60f2a

Please sign in to comment.