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.

68 lines 3.01 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 path_1 = __importDefault(require("path")); const extractor_1 = require("../extractor"); const scriptExtractor = __importStar(require("../scriptExtractor")); jest.mock('../getVersion', () => ({ getVersion: jest.fn(() => '1.0.0'), })); jest.mock('../scriptExtractor', () => ({ extractScript: jest.fn(), })); jest.mock('fs', () => ({ readdir: jest.fn((input, callback) => { if (input.includes('error')) { const error = new Error('Failed to read directory'); callback(error, null); } else { callback(null, ['file1.xml', 'file2.txt', 'file3.xml']); } }), })); describe('extractFromDirectory', () => { beforeEach(() => { jest.clearAllMocks(); }); it('should call extractScript for each XML file in the directory', () => { const extractScriptMock = jest.spyOn(scriptExtractor, 'extractScript'); (0, extractor_1.extractFromDirectory)('path/to/directory'); expect(extractScriptMock).toHaveBeenCalledTimes(2); // Two XML files in the mockFiles array expect(extractScriptMock).toHaveBeenCalledWith(path_1.default.resolve('path/to/directory'), 'file1.xml'); expect(extractScriptMock).toHaveBeenCalledWith(path_1.default.resolve('path/to/directory'), 'file3.xml'); }); it('should handle errors when reading the directory', () => { const consoleError = jest.spyOn(console, "error").mockImplementation(); expect(() => { (0, extractor_1.extractFromDirectory)('path/to/error/directory'); }).toThrow("Failed to read directory"); expect(consoleError).toHaveBeenCalledWith("Error reading directory: Error: Failed to read directory"); }); }); //# sourceMappingURL=extractor.test.js.map