UNPKG

backport

Version:

A CLI tool that automates the process of backporting commits

58 lines 2.74 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const os_1 = __importDefault(require("os")); const logger = __importStar(require("../lib/logger")); const globalConfig = __importStar(require("../options/config/globalConfig")); const postinstall_1 = require("./postinstall"); describe('postinstall', () => { beforeEach(() => { jest.spyOn(os_1.default, 'homedir').mockReturnValue('/myHomeDir'); }); afterEach(() => { jest.clearAllMocks(); }); it("should create global config if it doesn't exist", async () => { const createGlobalConfigAndFolderIfNotExistSpy = jest .spyOn(globalConfig, 'createGlobalConfigAndFolderIfNotExist') .mockResolvedValueOnce(true); await (0, postinstall_1.postinstall)(); expect(createGlobalConfigAndFolderIfNotExistSpy).toHaveBeenCalledTimes(1); expect(logger.consoleLog).toHaveBeenCalledWith('Global config successfully created in /myHomeDir/.backport/config.json'); }); it('should not create global config if it already exists', async () => { const consoleSpy = jest.spyOn(console, 'log'); const createGlobalConfigAndFolderIfNotExistSpy = jest .spyOn(globalConfig, 'createGlobalConfigAndFolderIfNotExist') .mockResolvedValueOnce(false); await (0, postinstall_1.postinstall)(); expect(createGlobalConfigAndFolderIfNotExistSpy).toHaveBeenCalledTimes(1); expect(consoleSpy).toHaveBeenCalledTimes(0); }); }); //# sourceMappingURL=postinstall.test.js.map