@@ -27,9 +27,35 @@ describe('Browser main tests', function () {
2727 expect ( Filer . fs . name ) . to . equal ( 'local' ) ;
2828 } ) ;
2929
30- it ( 'Should load Phoenix fs in browser' , function ( ) {
30+ it ( 'Should load Phoenix fs in browser' , async function ( ) {
3131 expect ( fs ) . to . exist ;
3232 expect ( fs . name ) . to . equal ( 'phoenixFS' ) ;
33+ // setup test folders
34+ console . log ( 'cleaning: ' , window . virtualTestPath ) ;
35+ let cleanSuccess = false ;
36+ fs . unlink ( window . virtualTestPath , ( ) => {
37+ cleanSuccess = true ;
38+ } ) ;
39+ await waitForTrue ( ( ) => { return cleanSuccess ; } , 10000 ) ;
40+ console . log ( 'cleaning: ' , window . mountTestPath ) ;
41+ cleanSuccess = false ;
42+ fs . unlink ( window . mountTestPath , ( ) => {
43+ cleanSuccess = true ;
44+ } ) ;
45+ await waitForTrue ( ( ) => { return cleanSuccess ; } , 10000 ) ;
46+
47+ console . log ( 'mkdir: ' , window . virtualTestPath ) ;
48+ cleanSuccess = false ;
49+ fs . mkdirs ( window . virtualTestPath , 777 , true , ( ) => {
50+ cleanSuccess = true ;
51+ } ) ;
52+ await waitForTrue ( ( ) => { return cleanSuccess ; } , 10000 ) ;
53+ console . log ( 'mkdir: ' , window . mountTestPath ) ;
54+ cleanSuccess = false ;
55+ fs . mkdirs ( window . mountTestPath , 777 , true , ( ) => {
56+ cleanSuccess = true ;
57+ } ) ;
58+ await waitForTrue ( ( ) => { return cleanSuccess ; } , 10000 ) ;
3359 } ) ;
3460
3561 it ( 'Should phoenix native write in browser' , async function ( ) {
@@ -39,7 +65,7 @@ describe('Browser main tests', function () {
3965 writeSuccess = true ;
4066 }
4167 } ) ;
42- await waitForTrue ( ( ) => { return writeSuccess ; } , 1000 ) ;
68+ await waitForTrue ( ( ) => { return writeSuccess ; } , 10000 ) ;
4369 expect ( writeSuccess ) . to . be . true ;
4470 } ) ;
4571
@@ -64,7 +90,7 @@ describe('Browser main tests', function () {
6490 } ) ;
6591 await waitForTrue ( ( ) => { return readSuccess ; } , 1000 ) ;
6692 expect ( readSuccess ) . to . be . true ;
67- expect ( contentsRead . length ) . to . be . above ( 1 ) ;
93+ expect ( contentsRead . length ) . to . equal ( 1 ) ;
6894 } ) ;
6995
7096 it ( 'Should phoenix native read dir with withFileTypes' , async function ( ) {
@@ -90,4 +116,72 @@ describe('Browser main tests', function () {
90116 await waitForTrue ( ( ) => { return delSuccess ; } , 1000 ) ;
91117 expect ( delSuccess ) . to . be . true ;
92118 } ) ;
119+
120+ it ( 'Should phoenix mkdir(path,cb) in browser if it doesnt exist' , async function ( ) {
121+ // mount fs
122+ let createSuccess = false ;
123+ fs . mkdir ( `${ window . mountTestPath } /testDir` , ( err ) => {
124+ if ( ! err ) {
125+ createSuccess = true ;
126+ }
127+ } ) ;
128+ await waitForTrue ( ( ) => { return createSuccess ; } , 1000 ) ;
129+ expect ( createSuccess ) . to . be . true ;
130+ // virtual fs
131+ createSuccess = false ;
132+ fs . mkdir ( `${ window . virtualTestPath } /testDir` , ( err ) => {
133+ if ( ! err ) {
134+ createSuccess = true ;
135+ }
136+ } ) ;
137+ await waitForTrue ( ( ) => { return createSuccess ; } , 1000 ) ;
138+ expect ( createSuccess ) . to . be . true ;
139+ } ) ;
140+
141+ it ( 'Should phoenix mount:mkdir(path,mode, cb) in browser if it doesnt exist' , async function ( ) {
142+ // mount fs
143+ let createSuccess = false ;
144+ fs . mkdir ( `${ window . mountTestPath } /testDir1` , 777 , ( err ) => {
145+ if ( ! err ) {
146+ createSuccess = true ;
147+ }
148+ } ) ;
149+ await waitForTrue ( ( ) => { return createSuccess ; } , 1000 ) ;
150+ expect ( createSuccess ) . to . be . true ;
151+ } ) ;
152+ it ( 'Should phoenix virtual:mkdir(path,mode, cb) in browser if it doesnt exist' , async function ( ) {
153+ // virtual fs
154+ let createSuccess = false ;
155+ fs . mkdir ( `${ window . virtualTestPath } /testDir1` , 777 , ( err ) => {
156+ if ( ! err ) {
157+ createSuccess = true ;
158+ }
159+ } ) ;
160+ await waitForTrue ( ( ) => { return createSuccess ; } , 1000 ) ;
161+ expect ( createSuccess ) . to . be . true ;
162+ } ) ;
163+
164+ it ( 'Should phoenix fail mount:mkdir(path,mode, cb) if already exists' , async function ( ) {
165+ // mount fs
166+ let failed = false ;
167+ fs . mkdir ( `${ window . mountTestPath } /testDir1` , 777 , ( err ) => {
168+ if ( err ) {
169+ failed = true ;
170+ }
171+ } ) ;
172+ await waitForTrue ( ( ) => { return failed ; } , 1000 ) ;
173+ expect ( failed ) . to . be . true ;
174+ } ) ;
175+
176+ it ( 'Should phoenix fail virtual:mkdir(path,mode, cb) if already exists' , async function ( ) {
177+ // virtual fs
178+ let failed = false ;
179+ fs . mkdir ( `${ window . virtualTestPath } /testDir1` , 777 , ( err ) => {
180+ if ( err ) {
181+ failed = true ;
182+ }
183+ } ) ;
184+ await waitForTrue ( ( ) => { return failed ; } , 1000 ) ;
185+ expect ( failed ) . to . be . true ;
186+ } ) ;
93187} ) ;
0 commit comments