@@ -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 ( './' ) , [
@@ -67,6 +86,54 @@ describe('utils', () => {
67
86
} ) ;
68
87
} ) ;
69
88
89
+ describe ( 'getProjectPackage' , ( ) => {
90
+ it ( 'gets contents from project package' , async ( ) => {
91
+ const { name, description, version, exports } = JSON . parse (
92
+ await fs . readFile ( './package.json' , 'utf8' )
93
+ ) ;
94
+
95
+ assert . deepEqual ( await getProjectPackage ( './' ) , {
96
+ name,
97
+ description,
98
+ version,
99
+ exports
100
+ } ) ;
101
+ } ) ;
102
+ it ( 'file to get contents from folder without package file' , async ( ) => {
103
+ assert . deepEqual ( await getProjectPackage ( './src/' ) , { } ) ;
104
+ } ) ;
105
+ } ) ;
106
+
107
+ describe ( 'getRootDirPath' , ( ) => {
108
+ it ( 'get dir path' , ( ) => {
109
+ assert . equal ( getRootDirPath ( ) , join ( process . cwd ( ) , './src' ) ) ;
110
+ } ) ;
111
+ } ) ;
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
+
70
137
describe ( 'parseIgnoreConfig' , ( ) => {
71
138
it ( 'parse ignore config' , ( ) => {
72
139
assert . deepEqual (
@@ -101,9 +168,14 @@ describe('utils', () => {
101
168
} ) ;
102
169
} ) ;
103
170
104
- describe ( 'getRootDirPath' , ( ) => {
105
- it ( 'get dir path' , ( ) => {
106
- assert . equal ( getRootDirPath ( ) , join ( process . cwd ( ) , './src' ) ) ;
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
+ ) ;
107
179
} ) ;
108
180
} ) ;
109
181
@@ -112,22 +184,4 @@ describe('utils', () => {
112
184
assert . equal ( slugify ( './src/utils.ts' ) , 'src-utils-ts' ) ;
113
185
} ) ;
114
186
} ) ;
115
-
116
- describe ( 'getProjectPackage' , ( ) => {
117
- it ( 'gets contents from project package' , async ( ) => {
118
- const { name, description, version, exports } = JSON . parse (
119
- await fs . readFile ( './package.json' , 'utf8' )
120
- ) ;
121
-
122
- assert . deepEqual ( await getProjectPackage ( './' ) , {
123
- name,
124
- description,
125
- version,
126
- exports
127
- } ) ;
128
- } ) ;
129
- it ( 'file to get contents from folder without package file' , async ( ) => {
130
- assert . deepEqual ( await getProjectPackage ( './src/' ) , { } ) ;
131
- } ) ;
132
- } ) ;
133
187
} ) ;
0 commit comments