22
33const { once} = require ( 'node:events' ) ;
44
5- const { test} = require ( 'supertape' ) ;
6- const mock = require ( 'mock-require' ) ;
7- const clear = require ( 'clear-module' ) ;
8- const wait = require ( '@iocmd/wait' ) ;
5+ const { test, stub} = require ( 'supertape' ) ;
96
10- const clearFileop = require ( '../lib/clear ' ) ;
7+ const wait = require ( '@iocmd/wait ' ) ;
118
129const {
1310 rawErrorEmitter,
@@ -16,17 +13,13 @@ const {
1613 endEmitter,
1714} = require ( '../lib/emitters' ) ;
1815
16+ const connect = require ( '../lib/connect' ) ;
1917const connectPath = '../lib/connect' ;
20- const extractPath = 'inly' ;
21- const isRootPath = '../../server/is-root-win32' ;
2218
2319test ( 'operate: extract: error' , async ( t ) => {
24- clearFileop ( ) ;
25- clear ( extractPath ) ;
26- mock ( extractPath , rawErrorEmitter ) ;
27- const connect = require ( connectPath ) ;
28-
29- const { socket, done} = await connect ( ) ;
20+ const { socket, done} = await connect ( {
21+ inly : rawErrorEmitter ,
22+ } ) ;
3023
3124 const error = 'EACCES: /hello/abc' ;
3225 const from = '/hello/abc' ;
@@ -49,13 +42,9 @@ test('operate: extract: error', async (t) => {
4942} ) ;
5043
5144test ( 'operate: extract: progress' , async ( t ) => {
52- clearFileop ( ) ;
53- clear ( extractPath ) ;
54- mock ( extractPath , progressEmitter ) ;
55-
56- const connect = require ( connectPath ) ;
57-
58- const { socket, done} = await connect ( ) ;
45+ const { socket, done} = await connect ( {
46+ inly : progressEmitter ,
47+ } ) ;
5948
6049 const from = '/hello/abc' ;
6150 const to = '/world/abc' ;
@@ -77,13 +66,11 @@ test('operate: extract: progress', async (t) => {
7766} ) ;
7867
7968test ( 'operate: extract: file' , async ( t ) => {
80- clearFileop ( ) ;
81- clear ( extractPath ) ;
82- mock ( extractPath , fileEmitter ) ;
83-
8469 const connect = require ( connectPath ) ;
8570
86- const { socket, done} = await connect ( ) ;
71+ const { socket, done} = await connect ( {
72+ inly : fileEmitter ,
73+ } ) ;
8774
8875 const from = '/hello/abc' ;
8976 const to = '/world/abc' ;
@@ -105,13 +92,11 @@ test('operate: extract: file', async (t) => {
10592} ) ;
10693
10794test ( 'operate: extract: end' , async ( t ) => {
108- clearFileop ( ) ;
109- clear ( extractPath ) ;
110- mock ( extractPath , endEmitter ) ;
111-
11295 const connect = require ( connectPath ) ;
11396
114- const { socket, done} = await connect ( ) ;
97+ const { socket, done} = await connect ( {
98+ inly : endEmitter ,
99+ } ) ;
115100
116101 const from = '/hello/abc' ;
117102 const to = '/world/abc' ;
@@ -129,35 +114,23 @@ test('operate: extract: end', async (t) => {
129114} ) ;
130115
131116test ( 'operate: extract: error: root' , async ( t ) => {
132- clearFileop ( ) ;
133- clear ( isRootPath ) ;
134-
135117 const from = '/hello' ;
136118 const to = '/world' ;
137119 const names = [ 'abc' ] ;
138- const truth = ( ) => true ;
120+ const truth = stub ( ) . returns ( true ) ;
121+ const isRootWin32 = stub ( ) . returns ( truth ) ;
139122
140- Object . defineProperty ( truth , 'length' , {
141- value : 2 ,
123+ const { socket , done } = await connect ( {
124+ isRootWin32 ,
142125 } ) ;
143126
144- const isRoot = require ( isRootPath ) ;
145- mock ( isRootPath , truth ) ;
146-
147- const connect = require ( connectPath ) ;
148-
149- mock ( isRootPath , isRoot ) ;
150-
151- const { socket, done} = await connect ( ) ;
152-
153127 socket . emit ( 'operation' , 'extract' , from , to , names ) ;
154128 const [ id ] = await once ( socket , 'id' ) ;
155129
156130 socket . emit ( `${ id } #start` ) ;
157131 const [ e ] = await once ( socket , `${ id } #error` ) ;
158132
159133 done ( ) ;
160- clear ( isRootPath ) ;
161134
162135 const error = 'Could not extract from root on windows!' ;
163136
0 commit comments