@@ -6,11 +6,15 @@ import { join } from 'path';
6
6
7
7
import {
8
8
findFileInPath ,
9
- getRootDirPath ,
9
+ findParentNodeModules ,
10
10
getIgnoreConfigInPath ,
11
+ getProjectPackage ,
12
+ getRootDirPath ,
13
+ isDirectory ,
14
+ isFile ,
11
15
parseIgnoreConfig ,
12
- slugify ,
13
- getProjectPackage
16
+ sanitizePath ,
17
+ slugify
14
18
} from './utils' ;
15
19
16
20
describe ( 'utils' , ( ) => {
@@ -38,6 +42,21 @@ describe('utils', () => {
38
42
} ) ;
39
43
} ) ;
40
44
45
+ describe ( 'findParentNodeModules' , ( ) => {
46
+ it ( 'find node_modules with input directory' , async ( ) => {
47
+ assert . equal (
48
+ await findParentNodeModules ( './' ) ,
49
+ join ( process . cwd ( ) , '../../node_modules' )
50
+ ) ;
51
+ } ) ;
52
+ it ( 'fail to find node_modules with input directory with depth of 1' , async ( ) => {
53
+ assert . notEqual (
54
+ await findParentNodeModules ( './' , 1 ) ,
55
+ join ( process . cwd ( ) , '../../node_modules' )
56
+ ) ;
57
+ } ) ;
58
+ } ) ;
59
+
41
60
describe ( 'getIgnoreConfigInPath' , ( ) => {
42
61
it ( 'find ignore config with input directory' , async ( ) => {
43
62
assert . deepEqual ( await getIgnoreConfigInPath ( './' ) , [
@@ -91,6 +110,30 @@ describe('utils', () => {
91
110
} ) ;
92
111
} ) ;
93
112
113
+ describe ( 'isDirectory' , ( ) => {
114
+ it ( 'return true with directory input' , async ( ) => {
115
+ assert . equal ( await isDirectory ( './' ) , true ) ;
116
+ } ) ;
117
+ it ( 'return false with file input' , async ( ) => {
118
+ assert . equal ( await isDirectory ( './package.json' ) , false ) ;
119
+ } ) ;
120
+ it ( 'return false with invalid input' , async ( ) => {
121
+ assert . equal ( await isDirectory ( './invalid.txt' ) , false ) ;
122
+ } ) ;
123
+ } ) ;
124
+
125
+ describe ( 'isFile' , ( ) => {
126
+ it ( 'return true with file input' , async ( ) => {
127
+ assert . equal ( await isFile ( './package.json' ) , true ) ;
128
+ } ) ;
129
+ it ( 'return false with directory input' , async ( ) => {
130
+ assert . equal ( await isFile ( './' ) , false ) ;
131
+ } ) ;
132
+ it ( 'return false with invalid input' , async ( ) => {
133
+ assert . equal ( await isFile ( './invalid.txt' ) , false ) ;
134
+ } ) ;
135
+ } ) ;
136
+
94
137
describe ( 'parseIgnoreConfig' , ( ) => {
95
138
it ( 'parse ignore config' , ( ) => {
96
139
assert . deepEqual (
@@ -125,6 +168,17 @@ describe('utils', () => {
125
168
} ) ;
126
169
} ) ;
127
170
171
+ describe ( 'sanitizePath' , ( ) => {
172
+ it ( 'sanitize path' , ( ) => {
173
+ assert . equal (
174
+ sanitizePath (
175
+ 'file:///Users/scottdoxey/git/github/doxdox/packages/doxdox-cli/dist/src/index.js'
176
+ ) ,
177
+ '/Users/scottdoxey/git/github/doxdox/packages/doxdox-cli/dist/src/index.js'
178
+ ) ;
179
+ } ) ;
180
+ } ) ;
181
+
128
182
describe ( 'slugify' , ( ) => {
129
183
it ( 'slugify path' , ( ) => {
130
184
assert . equal ( slugify ( './src/utils.ts' ) , 'src-utils-ts' ) ;
0 commit comments