UNPKG

apim-policy-utils

Version:

An XML file scripts maniputaling and debugging tool targeting to help working with Azure APIM Policy files in xml format.

72 lines 3.19 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; }; Object.defineProperty(exports, "__esModule", { value: true }); const combiner_1 = require("../combiner"); const scriptCombiner = __importStar(require("../scriptCombiner")); jest.mock('../getVersion', () => ({ getVersion: jest.fn(() => '1.0.0'), })); jest.mock('../scriptCombiner', () => ({ combineScript: jest.fn(), })); const cwdSpy = jest.spyOn(process, 'cwd'); cwdSpy.mockReturnValue('/'); jest.mock('fs', () => ({ readdirSync: jest.fn((input) => { console.log(input); if (input.includes('error')) { return new Error('Failed to read directory'); } else { const mockDirents = [ { name: 'subdir1', isDirectory: jest.fn(() => true) }, { name: 'subdir2', isDirectory: jest.fn(() => true) }, { name: 'file1.txt', isDirectory: jest.fn(() => false) }, ]; return mockDirents; } }), dirent: jest.fn(), })); describe('combineFromDirectory', () => { beforeEach(() => { jest.clearAllMocks(); }); it('should call combineScript for directory in the directory', () => { const combineScriptMock = jest.spyOn(scriptCombiner, 'combineScript'); (0, combiner_1.combineFromDirectory)('path/to/directory'); expect(combineScriptMock).toHaveBeenCalledTimes(2); expect(combineScriptMock).toHaveBeenCalledWith('/path/to/directory/subdir1', undefined); expect(combineScriptMock).toHaveBeenCalledWith('/path/to/directory/subdir2', undefined); }); it('should call combineScript for directory in the directory when there is destination path', () => { const combineScriptMock = jest.spyOn(scriptCombiner, 'combineScript'); (0, combiner_1.combineFromDirectory)('path/to/directory', 'path/to/destination'); expect(combineScriptMock).toHaveBeenCalledTimes(2); expect(combineScriptMock).toHaveBeenCalledWith('/path/to/directory/subdir1', '/path/to/destination'); expect(combineScriptMock).toHaveBeenCalledWith('/path/to/directory/subdir2', '/path/to/destination'); }); }); //# sourceMappingURL=combiner.test.js.map