UNPKG

sda

Version:

Software development assistant

132 lines 6.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = __importDefault(require("lodash")); const Log_1 = __importDefault(require("../Log")); const Constants_1 = require("../test/Constants"); const getCommands_1 = __importDefault(require("./getCommands")); beforeAll(() => { Log_1.default.isEnabled = false; }); let env; beforeEach(() => { env = lodash_1.default.cloneDeep(Constants_1.env); }); test('get an inline command', () => { const cmd = getCommands_1.default(env, ['inlineCommand']); expectSingleCommand(cmd, 'inline'); }); test('get an inline array command', () => { const cmd = getCommands_1.default(env, ['inlineArrayCommand']); expect(cmd.length).toBe(1); expect(cmd[0].cmd).toEqual(['inline1', 'inline2']); }); test('get a regular command', () => { const cmd = getCommands_1.default(env, ['regularCommand']); expectSingleCommand(cmd, 'regular'); }); test('get a regular array command', () => { const cmd = getCommands_1.default(env, ['regularArrayCommand']); expect(cmd.length).toBe(1); expect(cmd[0].cmd).toEqual(['regular1', 'regular2']); }); test('get a command with absolute folder', () => { const cmd = getCommands_1.default(env, ['commandWithAbsoluteFolder']); expect(cmd.length).toBe(1); expect(cmd[0].cmd).toEqual(['withFolder']); expect(cmd[0].cwd).toEqual('C:\\testX\\testY'); }); test('get a command with relative folder', () => { const cmd = getCommands_1.default(env, ['commandWithRelativeFolder']); expect(cmd.length).toBe(1); expect(cmd[0].cmd).toEqual(['withFolder']); expect(cmd[0].cwd).toEqual('C:\\folderA\\folderB\\test1\\test2'); }); test('get a non-existing command', () => { const cmd = getCommands_1.default(env, ['nonExistingCommand']); expect(cmd.length).toBe(0); }); test('get two commands', () => { const cmd = getCommands_1.default(env, ['inlineCommand', 'regularCommand']); expect(cmd.length).toBe(2); expect(cmd[0].cmd).toEqual(['inline']); expect(cmd[1].cmd).toEqual(['regular']); expect(cmd[0].cwd).toEqual('C:\\folderA\\folderB'); expect(cmd[1].cwd).toEqual('C:\\folderA\\folderB'); }); test('get an existing and a non-existing command', () => { const cmd = getCommands_1.default(env, ['inlineCommand', 'nonExistingCommand']); expectSingleCommand(cmd, 'inline'); }); test('get a non-existing and an existing command', () => { const cmd = getCommands_1.default(env, ['nonExistingCommand', 'inlineCommand']); expectSingleCommand(cmd, 'inline'); }); test('get a command from filepath', () => { const cmd = getCommands_1.default(env, ['commandWithFilePath']); expectSingleCommand(cmd, '"someFilePath"'); }); test('get a command from filepath and interpreter', () => { const cmd = getCommands_1.default(env, ['commandWithFilePathAndInterpreter']); expectSingleCommand(cmd, 'node "someFilePath"'); }); test('get a command from filePath and powershell interpreter', () => { const cmd = getCommands_1.default(env, ['powershellCommand']); expectSingleCommand(cmd, 'powershell -File "someFilePath"'); }); test('get a command with no valid params', () => { const cmd = getCommands_1.default(env, ['regularCommand'], []); expectSingleCommand(cmd, 'regular'); }); test('get a command with a valid param', () => { const cmd = getCommands_1.default(env, ['commandWithParams'], [['-param', 'paramValue'], ['-invalidParam']]); expectSingleCommand(cmd, 'withParams -param paramValue'); }); test('get a command with a param and placeholder', () => { const cmd = getCommands_1.default(env, ['commandWithParamsPlaceholder'], [['/p']]); expectSingleCommand(cmd, 'withParams /p && anotherCommand'); }); test('get a command with a placeholder and no params', () => { const cmd = getCommands_1.default(env, ['commandWithParamsPlaceholder']); expectSingleCommand(cmd, 'withParams && anotherCommand'); // Note the double space. }); test('get a command that does not accept passed param', () => { const cmd = getCommands_1.default(env, ['commandWithParams'], [['-invalidParam', 'paramValue']]); expectSingleCommand(cmd, 'withParams'); }); test('get a command from an alias', () => { const cmd = getCommands_1.default(env, ['ic']); expectSingleCommand(cmd, 'inline'); }); test('get a command with an invalid alias', () => { const cmd = getCommands_1.default(env, ['ne']); expect(cmd.length).toBe(0); }); test('get commands with existing command and valid alias', () => { const cmd = getCommands_1.default(env, ['ic', 'regularCommand']); expect(cmd.length).toBe(2); expect(cmd[0].cmd).toEqual(['inline']); expect(cmd[1].cmd).toEqual(['regular']); }); test('get commands with non-existing command and valid alias', () => { const cmd = getCommands_1.default(env, ['nonExistingCommand', 'ic']); expectSingleCommand(cmd, 'inline'); }); test('get commands with existing command and invalid alias', () => { const cmd = getCommands_1.default(env, ['regularCommand', 'ne']); expectSingleCommand(cmd, 'regular'); }); test('get command from alias with params', () => { const cmd = getCommands_1.default(env, ['cwp'], [['-param', 'paramValue'], ['-invalidParam']]); expectSingleCommand(cmd, 'withParams -param paramValue'); }); test('get command from alias with param placeholder', () => { const cmd = getCommands_1.default(env, ['cwpp'], [['/p']]); expectSingleCommand(cmd, 'withParams /p && anotherCommand'); }); function expectSingleCommand(command, expectedCommandCmd) { expect(command.length).toBe(1); expect(command[0].cmd).toEqual([expectedCommandCmd]); expect(command[0].cwd).toEqual('C:\\folderA\\folderB'); } //# sourceMappingURL=getCommands.test.js.map