Skip to content

Commit

Permalink
ci: Improved test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anadian committed Sep 11, 2022
1 parent eb726b2 commit bb525e5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"env-paths": "^3.0.0",
"get-stream": "^6.0.1",
"make-dir": "^3.1.0",
"pify": "^6.1.0",
"simple-package-meta": "^0.0.3"
},
"exports": "./source/lib.js",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions source/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ async function main_Async( options = {} ){
Logger.log({process: PROCESS_NAME, module: MODULE_NAME, file: FILENAME, function: FUNCTION_NAME, level: 'error', message: return_error.message});
}/* c8 ignore stop */
}
} //Single-file mode
}
//Single-file mode
if( multi_file_mode === false ){
///Input
if( return_error === null ){
Expand Down Expand Up @@ -511,7 +512,7 @@ try{
console.error('MakeDir.sync threw: %s', error);
}/* c8 ignore stop */
try{
console.log( PackageMeta.paths.log );
//console.log( PackageMeta.paths.log );
logger = ApplicationLogWinstonInterface.initWinstonLogger('debug.log', PackageMeta.paths.log);
//console.log( '%o', logger );
try{
Expand Down
42 changes: 41 additions & 1 deletion source/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env node
import ChildProcess from 'node:child_process';
import FS from 'node:fs/promises';
import AVA from 'ava';
//import Pify from 'pify';
import Pify from 'pify';
import * as Pevent from 'p-event';

AVA('CLI:HelpData', async function(t){
Expand Down Expand Up @@ -69,3 +70,42 @@ AVA('CLI:MultiFileShellGlob', async function(t){
t.fail();
}
});
AVA( 'CLI:STDINtoSTDOUT', async function( t ){
t.log( t.title );
const stdin_promise = FS.readFile( 'test/example-source-file.js', 'utf8' ).then( file_string => {
return file_string.replace( /\r\n/g, '\n' );
} );
const expected_stdout_promise = FS.readFile( 'test/example-source-file-output.txt', 'utf8' ).then( file_string => {
return file_string.replace( /\r\n/g, '\n' );
} );
var process_object = ChildProcess.fork( 'source/cli.js', [ '-vio' ], {
silent: true
//stdio: [ 0, 'pipe', 'pipe', 'ipc' ]
} );
var bound_write_function = process_object.stdio[0].write.bind( process_object.stdio[0], await stdin_promise, 'utf8' );
var write_stdin_function = Pify( bound_write_function, {multiArgs: true});
var [ error ] = await write_stdin_function();
if( error == null ){
process_object.stdio[0].end();
var actual_stdout = '';
var actual_stderr = '';
process_object.stdio[1].on('data', function( chunk ){
t.log(`Test: ${t.title} received stdout chunk: ${chunk.toString('utf8')}`);
actual_stdout += chunk.toString('utf8');
});
process_object.stdio[2].on('data', function( chunk ){
t.log(` Test: ${t.title} received stderr chunk: ${chunk.toString('utf8')}`);
actual_stderr += chunk.toString('utf8');
});
const [ code, signal ] = await Pevent.pEvent(process_object, 'exit', {multiArgs: true});
t.log(`Test: ${t.title}: process exited with code: ${code} signal: ${signal} stdout: ${actual_stdout} stderr: ${actual_stderr}`);
var stdout_string = actual_stdout.replace( /\r\n/g, '\n' );
if( code === 0 ){
t.is( stdout_string, (await expected_stdout_promise)+'\n' );
} else{
t.fail( `Unexpected process exit code: ${code}` );
}
} else{
t.fail( `Writing to STDIN returned an error: ${error}` );
}
} );

0 comments on commit bb525e5

Please sign in to comment.