UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

53 lines 2.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const child_process_1 = require("child_process"); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const strip_ansi_1 = __importDefault(require("strip-ansi")); const package_json_1 = __importDefault(require("../../../../package.json")); const getDevAccessToken_1 = require("../../private/getDevAccessToken"); const accessToken = (0, getDevAccessToken_1.getDevAccessToken)(); describe('CLI “backport” binary', () => { const binPath = path_1.default.resolve(__dirname, '../../../../bin/backport'); beforeAll(() => { // ensure dist folder exists const distPath = path_1.default.resolve(__dirname, '../../../../dist'); if (!fs_1.default.existsSync(distPath)) { throw new Error(`Please run "yarn build" before running this test.`); } }); it('exists and is executable', () => { expect(fs_1.default.existsSync(binPath)).toBe(true); const fileContent = fs_1.default.readFileSync(binPath, 'utf8'); expect(fileContent).toContain('#!/usr/bin/env node'); }); it('prints version with `--version`', () => { const result = (0, child_process_1.spawnSync)('node', [binPath, '--version'], { encoding: 'utf8', }); expect(result.status).toBe(0); expect(result.stdout.trim()).toBe(package_json_1.default.version); }); it('list commits', () => { const result = (0, child_process_1.spawnSync)('node', [binPath, '--repo', 'elastic/kibana', `--accessToken`, accessToken], { encoding: 'utf8', }); const strippedStdout = (0, strip_ansi_1.default)(result.stdout); expect(result.status).toBe(0); expect(strippedStdout).toContain('repo: elastic/kibana'); expect(strippedStdout).toContain('Select commit'); }); it('displays help section', () => { const result = (0, child_process_1.spawnSync)('node', [binPath, '--help'], { encoding: 'utf8', }); const strippedStdout = (0, strip_ansi_1.default)(result.stdout); expect(result.status).toBe(0); expect(strippedStdout).toContain('backport [args]'); expect(strippedStdout).toContain('-v, --version'); }); }); //# sourceMappingURL=binary.private.test.js.map