1+ const { describe, it, beforeEach, afterEach } = require ( "node:test" ) ;
12const assert = require ( "assert" ) ;
23const { Client } = require ( "../dist" ) ;
34const MockFtpServer = require ( "./MockFtpServer" ) ;
@@ -13,124 +14,126 @@ const NO_FEAT_REPLY = `
1314` ;
1415const FILENAME = "file.txt"
1516
16- describe ( "Simple commands" , function ( ) {
17+ describe ( "Simple commands" , ( ) => {
1718
18- this . beforeEach ( ( ) => {
19- this . server = new MockFtpServer ( )
20- this . client = new Client ( 1000 )
21- return this . client . access ( {
22- port : this . server . ctrlAddress . port ,
19+ let server , client ;
20+
21+ beforeEach ( ( ) => {
22+ server = new MockFtpServer ( )
23+ client = new Client ( 1000 )
24+ return client . access ( {
25+ port : server . ctrlAddress . port ,
2326 user : "test" ,
2427 password : "test"
2528 } )
2629 } )
2730
28- this . afterEach ( ( ) => {
29- this . client . close ( )
30- this . server . close ( )
31+ afterEach ( ( ) => {
32+ client . close ( )
33+ server . close ( )
3134 } )
3235
3336 it ( "can get a file size" , ( ) => {
34- this . server . addHandlers ( {
35- "size" : ( { arg} ) => arg === "file.txt" ? "213 6666" : "400 File not found"
37+ server . addHandlers ( {
38+ "size" : ( { arg} ) => arg === "file.txt" ? "213 6666" : "400 File not found"
3639 } )
37- return this . client . size ( "file.txt" ) . then ( result => {
40+ return client . size ( "file.txt" ) . then ( result => {
3841 assert . strictEqual ( result , 6666 )
3942 } )
4043 } )
4144
4245 it ( "can get last modified time" , ( ) => {
43- this . server . addHandlers ( {
46+ server . addHandlers ( {
4447 "mdtm" : ( { arg} ) => arg === "file.txt" ? "213 19951217032400" : "400 File not found"
4548 } )
46- return this . client . lastMod ( "file.txt" ) . then ( result => {
49+ return client . lastMod ( "file.txt" ) . then ( result => {
4750 assert . deepEqual ( result , new Date ( "1995-12-17T03:24:00+0000" ) )
48- } )
51+ } )
4952 } )
5053
5154 it ( "can get features" , ( ) => {
52- this . server . addHandlers ( {
55+ server . addHandlers ( {
5356 "feat" : ( ) => FEAT_REPLY
5457 } )
55- return this . client . features ( ) . then ( result => {
58+ return client . features ( ) . then ( result => {
5659 assert . deepEqual ( result , new Map ( [ [ "MLST" , "size*;create" ] , [ "SIZE" , "" ] ] ) )
57- } )
60+ } )
5861 } )
5962
6063 it ( "can handle no features" , ( ) => {
61- this . server . addHandlers ( {
64+ server . addHandlers ( {
6265 "feat" : ( ) => NO_FEAT_REPLY
6366 } )
64- return this . client . features ( ) . then ( result => {
67+ return client . features ( ) . then ( result => {
6568 assert . deepEqual ( result , new Map ( ) )
66- } )
69+ } )
6770 } )
6871
6972 it ( "returns empty feature set when server sends error" , ( ) => {
70- this . server . addHandlers ( {
73+ server . addHandlers ( {
7174 "test" : ( ) => "200 OK"
7275 } )
73- return this . client . send ( "TEST" ) . then ( result => {
76+ return client . send ( "TEST" ) . then ( result => {
7477 assert . deepEqual ( result , { code : 200 , message : "200 OK" } )
75- } )
78+ } )
7679 } )
7780
7881 it ( "sending command handles error" , ( ) => {
79- this . server . addHandlers ( {
82+ server . addHandlers ( {
8083 "test" : ( ) => "500 Command unknown"
8184 } )
82- return assert . rejects ( ( ) => this . client . send ( "TEST" ) , {
85+ return assert . rejects ( ( ) => client . send ( "TEST" ) , {
8386 name : "FTPError" ,
8487 message : "500 Command unknown"
85- } )
88+ } )
8689 } )
8790
8891 it ( "can ignore error response " , ( ) => {
89- this . server . addHandlers ( {
92+ server . addHandlers ( {
9093 "test" : ( ) => "500 Command unknown"
9194 } )
92- return assert . doesNotReject ( ( ) => this . client . sendIgnoringError ( "TEST" ) )
95+ return assert . doesNotReject ( ( ) => client . sendIgnoringError ( "TEST" ) )
9396 } )
9497
9598 it ( "throws if connection error even if ignoring errors has been requested" , ( ) => {
96- this . server . addHandlers ( {
97- "test" : ( ) => this . server . ctrlConn . destroy ( )
99+ server . addHandlers ( {
100+ "test" : ( ) => server . ctrlConn . destroy ( )
98101 } )
99- return assert . rejects ( ( ) => this . client . send ( "TEST" ) , {
102+ return assert . rejects ( ( ) => client . send ( "TEST" ) , {
100103 name : "Error" ,
101104 message : "Server sent FIN packet unexpectedly, closing connection."
102- } )
105+ } )
103106 } )
104107
105108 it ( "can rename a file" , ( ) => {
106- this . server . addHandlers ( {
109+ server . addHandlers ( {
107110 "rnfr" : ( { arg} ) => arg === "old.txt" ? "350 Accepted" : "500 File not found" ,
108111 "rnto" : ( { arg} ) => arg === "new.txt" ? "200 Renamed" : "500 File not found" ,
109112 } )
110- return this . client . rename ( "old.txt" , "new.txt" ) . then ( result => {
113+ return client . rename ( "old.txt" , "new.txt" ) . then ( result => {
111114 assert . deepEqual ( result , { code : 200 , message : "200 Renamed" } )
112115 } )
113116 } )
114-
117+
115118 it ( "can handle leading whitespace in a filename" , ( ) => {
116- this . server . addHandlers ( {
119+ server . addHandlers ( {
117120 "pwd" : ( ) => `257 "/this/that"`
118121 } )
119- return this . client . protectWhitespace ( " file.txt" ) . then ( result => {
122+ return client . protectWhitespace ( " file.txt" ) . then ( result => {
120123 assert . strictEqual ( result , "/this/that/ file.txt" )
121124 } )
122125 } )
123126
124127 it ( "can handle leading whitespace in relative path" , ( ) => {
125- this . server . addHandlers ( {
128+ server . addHandlers ( {
126129 "pwd" : ( ) => `257 "/this/that"`
127130 } )
128- return this . client . protectWhitespace ( " a/b" ) . then ( result => {
131+ return client . protectWhitespace ( " a/b" ) . then ( result => {
129132 assert . strictEqual ( result , "/this/that/ a/b" )
130133 } )
131134 } )
132135
133- it ( "can remove a file" )
134- it ( "can change directory" )
135- it ( "can get the current working directory" )
136- } )
136+ it . todo ( "can remove a file" )
137+ it . todo ( "can change directory" )
138+ it . todo ( "can get the current working directory" )
139+ } )
0 commit comments