@@ -19,44 +19,31 @@ import { basename } from 'node:path'
19
19
import { WriteStream } from 'node:fs'
20
20
import { Readable , Transform , Writable } from 'node:stream'
21
21
import { Socket } from 'node:net'
22
- import { ProcessPromise , ProcessOutput , getZxDefaults } from '../build/index.js'
22
+ import {
23
+ ProcessPromise ,
24
+ ProcessOutput ,
25
+ resolveDefaults ,
26
+ } from '../build/index.js'
23
27
import '../build/globals.js'
24
28
25
29
describe ( 'core' , ( ) => {
26
- describe ( 'getZxDefaults ' , ( ) => {
27
- test ( 'verbose rewrite ' , async ( ) => {
28
- const defaults = getZxDefaults ( { verbose : false } , 'ZX_' , {
30
+ describe ( 'resolveDefaults() ' , ( ) => {
31
+ test ( 'overrides known (allowed) opts ' , async ( ) => {
32
+ const defaults = resolveDefaults ( { verbose : false } , 'ZX_' , {
29
33
ZX_VERBOSE : 'true' ,
34
+ ZX_PREFER_LOCAL : '/foo/bar/' ,
30
35
} )
31
36
assert . equal ( defaults . verbose , true )
37
+ assert . equal ( defaults . preferLocal , '/foo/bar/' )
32
38
} )
33
39
34
- test ( 'verbose ignore' , async ( ) => {
35
- const defaults = getZxDefaults ( { verbose : false } , 'ZX_' , {
36
- ZX_VERBOSE : 'true123' ,
37
- } )
38
- assert . equal ( defaults . verbose , false )
39
- } )
40
-
41
- test ( 'input ignored' , async ( ) => {
42
- const defaults = getZxDefaults ( { } , 'ZX_' , {
40
+ test ( 'ignores unknown' , async ( ) => {
41
+ const defaults = resolveDefaults ( { } , 'ZX_' , {
43
42
ZX_INPUT : 'input' ,
43
+ ZX_FOO : 'test' ,
44
44
} )
45
45
assert . equal ( defaults . input , undefined )
46
- } )
47
-
48
- test ( 'preferLocal rewrite boolean' , async ( ) => {
49
- const defaults = getZxDefaults ( { preferLocal : false } , 'ZX_' , {
50
- ZX_PREFER_LOCAL : 'true' ,
51
- } )
52
- assert . equal ( defaults . preferLocal , true )
53
- } )
54
-
55
- test ( 'preferLocal rewrite string' , async ( ) => {
56
- const defaults = getZxDefaults ( { preferLocal : false } , 'ZX_' , {
57
- ZX_PREFER_LOCAL : 'true123' ,
58
- } )
59
- assert . equal ( defaults . preferLocal , 'true123' )
46
+ assert . equal ( defaults . foo , undefined )
60
47
} )
61
48
} )
62
49
@@ -759,7 +746,6 @@ describe('core', () => {
759
746
describe ( '[Symbol.asyncIterator]' , ( ) => {
760
747
it ( 'should iterate over lines from stdout' , async ( ) => {
761
748
const process = $ `echo "Line1\nLine2\nLine3"`
762
-
763
749
const lines = [ ]
764
750
for await ( const line of process ) {
765
751
lines . push ( line )
@@ -773,7 +759,6 @@ describe('core', () => {
773
759
774
760
it ( 'should handle partial lines correctly' , async ( ) => {
775
761
const process = $ `node -e "process.stdout.write('PartialLine1\\nLine2\\nPartial'); setTimeout(() => process.stdout.write('Line3\\n'), 100)"`
776
-
777
762
const lines = [ ]
778
763
for await ( const line of process ) {
779
764
lines . push ( line )
@@ -795,7 +780,6 @@ describe('core', () => {
795
780
796
781
it ( 'should handle empty stdout' , async ( ) => {
797
782
const process = $ `echo -n ""`
798
-
799
783
const lines = [ ]
800
784
for await ( const line of process ) {
801
785
lines . push ( line )
@@ -806,7 +790,6 @@ describe('core', () => {
806
790
807
791
it ( 'should handle single line without trailing newline' , async ( ) => {
808
792
const process = $ `echo -n "SingleLine"`
809
-
810
793
const lines = [ ]
811
794
for await ( const line of process ) {
812
795
lines . push ( line )
@@ -821,27 +804,17 @@ describe('core', () => {
821
804
} )
822
805
823
806
it ( 'should yield all buffered and new chunks when iterated after a delay' , async ( ) => {
824
- const process = $ `sleep 0.1; echo Chunk1; sleep 0.2; echo Chunk2;`
825
-
826
- const collectedChunks = [ ]
827
-
828
- await new Promise ( ( resolve ) => setTimeout ( resolve , 400 ) )
807
+ const process = $ `sleep 0.1; echo Chunk1; sleep 0.1; echo Chunk2; sleep 0.2; echo Chunk3; sleep 0.1; echo Chunk4;`
808
+ const chunks = [ ]
829
809
810
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 250 ) )
830
811
for await ( const chunk of process ) {
831
- collectedChunks . push ( chunk )
812
+ chunks . push ( chunk )
832
813
}
833
814
834
- assert . equal ( collectedChunks . length , 2 , 'Should have received 2 chunks' )
835
- assert . equal (
836
- collectedChunks [ 0 ] ,
837
- 'Chunk1' ,
838
- 'First chunk should be "Chunk1"'
839
- )
840
- assert . equal (
841
- collectedChunks [ 1 ] ,
842
- 'Chunk2' ,
843
- 'Second chunk should be "Chunk2"'
844
- )
815
+ assert . equal ( chunks . length , 4 , 'Should get all chunks' )
816
+ assert . equal ( chunks [ 0 ] , 'Chunk1' , 'First chunk should be "Chunk1"' )
817
+ assert . equal ( chunks [ 3 ] , 'Chunk4' , 'Second chunk should be "Chunk4"' )
845
818
} )
846
819
} )
847
820
0 commit comments