@@ -2,8 +2,11 @@ const fsp = require('fs').promises;
22const p = require ( 'path' ) ;
33const { execCommandLine} = require ( './utilities/exec' ) ;
44const walk = require ( '../action-walk' ) ;
5- const { expect} = require ( 'chai' ) ;
5+ const chai = require ( 'chai' ) ;
6+ const expect = chai . expect ;
7+ chai . use ( require ( 'chai-as-promised' ) ) ;
68
9+ // calculate expected results using stat, du, and find.
710const testdir = '.' ;
811let testdirStat ;
912const duOutput = {
@@ -59,7 +62,26 @@ describe('verify that action-walk works as expected', function () {
5962 } )
6063 } ) ;
6164
62- it . only ( 'should count the correct number of directories, files, and links' , function ( ) {
65+ it ( 'should work with no arguments other than a directory' , function ( ) {
66+ return walk ( '/dev' ) ;
67+ } ) ;
68+
69+ it ( 'should reject if the argument is not a directory' , function ( ) {
70+ return expect ( walk ( './package.json' ) ) . eventually . rejected ;
71+ } )
72+
73+ it ( 'should work with non-file, non-directory, non-link file types' , function ( ) {
74+ const options = {
75+ otherAction : ( ) => options . own . other += 1 ,
76+ own : { other : 0 } ,
77+ } ;
78+ return walk ( '/dev' , options )
79+ . then ( ( ) => {
80+ expect ( options . own . other ) . not . equal ( 0 ) ;
81+ } ) ;
82+ } ) ;
83+
84+ it ( 'should count the correct number of directories, files, and links' , function ( ) {
6385 let dirCount = 0 ;
6486 let fileCount = 0 ;
6587 let linkCount = 0 ;
@@ -80,7 +102,7 @@ describe('verify that action-walk works as expected', function () {
80102 } ) ;
81103 } ) ;
82104
83- it . only ( 'du -ab totals should differ by targetsize - linksize using stat' , function ( ) {
105+ it ( 'du -ab totals should differ by targetsize - linksize using stat' , function ( ) {
84106 let delta = 0 ;
85107 const options = {
86108 dirAction : ( path , ctx ) => ctx . own . total += ctx . stat . size ,
@@ -111,7 +133,7 @@ describe('verify that action-walk works as expected', function () {
111133 } )
112134 } ) ;
113135
114- it . only ( 'should match du -ab output using lstat without a linkAction' , function ( ) {
136+ it ( 'should match du -ab output using lstat without a linkAction' , function ( ) {
115137 const options = {
116138 dirAction : ( path , ctx ) => ctx . own . total += ctx . stat . size ,
117139 fileAction : ( path , ctx ) => ctx . own . total += ctx . stat . size ,
@@ -128,7 +150,7 @@ describe('verify that action-walk works as expected', function () {
128150 } )
129151 } ) ;
130152
131- it . only ( 'should match du -ab --exclude=node_modules' , function ( ) {
153+ it ( 'should match du -ab --exclude=node_modules' , function ( ) {
132154 const options = {
133155 dirAction : ( path , { dirent, stat, own} ) => {
134156 if ( own . skipDirs && own . skipDirs . indexOf ( dirent . name ) >= 0 ) {
@@ -150,10 +172,10 @@ describe('verify that action-walk works as expected', function () {
150172 } )
151173 } ) ;
152174
153- it . only ( 'should execute recursively matching du -b' , function ( ) {
175+ it ( 'should execute recursively matching du -b' , function ( ) {
154176 const own = { total : 0 , linkCount : 0 , dirTotals : { } , skipDirs : [ ] } ;
155177 const options = {
156- dirAction : daDirOnly ,
178+ dirAction : daDirsOnly ,
157179 fileAction : ( path , ctx ) => ctx . own . total += ctx . stat . size ,
158180 own,
159181 stat : 'lstat' ,
@@ -171,17 +193,17 @@ describe('verify that action-walk works as expected', function () {
171193 it ( 'should execute recursively matching du -b --exclude=node_modules' , function ( ) {
172194 const own = { total : 0 , linkCount : 0 , dirTotals : { } , skipDirs : [ 'node_modules' ] } ;
173195 const options = {
174- dirAction : daDirOnly ,
196+ dirAction : daDirsOnly ,
175197 fileAction : ( path , ctx ) => ctx . own . total += ctx . stat . size ,
176198 own,
177199 stat : 'lstat' ,
178200 } ;
179201
180202 return walk ( testdir , options )
181203 . then ( ( ) => {
182- expect ( own . total + testdirStat . size ) . equal ( duOutput . w_node [ testdir ] ) ;
204+ expect ( own . total + testdirStat . size ) . equal ( duOutput . wo_node [ testdir ] ) ;
183205 for ( const dir in own . dirTotals ) {
184- expect ( own . dirTotals [ dir ] ) . equal ( duOutput . w_node [ `${ dir } ` ] ) ;
206+ expect ( own . dirTotals [ dir ] ) . equal ( duOutput . wo_node [ `${ dir } ` ] ) ;
185207 }
186208 } ) ;
187209 } ) ;
@@ -193,15 +215,15 @@ describe('verify that action-walk works as expected', function () {
193215// utilities
194216//
195217
196- async function daDirOnly ( path , ctx ) {
218+ async function daDirsOnly ( path , ctx ) {
197219 const { dirent, stat, own} = ctx ;
198220 if ( own . skipDirs && own . skipDirs . indexOf ( dirent . name ) >= 0 ) {
199221 return 'skip' ;
200222 }
201223 own . dirTotals [ path ] = 0 ;
202224 const newown = { total : 0 , dirTotals : own . dirTotals } ;
203225 const options = {
204- dirAction : daDirOnly ,
226+ dirAction : daDirsOnly ,
205227 fileAction : ( path , ctx ) => ctx . own . total += ctx . stat . size ,
206228 own : newown ,
207229 stat : 'lstat' ,
0 commit comments