Skip to content

Commit

Permalink
fix(webhook): depcrated warning on ts-jest mocked (philips-labs#1615)
Browse files Browse the repository at this point in the history
- order typsscript import
- add prettier plugin to automatically format plugin order
- replaces importing mocked from ts-jest/utils by jest-mock
  • Loading branch information
npalm authored Jan 14, 2022
1 parent f2ff2e6 commit 56c1ece
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 94 deletions.
8 changes: 7 additions & 1 deletion modules/webhook/lambdas/webhook/.prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
"singleQuote": true,
"trailingComma": "all",
"semi": true,
}
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"importOrder": [
"<THIRD_PARTY_MODULES>",
"^[./]"
]
}
4 changes: 3 additions & 1 deletion modules/webhook/lambdas/webhook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"devDependencies": {
"@octokit/webhooks-definitions": "^3.67.3",
"@trivago/prettier-plugin-sort-imports": "^3.1.1",
"@types/aws-lambda": "^8.10.89",
"@types/express": "^4.17.11",
"@types/jest": "^27.4.0",
Expand All @@ -30,6 +31,7 @@
"eslint-plugin-prettier": "4.0.0",
"express": "^4.17.2",
"jest": "^27.4.7",
"jest-mock": "^27.4.6",
"nock": "^13.2.1",
"prettier": "2.5.1",
"ts-jest": "^27.1.2",
Expand All @@ -43,4 +45,4 @@
"aws-lambda": "^1.0.7",
"tslog": "^3.3.1"
}
}
}
1 change: 1 addition & 0 deletions modules/webhook/lambdas/webhook/src/lambda.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { APIGatewayEvent, Context } from 'aws-lambda';
import { mocked } from 'ts-jest/utils';

import { githubWebhook } from './lambda';
import { handle } from './webhook/handler';
import { logger } from './webhook/logger';
Expand Down
3 changes: 2 additions & 1 deletion modules/webhook/lambdas/webhook/src/lambda.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { APIGatewayEvent, Callback, Context } from 'aws-lambda';

import { handle } from './webhook/handler';
import { APIGatewayEvent, Context, Callback } from 'aws-lambda';
import { logger } from './webhook/logger';

export interface Response {
Expand Down
3 changes: 2 additions & 1 deletion modules/webhook/lambdas/webhook/src/local.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from 'express';
import bodyParser from 'body-parser';
import express from 'express';

import { handle } from './webhook/handler';

const app = express();
Expand Down
3 changes: 2 additions & 1 deletion modules/webhook/lambdas/webhook/src/sqs/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SQS } from 'aws-sdk';
import { sendActionRequest, ActionRequestMessage } from '.';

import { ActionRequestMessage, sendActionRequest } from '.';

const mockSQS = {
sendMessage: jest.fn(() => {
Expand Down
3 changes: 2 additions & 1 deletion modules/webhook/lambdas/webhook/src/sqs/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { SQS } from 'aws-sdk';
import { LogFields, logger as logger } from '../webhook/logger';

import { LogFields, logger } from '../webhook/logger';

export interface ActionRequestMessage {
id: number;
Expand Down
3 changes: 2 additions & 1 deletion modules/webhook/lambdas/webhook/src/ssm/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GetParameterCommandOutput, SSM } from '@aws-sdk/client-ssm';
import nock from 'nock';

import { getParameterValue } from '.';
import { SSM, GetParameterCommandOutput } from '@aws-sdk/client-ssm';

jest.mock('@aws-sdk/client-ssm');

Expand Down
13 changes: 7 additions & 6 deletions modules/webhook/lambdas/webhook/src/webhook/handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { handle } from './handler';
import { mocked } from 'ts-jest/utils';
import { Webhooks } from '@octokit/webhooks';
import { getParameterValue } from '../ssm';
import { sendActionRequest } from '../sqs';
import workflowjob_event from '../../test/resources/github_workflowjob_event.json';
import checkrun_event from '../../test/resources/github_check_run_event.json';
import { mocked } from 'jest-mock';
import nock from 'nock';

import checkrun_event from '../../test/resources/github_check_run_event.json';
import workflowjob_event from '../../test/resources/github_workflowjob_event.json';
import { sendActionRequest } from '../sqs';
import { getParameterValue } from '../ssm';
import { handle } from './handler';

jest.mock('../sqs');
jest.mock('../ssm');

Expand Down
9 changes: 5 additions & 4 deletions modules/webhook/lambdas/webhook/src/webhook/handler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { IncomingHttpHeaders } from 'http';
import { Webhooks } from '@octokit/webhooks';
import { sendActionRequest } from '../sqs';
import { CheckRunEvent, WorkflowJobEvent } from '@octokit/webhooks-types';
import { getParameterValue } from '../ssm';
import { logger as rootLogger, LogFields } from './logger';
import { IncomingHttpHeaders } from 'http';

import { Response } from '../lambda';
import { sendActionRequest } from '../sqs';
import { getParameterValue } from '../ssm';
import { LogFields, logger as rootLogger } from './logger';

const supportedEvents = ['check_run', 'workflow_job'];
const logger = rootLogger.getChildLogger();
Expand Down
Loading

0 comments on commit 56c1ece

Please sign in to comment.