1
- import assert from 'assert' ;
2
-
3
1
import { promises as fs } from 'fs' ;
4
2
5
3
import { join } from 'path' ;
@@ -19,40 +17,34 @@ import {
19
17
describe ( 'utils' , ( ) => {
20
18
describe ( 'findFileInPath' , ( ) => {
21
19
it ( 'find package with input directory' , async ( ) => {
22
- assert . equal (
23
- await findFileInPath ( './' ) ,
20
+ expect ( await findFileInPath ( './' ) ) . toEqual (
24
21
join ( process . cwd ( ) , './package.json' )
25
22
) ;
26
23
} ) ;
27
24
28
25
it ( 'find package with input file' , async ( ) => {
29
- assert . equal (
30
- await findFileInPath ( './package.json' ) ,
26
+ expect ( await findFileInPath ( './package.json' ) ) . toEqual (
31
27
join ( process . cwd ( ) , './package.json' )
32
28
) ;
33
29
} ) ;
34
30
35
31
it ( 'fail to find package with input non package.json file' , async ( ) => {
36
- assert . equal ( await findFileInPath ( './jest.config.js' ) , null ) ;
32
+ expect ( await findFileInPath ( './jest.config.js' ) ) . toBeNull ( ) ;
37
33
} ) ;
38
34
39
35
it ( 'fail to find package with invalid directory' , async ( ) => {
40
- assert . equal ( await findFileInPath ( '../testing' ) , null ) ;
36
+ expect ( await findFileInPath ( '../testing' ) ) . toBeNull ( ) ;
41
37
} ) ;
42
38
} ) ;
43
39
44
40
describe ( 'findParentNodeModules' , ( ) => {
45
41
it ( 'find node_modules with input directory' , async ( ) => {
46
- assert . equal (
47
- await findParentNodeModules ( './' ) ,
42
+ expect ( await findParentNodeModules ( './' ) ) . toEqual (
48
43
join ( process . cwd ( ) , '../../node_modules' )
49
44
) ;
50
45
} ) ;
51
46
it ( 'fail to find node_modules with input directory with depth of 1' , async ( ) => {
52
- assert . notEqual (
53
- await findParentNodeModules ( './' , 1 ) ,
54
- join ( process . cwd ( ) , '../../node_modules' )
55
- ) ;
47
+ expect ( await findParentNodeModules ( './' , 1 ) ) . toBeNull ( ) ;
56
48
} ) ;
57
49
} ) ;
58
50
@@ -62,96 +54,114 @@ describe('utils', () => {
62
54
await fs . readFile ( './package.json' , 'utf8' )
63
55
) ;
64
56
65
- assert . deepEqual ( await getProjectPackage ( './' ) , {
66
- name,
67
- description,
68
- version,
69
- exports
70
- } ) ;
57
+ expect ( await getProjectPackage ( './' ) ) . toEqual (
58
+ expect . objectContaining ( {
59
+ name,
60
+ description,
61
+ version,
62
+ exports
63
+ } )
64
+ ) ;
71
65
} ) ;
72
66
it ( 'file to get contents from folder without package file' , async ( ) => {
73
- assert . deepEqual ( await getProjectPackage ( './src/' ) , { } ) ;
67
+ expect ( await getProjectPackage ( './src/' ) ) . toEqual ( { } ) ;
74
68
} ) ;
75
69
} ) ;
76
70
77
71
describe ( 'getRootDirPath' , ( ) => {
78
72
it ( 'get dir path' , ( ) => {
79
- assert . equal ( getRootDirPath ( ) , join ( process . cwd ( ) , './src' ) ) ;
73
+ expect ( getRootDirPath ( ) ) . toEqual ( join ( process . cwd ( ) , './src' ) ) ;
80
74
} ) ;
81
75
} ) ;
82
76
83
77
describe ( 'isDirectory' , ( ) => {
84
78
it ( 'return true with directory input' , async ( ) => {
85
- assert . equal ( await isDirectory ( './' ) , true ) ;
79
+ expect ( await isDirectory ( './' ) ) . toBeTruthy ( ) ;
86
80
} ) ;
87
81
it ( 'return false with file input' , async ( ) => {
88
- assert . equal ( await isDirectory ( './package.json' ) , false ) ;
82
+ expect ( await isDirectory ( './package.json' ) ) . toBeFalsy ( ) ;
89
83
} ) ;
90
84
it ( 'return false with invalid input' , async ( ) => {
91
- assert . equal ( await isDirectory ( './invalid.txt' ) , false ) ;
85
+ expect ( await isDirectory ( './invalid.txt' ) ) . toBeFalsy ( ) ;
92
86
} ) ;
93
87
} ) ;
94
88
95
89
describe ( 'isFile' , ( ) => {
96
90
it ( 'return true with file input' , async ( ) => {
97
- assert . equal ( await isFile ( './package.json' ) , true ) ;
91
+ expect ( await isFile ( './package.json' ) ) . toBeTruthy ( ) ;
98
92
} ) ;
99
93
it ( 'return false with directory input' , async ( ) => {
100
- assert . equal ( await isFile ( './' ) , false ) ;
94
+ expect ( await isFile ( './' ) ) . toBeFalsy ( ) ;
101
95
} ) ;
102
96
it ( 'return false with invalid input' , async ( ) => {
103
- assert . equal ( await isFile ( './invalid.txt' ) , false ) ;
97
+ expect ( await isFile ( './invalid.txt' ) ) . toBeFalsy ( ) ;
104
98
} ) ;
105
99
} ) ;
106
100
107
101
describe ( 'parseIgnoreConfig' , ( ) => {
108
102
it ( 'parse ignore config' , ( ) => {
109
- assert . deepEqual (
103
+ expect (
110
104
parseIgnoreConfig ( `**/*.test.*
111
105
./coverage/
112
- ./dist/` ) ,
113
- [ '!**/*.test.*' , '!./coverage/' , '!./dist/' ]
106
+ ./dist/` )
107
+ ) . toEqual (
108
+ expect . arrayContaining ( [
109
+ '!**/*.test.*' ,
110
+ '!./coverage/' ,
111
+ '!./dist/'
112
+ ] )
114
113
) ;
115
114
} ) ;
116
115
it ( 'parse ignore config with empty lines' , ( ) => {
117
- assert . deepEqual (
116
+ expect (
118
117
parseIgnoreConfig ( `**/*.test.*
119
118
120
119
./coverage/
121
120
122
- ./dist/` ) ,
123
- [ '!**/*.test.*' , '!./coverage/' , '!./dist/' ]
121
+ ./dist/` )
122
+ ) . toEqual (
123
+ expect . arrayContaining ( [
124
+ '!**/*.test.*' ,
125
+ '!./coverage/' ,
126
+ '!./dist/'
127
+ ] )
124
128
) ;
125
129
} ) ;
126
130
it ( 'parse ignore config with ! leading characters' , ( ) => {
127
- assert . deepEqual (
131
+ expect (
128
132
parseIgnoreConfig ( `!**/*.test.*
129
133
130
134
!./coverage/
131
135
132
- !./dist/` ) ,
133
- [ '!**/*.test.*' , '!./coverage/' , '!./dist/' ]
136
+ !./dist/` )
137
+ ) . toEqual (
138
+ expect . arrayContaining ( [
139
+ '!**/*.test.*' ,
140
+ '!./coverage/' ,
141
+ '!./dist/'
142
+ ] )
134
143
) ;
135
144
} ) ;
136
145
it ( 'parse ignore config with empty contents' , ( ) => {
137
- assert . deepEqual ( parseIgnoreConfig ( '' ) , [ ] ) ;
146
+ expect ( parseIgnoreConfig ( '' ) ) . toEqual ( [ ] ) ;
138
147
} ) ;
139
148
} ) ;
140
149
141
150
describe ( 'sanitizePath' , ( ) => {
142
151
it ( 'sanitize path' , ( ) => {
143
- assert . equal (
152
+ expect (
144
153
sanitizePath (
145
154
'file:///Users/scottdoxey/git/github/doxdox/packages/doxdox-cli/dist/src/index.js'
146
- ) ,
155
+ )
156
+ ) . toEqual (
147
157
'/Users/scottdoxey/git/github/doxdox/packages/doxdox-cli/dist/src/index.js'
148
158
) ;
149
159
} ) ;
150
160
} ) ;
151
161
152
162
describe ( 'slugify' , ( ) => {
153
163
it ( 'slugify path' , ( ) => {
154
- assert . equal ( slugify ( './src/utils.ts' ) , 'src-utils-ts' ) ;
164
+ expect ( slugify ( './src/utils.ts' ) ) . toEqual ( 'src-utils-ts' ) ;
155
165
} ) ;
156
166
} ) ;
157
167
} ) ;
0 commit comments