cli-testing-tool
Advanced tools
Comparing version
@@ -41,8 +41,2 @@ const { spawn } = require('child_process'); | ||
const commandArgs = commandString.split(' '); | ||
const command = spawn(commandArgs[0], commandArgs.slice(1), { | ||
detached: true, | ||
stdio: 'pipe', | ||
cwd: options.cwd, | ||
env: options.env | ||
}); | ||
@@ -52,26 +46,38 @@ let outputs = ''; | ||
command.stdout.on('data', (data) => { | ||
if (options.logData) { | ||
console.log(data.toString()); | ||
} | ||
outputs += data.toString(); | ||
}); | ||
const initCommandListeners = () => { | ||
outputs = ''; | ||
isFinishTypingCalled = false; | ||
const commandInterface = spawn(commandArgs[0], commandArgs.slice(1), { | ||
detached: true, | ||
stdio: 'pipe', | ||
cwd: options.cwd, | ||
env: options.env | ||
}); | ||
command.stderr.on('data', (error) => { | ||
if (options.logData) { | ||
console.error(error.toString()); | ||
} | ||
outputs += error.toString(); | ||
}); | ||
commandInterface.stdout.on('data', (data) => { | ||
if (options.logData) { | ||
console.log(data.toString()); | ||
} | ||
outputs += data.toString(); | ||
}); | ||
command.on('error', (error) => { | ||
throw error; | ||
}); | ||
commandInterface.stderr.on('data', (error) => { | ||
if (options.logData) { | ||
console.error(error.toString()); | ||
} | ||
outputs += error.toString(); | ||
}); | ||
commandInterface.on('error', (error) => { | ||
throw error; | ||
}); | ||
return commandInterface; | ||
}; | ||
let command = initCommandListeners(); | ||
const type = async (text) => { | ||
if (isFinishTypingCalled) { | ||
throw new Error( | ||
// eslint-disable-next-line max-len | ||
'[cli-testing-tool]: `type` cannot be called after `getOutput` or `finishTyping`' | ||
); | ||
command = initCommandListeners(); | ||
} | ||
@@ -78,0 +84,0 @@ |
{ | ||
"name": "cli-testing-tool", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -5,16 +5,4 @@ # CLI Testing Tool | ||
*Note: This is a work in progress.* | ||
*Note: This is WIP but it should be ready enough for most common CLI use-cases I can think of* | ||
**Terminal Text Parsing Support Checklist** | ||
Refer to [Full List of Ansi Escape Codes](https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797) that need to be handled. | ||
- [x] Normal text without ansi escape codes | ||
- [x] Colored text | ||
- [x] Cursor movement (Basic Support. Not tested) | ||
- [x] Erase Line/Screen Clear (Basic Support. Not tested) | ||
- [ ] Screen Modes (No Support) | ||
- [ ] Private Modes (No Support) | ||
- [ ] Multiple Arguments (No Support. Difficult to support this) | ||
## Installation | ||
@@ -107,2 +95,15 @@ | ||
## Terminal Text Parsing Support Checklist | ||
Refer to [Full List of Ansi Escape Codes](https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797) that need to be handled. | ||
- [x] Normal text without ansi escape codes | ||
- [x] Colored text | ||
- [x] Cursor movement (Basic Support. Not tested) | ||
- [x] Erase Line/Screen Clear (Basic Support. Not tested) | ||
- [ ] Screen Modes (No Support) | ||
- [ ] Private Modes (No Support) | ||
- [ ] Multiple Arguments (No Support. Difficult to support this) | ||
---- | ||
@@ -113,2 +114,2 @@ | ||
- [@netzkolchose](https://github.com/netzkolchose) for [node-ansiterminal](https://github.com/netzkolchose/node-ansiterminal) library. | ||
- [@netzkolchose](https://github.com/netzkolchose) for [node-ansiterminal](https://github.com/netzkolchose/node-ansiterminal) library. |
113
1.8%10347
-2.13%5
-16.67%219
-3.1%