UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

91 lines (87 loc) • 3.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const childProcessHelper_1 = require("../../childProcessHelper"); const getDevAccessToken_1 = require("../../private/getDevAccessToken"); const sandbox_1 = require("../../sandbox"); const runBackportViaCli_1 = require("./runBackportViaCli"); const accessToken = (0, getDevAccessToken_1.getDevAccessToken)(); jest.setTimeout(15000); describe('test-that-repo-can-be-cloned', () => { describe('when local repo does not exist', () => { let sandboxPath; beforeAll(async () => { sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename }); await (0, sandbox_1.resetSandbox)(sandboxPath); }); function run() { return (0, runBackportViaCli_1.runBackportViaCli)([ '--repo=backport-org/test-that-repo-can-be-cloned', '--branch=production', '--pr=1', `--dir=${sandboxPath}`, '--dry-run', `--accessToken=${accessToken}`, ], { showOra: true }); } it('clones the repo remote repo', async () => { const { output } = await run(); expect(output).toContain('Cloning repository from github.com'); expect(output).toMatchInlineSnapshot(` "- Initializing... repo: backport-org/test-that-repo-can-be-cloned šŸ”¹ sourceBranch: main šŸ”¹ pullNumber: 1 šŸ”¹ author: sorenlouv ? Select pull request Beginning of a beautiful repo (#1) āœ” 100% Cloning repository from github.com (one-time operation) Backporting to production: - Pulling latest changes āœ” Pulling latest changes - Cherry-picking: Beginning of a beautiful repo (#1) āœ” Cherry-picking: Beginning of a beautiful repo (#1) - Creating pull request āœ” Creating pull request View pull request: this-is-a-dry-run" `); }); it('does not clone again on subsequent runs', async () => { const { output } = await run(); expect(output).not.toContain('Cloning repository from github.com'); expect(output).toMatchInlineSnapshot(` "- Initializing... repo: backport-org/test-that-repo-can-be-cloned šŸ”¹ sourceBranch: main šŸ”¹ pullNumber: 1 šŸ”¹ author: sorenlouv ? Select pull request Beginning of a beautiful repo (#1) Backporting to production: - Pulling latest changes āœ” Pulling latest changes - Cherry-picking: Beginning of a beautiful repo (#1) āœ” Cherry-picking: Beginning of a beautiful repo (#1) - Creating pull request āœ” Creating pull request View pull request: this-is-a-dry-run" `); }); }); describe('when local repo exists', () => { let sourceRepo; let backportRepo; beforeEach(async () => { const sandboxPath = (0, sandbox_1.getSandboxPath)({ filename: __filename }); await (0, sandbox_1.resetSandbox)(sandboxPath); sourceRepo = `${sandboxPath}/source`; backportRepo = `${sandboxPath}/backport`; await (0, childProcessHelper_1.exec)(`git clone https://github.com/backport-org/test-that-repo-can-be-cloned.git ${sourceRepo}`, { cwd: sandboxPath }); }); function run() { return (0, runBackportViaCli_1.runBackportViaCli)([ '--branch=production', '--pr=1', `--dir=${backportRepo}`, '--dry-run', `--accessToken=${accessToken}`, ], { cwd: sourceRepo, showOra: true }); } it('clones using the local repo', async () => { const { output } = await run(); expect(output.replaceAll('\n', '').replaceAll(sourceRepo, '<SOURCE_REPO>')).toContain('āœ” 100% Cloning repository from <SOURCE_REPO> (one-time operation)'); }); }); }); //# sourceMappingURL=test-that-repo-can-be-cloned.private.test.js.map