Skip to content

Commit

Permalink
Fix mutation test (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Mar 28, 2022
1 parent 8a4d348 commit 578ee6b
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 41 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"find-up": "^5.0.0",
"graphql": "^16.3.0",
"graphql-tag": "^2.12.6",
"inquirer": "^8.2.1",
"inquirer": "^8.2.2",
"lodash": "^4.17.21",
"make-dir": "^3.1.0",
"ora": "^5.4.1",
Expand All @@ -96,21 +96,21 @@
"@types/yargs-parser": "^21.0.0",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"eslint": "^8.11.0",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^26.1.2",
"eslint-plugin-jest": "^26.1.3",
"eslint-plugin-prettier": "^4.0.0",
"graphql-config": "^4.1.0",
"husky": "^7.0.4",
"jest": "^27.5.1",
"jest-snapshot-serializer-ansi": "^1.0.0",
"lint-staged": "^12.3.7",
"nock": "^13.2.4",
"prettier": "^2.6.0",
"prettier": "^2.6.1",
"strip-ansi": "^6.0.1",
"ts-jest": "^27.1.3",
"ts-jest": "^27.1.4",
"ts-node": "^10.7.0",
"typescript": "^4.6.2"
"typescript": "^4.6.3"
}
}
2 changes: 1 addition & 1 deletion src/backportRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export async function backportRun({
process.exitCode = 1;
}

logger.error('Unhandled exception', e);
logger.error('Unhandled exception:', e);

return backportResponse;
}
Expand Down
4 changes: 3 additions & 1 deletion src/lib/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export async function cloneRepo(
{ sourcePath, targetPath }: { sourcePath: string; targetPath: string },
onProgress: (progress: number) => void
) {
logger.info(`Cloning repo from ${sourcePath} to ${targetPath}`);

return new Promise<void>((resolve, reject) => {
const subprocess = spawnOriginal('git', [
'clone',
Expand All @@ -42,7 +44,7 @@ export async function cloneRepo(
subprocess.on('error', (err) => reject(err));

subprocess.stderr.on('data', (data: string) => {
logger.verbose(`Cloning repo: ${data.toString()}`);
logger.verbose(data.toString());
const [, objectReceiveProgress]: RegExpMatchArray =
data.toString().match(/^Receiving objects:\s+(\d+)%/) || [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ import { fetchPullRequestAutoMergeMethod } from './fetchPullRequestAutoMergeMeth
// otherwise it will be merged when auto-merge is turned on
const TEST_REPO_OWNER = 'backport-org';
const TEST_REPO_NAME = 'repo-with-auto-merge-enabled';
const INITIAL_SHA = '70aa879411e95b6662f8ddcb80a944fc4444579f';

// commit to create new branch from
// https://github.com/backport-org/repo-with-auto-merge-enabled/commit/1a88d210f90a22e2a06253c5760909833dc820e9
const COMMIT_SHA = '1a88d210f90a22e2a06253c5760909833dc820e9';
jest.setTimeout(10_000);

const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

function resetReference(octokit: Octokit) {
return octokit.rest.git.updateRef({
owner: TEST_REPO_OWNER,
repo: TEST_REPO_NAME,
ref: 'heads/main',
sha: INITIAL_SHA,
force: true,
});
}

async function closePr(octokit: Octokit, pullNumber: number) {
await octokit.pulls.update({
owner: TEST_REPO_OWNER,
Expand All @@ -30,7 +39,7 @@ async function closePr(octokit: Octokit, pullNumber: number) {

async function createPr(options: ValidConfigOptions, branchName: string) {
const prPayload: PullRequestPayload = {
base: 'main',
base: '7.x',
head: branchName,
body: 'testing...',
owner: TEST_REPO_OWNER,
Expand Down Expand Up @@ -59,10 +68,25 @@ async function createBranch(octokit: Octokit, branchName: string, sha: string) {
});
}

// causes flaky test runs on CI because parallel builds are racing each other
// might also be an issue with Github's API being slow at updating after a mutation happens
async function addCommit(octokit: Octokit) {
const randomString = Math.random().toString(36).slice(2);
const res = await octokit.rest.repos.createOrUpdateFileContents({
owner: TEST_REPO_OWNER,
repo: TEST_REPO_NAME,
path: `file-to-change-${randomString}`,
message: 'Automatically changed',
content: Buffer.from(`My new hash ${randomString}`).toString('base64'),
branch: 'main',
});

const sha = res.data.commit.sha;
return sha;
}

// Error: cannot have more than 100 pull requests with the same head_sha
// TODO: have unique head sha for every test run
// eslint-disable-next-line jest/no-disabled-tests
describe.skip('enablePullRequestAutoMerge', () => {
describe('enablePullRequestAutoMerge', () => {
let pullNumber: number;
let branchName: string;
let octokit: Octokit;
Expand All @@ -80,14 +104,20 @@ describe.skip('enablePullRequestAutoMerge', () => {
} as ValidConfigOptions;

octokit = new Octokit({ auth: accessToken });
await createBranch(octokit, branchName, COMMIT_SHA);
await resetReference(octokit);

const sha = await addCommit(octokit);
if (sha) {
await createBranch(octokit, branchName, sha);
}
pullNumber = await createPr(options, branchName);
});

// cleanup
afterAll(async () => {
await closePr(octokit, pullNumber);
await deleteBranch(octokit, branchName);
await resetReference(octokit);
});

// reset auto-merge state between runs
Expand Down
3 changes: 2 additions & 1 deletion src/lib/github/v4/enablePullRequestAutoMerge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ export async function enablePullRequestAutoMerge(
spinner.succeed();
return res.enablePullRequestAutoMerge.pullRequest?.number;
} catch (e) {
const err = e as Error;
spinner.fail();
logger.info(
`Could not enable auto merging for ${targetPullRequestNumber}`,
`Could not enable auto merging for ${targetPullRequestNumber} due to ${err.message}`,
e
);
}
Expand Down
48 changes: 24 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2043,10 +2043,10 @@ eslint-plugin-import@^2.25.4:
resolve "^1.20.0"
tsconfig-paths "^3.12.0"

eslint-plugin-jest@^26.1.2:
version "26.1.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-26.1.2.tgz#0f1a15c62889fffc3f78a773749d672f1bedb15f"
integrity sha512-1bXCoRODPkGN06n9KAMls4Jm0eyS+0Q/LWcIxhqWR2ycV0Z7lnx2c10idk4dtFIJY5xStgiIr5snC6/rxcXpbw==
eslint-plugin-jest@^26.1.3:
version "26.1.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-26.1.3.tgz#e722e5efeea18aa9dec7c7349987b641db19feb7"
integrity sha512-Pju+T7MFpo5VFhFlwrkK/9jRUu18r2iugvgyrWOnnGRaVTFFmFXp+xFJpHyqmjjLmGJPKLeEFLVTAxezkApcpQ==
dependencies:
"@typescript-eslint/utils" "^5.10.0"

Expand Down Expand Up @@ -2090,10 +2090,10 @@ eslint-visitor-keys@^3.0.0, eslint-visitor-keys@^3.3.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826"
integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==

eslint@^8.11.0:
version "8.11.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.11.0.tgz#88b91cfba1356fc10bb9eb592958457dfe09fb37"
integrity sha512-/KRpd9mIRg2raGxHRGwW9ZywYNAClZrHjdueHcrVDuO3a6bj83eoTirCCk0M0yPwOjWYKHwRVRid+xK4F/GHgA==
eslint@^8.12.0:
version "8.12.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.12.0.tgz#c7a5bd1cfa09079aae64c9076c07eada66a46e8e"
integrity sha512-it1oBL9alZg1S8UycLm5YDMAkIhtH6FtAzuZs6YvoGVldWjbS08BkAdb/ymP9LlAyq8koANu32U7Ib/w+UNh8Q==
dependencies:
"@eslint/eslintrc" "^1.2.1"
"@humanwhocodes/config-array" "^0.9.2"
Expand Down Expand Up @@ -2659,10 +2659,10 @@ inherits@2, inherits@^2.0.3, inherits@^2.0.4:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==

inquirer@^8.2.1:
version "8.2.1"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.2.1.tgz#e00022e3e8930a92662f760f020686530a84671d"
integrity sha512-pxhBaw9cyTFMjwKtkjePWDhvwzvrNGAw7En4hottzlPvz80GZaMZthdDU35aA6/f5FRZf3uhE057q8w1DE3V2g==
inquirer@^8.2.2:
version "8.2.2"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.2.2.tgz#1310517a87a0814d25336c78a20b44c3d9b7629d"
integrity sha512-pG7I/si6K/0X7p1qU+rfWnpTE1UIkTONN1wxtzh0d+dHXtT/JG6qBgLxoyHVsQa8cFABxAPh0pD6uUUHiAoaow==
dependencies:
ansi-escapes "^4.2.1"
chalk "^4.1.1"
Expand Down Expand Up @@ -3978,10 +3978,10 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"

prettier@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.0.tgz#12f8f504c4d8ddb76475f441337542fa799207d4"
integrity sha512-m2FgJibYrBGGgQXNzfd0PuDGShJgRavjUoRCw1mZERIWVSXF0iLzLm+aOqTAbLnC3n6JzUhAA8uZnFVghHJ86A==
prettier@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.1.tgz#d472797e0d7461605c1609808e27b80c0f9cfe17"
integrity sha512-8UVbTBYGwN37Bs9LERmxCPjdvPxlEowx2urIL6urHzdb3SDq4B/Z6xLFCblrSnE4iKWcS6ziJ3aOYrc1kz/E2A==

pretty-format@^27.0.0, pretty-format@^27.5.1:
version "27.5.1"
Expand Down Expand Up @@ -4532,10 +4532,10 @@ triple-beam@^1.3.0:
resolved "https://registry.yarnpkg.com/triple-beam/-/triple-beam-1.3.0.tgz#a595214c7298db8339eeeee083e4d10bd8cb8dd9"
integrity sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==

ts-jest@^27.1.3:
version "27.1.3"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-27.1.3.tgz#1f723e7e74027c4da92c0ffbd73287e8af2b2957"
integrity sha512-6Nlura7s6uM9BVUAoqLH7JHyMXjz8gluryjpPXxr3IxZdAXnU6FhjvVLHFtfd1vsE1p8zD1OJfskkc0jhTSnkA==
ts-jest@^27.1.4:
version "27.1.4"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-27.1.4.tgz#84d42cf0f4e7157a52e7c64b1492c46330943e00"
integrity sha512-qjkZlVPWVctAezwsOD1OPzbZ+k7zA5z3oxII4dGdZo5ggX/PL7kvwTM0pXTr10fAtbiVpJaL3bWd502zAhpgSQ==
dependencies:
bs-logger "0.x"
fast-json-stable-stringify "2.x"
Expand Down Expand Up @@ -4640,10 +4640,10 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@^4.6.2:
version "4.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.2.tgz#fe12d2727b708f4eef40f51598b3398baa9611d4"
integrity sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==
typescript@^4.6.3:
version "4.6.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.6.3.tgz#eefeafa6afdd31d725584c67a0eaba80f6fc6c6c"
integrity sha512-yNIatDa5iaofVozS/uQJEl3JRWLKKGJKh6Yaiv0GLGSuhpFJe7P3SbHZ8/yjAHRQwKRoA6YZqlfjXWmVzoVSMw==

unbox-primitive@^1.0.1:
version "1.0.1"
Expand Down

0 comments on commit 578ee6b

Please sign in to comment.