Skip to content

Commit

Permalink
chore: improve typings and test mocks (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 authored Oct 8, 2024
1 parent d9c4c82 commit 8c2c7ba
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 145 deletions.
235 changes: 109 additions & 126 deletions spec/index.spec.ts

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions spec/operations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const backportPRMergedEvent = require('./fixtures/backport_pull_request.merged.j
const backportPROpenedEvent = require('./fixtures/backport_pull_request.opened.json');

jest.mock('../src/utils', () => ({
tagBackportReviewers: jest.fn().mockReturnValue(Promise.resolve()),
tagBackportReviewers: jest.fn().mockResolvedValue(undefined),
isSemverMinorPR: jest.fn().mockReturnValue(false),
}));

Expand Down Expand Up @@ -125,11 +125,11 @@ describe('runner', () => {
describe('updateManualBackport()', () => {
const octokit = {
pulls: {
get: jest.fn().mockReturnValue(Promise.resolve({})),
get: jest.fn().mockResolvedValue({}),
},
issues: {
createComment: jest.fn().mockReturnValue(Promise.resolve({})),
listComments: jest.fn().mockReturnValue(Promise.resolve({ data: [] })),
createComment: jest.fn().mockResolvedValue({}),
listComments: jest.fn().mockResolvedValue({ data: [] }),
},
};

Expand Down
12 changes: 5 additions & 7 deletions spec/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ describe('utils', () => {
requestReviewers: jest.fn(),
},
repos: {
getCollaboratorPermissionLevel: jest.fn().mockReturnValue(
Promise.resolve({
data: {
permission: 'admin',
},
}),
),
getCollaboratorPermissionLevel: jest.fn().mockResolvedValue({
data: {
permission: 'admin',
},
}),
},
};

Expand Down
4 changes: 2 additions & 2 deletions src/Queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { log } from './utils/log-util';
import { LogLevel } from './enums';

export type Executor = () => Promise<void>;
export type ErrorExecutor = (err: any) => Promise<void>;
export type ErrorExecutor = (err: unknown) => Promise<void>;

const DEFAULT_MAX_ACTIVE = 5;

Expand Down Expand Up @@ -36,7 +36,7 @@ export class ExecutionQueue extends EventEmitter {
this.active += 1;
fns[1]()
.then(() => this.runNext(fns[0]))
.catch((err: any) => {
.catch((err: unknown) => {
if (!process.env.SPEC_RUNNING) {
console.error(err);
}
Expand Down
4 changes: 2 additions & 2 deletions src/operations/update-manual-backport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const updateManualBackport = async (
const newPRLabelsToAdd = [pr.base.ref];

// Changed labels on the original PR.
let labelToAdd;
let labelToRemove;
let labelToAdd: string | undefined;
let labelToRemove: string;

log(
'updateManualBackport',
Expand Down
5 changes: 3 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ export const backportImpl = async (
await fs.remove(createdDir);
},
async () => {
let annotations: any[] | null = null;
let annotations: unknown[] | null = null;
let diff;
let rawDiff;
if (createdDir) {
Expand Down Expand Up @@ -751,7 +751,8 @@ export const backportImpl = async (
message: 'Patch Conflict',
raw_details: hunk.lines
.filter(
(_: any, i: number) => i >= startOffset && i <= finalOffset,
(_: unknown, i: number) =>
i >= startOffset && i <= finalOffset,
)
.join('\n'),
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/label-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const addLabels = async (
};

export const getSemverLabel = (pr: Pick<WebHookPR, 'labels'>) => {
return pr.labels.find((l: any) => l.name.startsWith(SEMVER_PREFIX));
return pr.labels.find((l) => l.name.startsWith(SEMVER_PREFIX));
};

export const getHighestSemverLabel = (...labels: string[]) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/log-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LogLevel } from '../enums';
export const log = (
functionName: string,
logLevel: LogLevel,
...message: any[]
...message: unknown[]
) => {
const output = `${functionName}: ${message}`;

Expand Down

0 comments on commit 8c2c7ba

Please sign in to comment.