@lucasmeira/npmfix
Version:
A CLI to fix npm dependencies
34 lines (33 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const run_1 = require("@/src/commands/run");
const logger_1 = tslib_1.__importDefault(require("@/src/logger"));
jest.mock('@/src/logger', () => {
return {
getInstance: jest.fn().mockResolvedValue({
info: jest.fn(),
error: jest.fn(),
}),
};
});
describe('runCommand - Shell Command Execution and Logging', () => {
let logger;
beforeEach(async () => {
logger = await logger_1.default.getInstance();
});
it('should execute the echo command and log the correct output', async () => {
const script = 'echo "Hello World!"';
await (0, run_1.runCommand)(script);
expect(logger.info).toHaveBeenNthCalledWith(1, `Executing script: ${script}`);
expect(logger.info).toHaveBeenNthCalledWith(2, 'Hello World!\n');
expect(logger.info).toHaveBeenNthCalledWith(3, `Script executed successfully: ${script}`);
expect(logger.error).not.toHaveBeenCalled();
});
it('deve registrar erro ao executar um comando inválido', async () => {
const invalidScript = 'invalid-command';
await (0, run_1.runCommand)(invalidScript);
expect(logger.info).toHaveBeenCalledWith(`Executing script: ${invalidScript}`);
expect(logger.error).toHaveBeenCalled();
});
});