@@ -2,7 +2,7 @@ import { makeParseConsoleOutput } from './makeParseConsoleOutput';
22import { ParseConsoleOutputResult } from './types' ;
33
44describe ( 'parse console output' , ( ) => {
5- let parseConsoleOutput : ( data : string ) => ParseConsoleOutputResult ;
5+ let parseConsoleOutput : ( data : Buffer ) => ParseConsoleOutputResult ;
66
77 beforeEach ( ( ) => {
88 parseConsoleOutput = makeParseConsoleOutput ( {
@@ -13,91 +13,108 @@ describe('parse console output', () => {
1313
1414 it ( 'should return a single line when output contains a line separator and prompt' , ( ) => {
1515 expect (
16- parseConsoleOutput ( 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \n/ #' )
16+ parseConsoleOutput (
17+ Buffer . from ( 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \n/ #' )
18+ )
1719 ) . toEqual ( {
1820 lines : [ 'drwxr-xr-x 18 root root 0 Sep 11 15:48 .' ] ,
19- remaining : '' ,
21+ remaining : Buffer . alloc ( 0 ) ,
2022 } ) ;
2123 } ) ;
2224
2325 it ( 'should return many lines when output contains line separator and prompt' , ( ) => {
2426 expect (
2527 parseConsoleOutput (
26- 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \ndrwxr-xr-x 18 root root 0 Sep 11 15:48 .. \n/ #'
28+ Buffer . from (
29+ 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \ndrwxr-xr-x 18 root root 0 Sep 11 15:48 .. \n/ #'
30+ )
2731 )
2832 ) . toEqual ( {
2933 lines : [
3034 'drwxr-xr-x 18 root root 0 Sep 11 15:48 .' ,
3135 'drwxr-xr-x 18 root root 0 Sep 11 15:48 ..' ,
3236 ] ,
33- remaining : '' ,
37+ remaining : Buffer . alloc ( 0 ) ,
3438 } ) ;
3539 } ) ;
3640
3741 it ( 'should return lines when output contains expected prompt with pre escape chars' , ( ) => {
3842 expect (
3943 parseConsoleOutput (
40- 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \ndrwxr-xr-x 18 root root 0 Sep 11 15:48 .. \n\u001b[1;32m/ #'
44+ Buffer . from (
45+ 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \ndrwxr-xr-x 18 root root 0 Sep 11 15:48 .. \n\u001b[1;32m/ #'
46+ )
4147 )
4248 ) . toEqual ( {
4349 lines : [
4450 'drwxr-xr-x 18 root root 0 Sep 11 15:48 .' ,
4551 'drwxr-xr-x 18 root root 0 Sep 11 15:48 ..' ,
4652 ] ,
47- remaining : '' ,
53+ remaining : Buffer . alloc ( 0 ) ,
4854 } ) ;
4955 } ) ;
5056
5157 it ( 'should return lines when output contains expected prompt with post escape chars' , ( ) => {
5258 expect (
5359 parseConsoleOutput (
54- 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \ndrwxr-xr-x 18 root root 0 Sep 11 15:48 .. \n/ #\u001b[1;32m'
60+ Buffer . from (
61+ 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \ndrwxr-xr-x 18 root root 0 Sep 11 15:48 .. \n/ #\u001b[1;32m'
62+ )
5563 )
5664 ) . toEqual ( {
5765 lines : [
5866 'drwxr-xr-x 18 root root 0 Sep 11 15:48 .' ,
5967 'drwxr-xr-x 18 root root 0 Sep 11 15:48 ..' ,
6068 ] ,
61- remaining : '' ,
69+ remaining : Buffer . alloc ( 0 ) ,
6270 } ) ;
6371 } ) ;
6472
6573 it ( 'should return remaining data when no prompt in output' , ( ) => {
6674 expect (
6775 parseConsoleOutput (
68- 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \ndrwxr-xr-x 18 root root 0 Sep 11 15:48 .. \n'
76+ Buffer . from (
77+ 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \ndrwxr-xr-x 18 root root 0 Sep 11 15:48 .. \n'
78+ )
6979 )
7080 ) . toEqual ( {
7181 lines : [ ] ,
72- remaining :
73- 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \ndrwxr-xr-x 18 root root 0 Sep 11 15:48 .. \n' ,
82+ remaining : Buffer . from (
83+ 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \ndrwxr-xr-x 18 root root 0 Sep 11 15:48 .. \n'
84+ ) ,
7485 } ) ;
7586 } ) ;
7687
7788 it ( 'should return remaining data when no line separator in output' , ( ) => {
7889 expect (
79- parseConsoleOutput ( 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . / #' )
90+ parseConsoleOutput (
91+ Buffer . from ( 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . / #' )
92+ )
8093 ) . toEqual ( {
8194 lines : [ ] ,
82- remaining : 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . / #' ,
95+ remaining : Buffer . from ( 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . / #' ) ,
8396 } ) ;
8497 } ) ;
8598
8699 it ( 'should return remaining data when prompt is not the expected one' , ( ) => {
87100 expect (
88- parseConsoleOutput ( 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \n/ $' )
101+ parseConsoleOutput (
102+ Buffer . from ( 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \n/ $' )
103+ )
89104 ) . toEqual ( {
90105 lines : [ ] ,
91- remaining : 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \n/ $' ,
106+ remaining : Buffer . from ( 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \n/ $' ) ,
92107 } ) ;
93108 } ) ;
94109
95110 it ( 'should return remaining data when line separator is not the expected one' , ( ) => {
96111 expect (
97- parseConsoleOutput ( 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \r/ #' )
112+ parseConsoleOutput (
113+ Buffer . from ( 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \r/ #' )
114+ )
98115 ) . toEqual ( {
99116 lines : [ ] ,
100- remaining : 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \r/ #' ,
117+ remaining : Buffer . from ( 'drwxr-xr-x 18 root root 0 Sep 11 15:48 . \r/ #' ) ,
101118 } ) ;
102119 } ) ;
103120} ) ;
0 commit comments