1
- import { existsSync , promises as fs } from ' node:fs' ;
2
- import path from ' node:path' ;
1
+ import { existsSync , promises as fs } from " node:fs" ;
2
+ import path from " node:path" ;
3
3
import {
4
4
createDependencyGraph ,
5
5
type DependencyGraph ,
6
- } from ' ./create-dependency-graph.js' ;
6
+ } from " ./create-dependency-graph.js" ;
7
7
8
8
const pathToFileForTestingDependencyGraph = path . join (
9
9
__dirname ,
10
- ' .for-dependency-graph.ts' ,
10
+ " .for-dependency-graph.ts" ,
11
11
) ;
12
12
13
- vi . mock ( ' @babel/traverse' , async ( ) => {
14
- const traverse = await vi . importActual ( ' @babel/traverse' ) ;
13
+ vi . mock ( " @babel/traverse" , async ( ) => {
14
+ const traverse = await vi . importActual ( " @babel/traverse" ) ;
15
15
return { default : traverse } ;
16
16
} ) ;
17
17
18
- test ( ' createDependencyGraph()' , async ( ) => {
18
+ test ( " createDependencyGraph()" , async ( ) => {
19
19
if ( existsSync ( pathToFileForTestingDependencyGraph ) ) {
20
20
await fs . rm ( pathToFileForTestingDependencyGraph ) ;
21
21
}
@@ -44,158 +44,163 @@ test('createDependencyGraph()', async () => {
44
44
} ;
45
45
46
46
const initialDependencyGraph = convertPathsToAbsolute ( {
47
- ' ../../../../package.json' : {
47
+ " ../../../../package.json" : {
48
48
dependencyPaths : [ ] ,
49
- dependentPaths : [ ' ../../packageJson.ts' ] ,
49
+ dependentPaths : [ " ../../packageJson.ts" ] ,
50
50
moduleDependencies : [ ] ,
51
- path : ' ../../../../package.json' ,
51
+ path : " ../../../../package.json" ,
52
52
} ,
53
- ' create-dependency-graph.ts' : {
54
- path : ' create-dependency-graph.ts' ,
53
+ " create-dependency-graph.ts" : {
54
+ path : " create-dependency-graph.ts" ,
55
55
dependencyPaths : [
56
- ' ../start-dev-server.ts' ,
57
- ' get-imported-modules.ts' ,
58
- ' resolve-path-aliases.ts' ,
56
+ " ../start-dev-server.ts" ,
57
+ " get-imported-modules.ts" ,
58
+ " resolve-path-aliases.ts" ,
59
59
] ,
60
60
dependentPaths : [
61
- ' create-dependency-graph.spec.ts' ,
62
- ' setup-hot-reloading.ts' ,
61
+ " create-dependency-graph.spec.ts" ,
62
+ " setup-hot-reloading.ts" ,
63
63
] ,
64
- moduleDependencies : [ ' node:fs' , ' node:path' , ' chokidar/handler.js' ] ,
64
+ moduleDependencies : [ " node:fs" , " node:path" , " chokidar/handler.js" ] ,
65
65
} ,
66
- '../../get-preview-server-location.ts' : {
67
- dependencyPaths : [ ] ,
68
- dependentPaths : [ '../../preview/start-dev-server.ts' ] ,
69
- moduleDependencies : [ 'node:path' , 'node:url' , 'jiti' , 'nypm' , 'prompts' ] ,
70
- path : '../../get-preview-server-location.ts' ,
66
+ "../../get-preview-server-location.ts" : {
67
+ dependencyPaths : [
68
+ "../../packageJson.ts" ,
69
+ ] ,
70
+ dependentPaths : [ "../../preview/start-dev-server.ts" ] ,
71
+ moduleDependencies : [ "node:path" , "node:url" , "jiti" , "nypm" , "prompts" ] ,
72
+ path : "../../get-preview-server-location.ts" ,
71
73
} ,
72
- '../../packageJson.ts' : {
73
- dependencyPaths : [ '../../../../package.json' ] ,
74
- dependentPaths : [ '../../preview/start-dev-server.ts' ] ,
74
+ "../../packageJson.ts" : {
75
+ dependencyPaths : [ "../../../../package.json" ] ,
76
+ dependentPaths : [
77
+ "../../get-preview-server-location.ts" ,
78
+ "../../preview/start-dev-server.ts" ,
79
+ ] ,
75
80
moduleDependencies : [ ] ,
76
- path : ' ../../packageJson.ts' ,
81
+ path : " ../../packageJson.ts" ,
77
82
} ,
78
- ' create-dependency-graph.spec.ts' : {
79
- path : ' create-dependency-graph.spec.ts' ,
80
- dependencyPaths : [ ' create-dependency-graph.ts' ] ,
83
+ " create-dependency-graph.spec.ts" : {
84
+ path : " create-dependency-graph.spec.ts" ,
85
+ dependencyPaths : [ " create-dependency-graph.ts" ] ,
81
86
dependentPaths : [ ] ,
82
- moduleDependencies : [ ' node:fs' , ' node:path' ] ,
87
+ moduleDependencies : [ " node:fs" , " node:path" ] ,
83
88
} ,
84
- ' ../get-env-variables-for-preview-app.ts' : {
85
- dependencyPaths : [ ' ../../preview/start-dev-server.ts' ] ,
86
- dependentPaths : [ ' ../../preview/start-dev-server.ts' ] ,
87
- moduleDependencies : [ ' node:path' ] ,
88
- path : ' ../../preview/get-env-variables-for-preview-app.ts' ,
89
+ " ../get-env-variables-for-preview-app.ts" : {
90
+ dependencyPaths : [ " ../../preview/start-dev-server.ts" ] ,
91
+ dependentPaths : [ " ../../preview/start-dev-server.ts" ] ,
92
+ moduleDependencies : [ " node:path" ] ,
93
+ path : " ../../preview/get-env-variables-for-preview-app.ts" ,
89
94
} ,
90
- ' ./test/some-file.ts' : {
95
+ " ./test/some-file.ts" : {
91
96
dependencyPaths : [ ] ,
92
97
dependentPaths : [ ] ,
93
98
moduleDependencies : [ ] ,
94
- path : ' /home/gabriel/Projects/Resend/react-email/packages/react-email/src/cli/utils/preview/hot-reloading/test/some-file.ts' ,
99
+ path : " /home/gabriel/Projects/Resend/react-email/packages/react-email/src/cli/utils/preview/hot-reloading/test/some-file.ts" ,
95
100
} ,
96
- ' resolve-path-aliases.ts' : {
97
- path : ' resolve-path-aliases.ts' ,
101
+ " resolve-path-aliases.ts" : {
102
+ path : " resolve-path-aliases.ts" ,
98
103
dependentPaths : [
99
- ' create-dependency-graph.ts' ,
100
- ' resolve-path-aliases.spec.ts' ,
104
+ " create-dependency-graph.ts" ,
105
+ " resolve-path-aliases.spec.ts" ,
101
106
] ,
102
107
dependencyPaths : [ ] ,
103
- moduleDependencies : [ ' node:path' , ' tsconfig-paths' ] ,
108
+ moduleDependencies : [ " node:path" , " tsconfig-paths" ] ,
104
109
} ,
105
- ' resolve-path-aliases.spec.ts' : {
106
- path : ' resolve-path-aliases.spec.ts' ,
107
- dependencyPaths : [ ' resolve-path-aliases.ts' ] ,
110
+ " resolve-path-aliases.spec.ts" : {
111
+ path : " resolve-path-aliases.spec.ts" ,
112
+ dependencyPaths : [ " resolve-path-aliases.ts" ] ,
108
113
dependentPaths : [ ] ,
109
- moduleDependencies : [ ' node:path' ] ,
114
+ moduleDependencies : [ " node:path" ] ,
110
115
} ,
111
- ' get-imported-modules.ts' : {
112
- path : ' get-imported-modules' ,
116
+ " get-imported-modules.ts" : {
117
+ path : " get-imported-modules" ,
113
118
dependentPaths : [
114
- ' create-dependency-graph.ts' ,
115
- ' get-imported-modules.spec.ts' ,
119
+ " create-dependency-graph.ts" ,
120
+ " get-imported-modules.spec.ts" ,
116
121
] ,
117
122
dependencyPaths : [ ] ,
118
- moduleDependencies : [ ' @babel/parser' , ' @babel/traverse' ] ,
123
+ moduleDependencies : [ " @babel/parser" , " @babel/traverse" ] ,
119
124
} ,
120
- ' get-imported-modules.spec.ts' : {
121
- path : ' get-imported-modules.spec.ts' ,
122
- dependencyPaths : [ ' get-imported-modules.ts' ] ,
125
+ " get-imported-modules.spec.ts" : {
126
+ path : " get-imported-modules.spec.ts" ,
127
+ dependencyPaths : [ " get-imported-modules.ts" ] ,
123
128
dependentPaths : [ ] ,
124
- moduleDependencies : [ ' node:fs' ] ,
129
+ moduleDependencies : [ " node:fs" ] ,
125
130
} ,
126
- ' setup-hot-reloading.ts' : {
127
- path : ' setup-hot-reloading.ts' ,
131
+ " setup-hot-reloading.ts" : {
132
+ path : " setup-hot-reloading.ts" ,
128
133
dependencyPaths : [
129
- ' ../../types/hot-reload-change.ts' ,
130
- ' create-dependency-graph.ts' ,
134
+ " ../../types/hot-reload-change.ts" ,
135
+ " create-dependency-graph.ts" ,
131
136
] ,
132
137
dependentPaths : [ ] ,
133
138
moduleDependencies : [
134
- ' node:http' ,
135
- ' node:path' ,
136
- ' chokidar' ,
137
- ' debounce' ,
138
- ' socket.io' ,
139
+ " node:http" ,
140
+ " node:path" ,
141
+ " chokidar" ,
142
+ " debounce" ,
143
+ " socket.io" ,
139
144
] ,
140
145
} ,
141
- ' ../start-dev-server.ts' : {
146
+ " ../start-dev-server.ts" : {
142
147
dependencyPaths : [
143
- ' ../../register-spinner-autostopping.ts' ,
144
- ' ../../get-preview-server-location.ts' ,
145
- ' ../../packageJson.ts' ,
146
- ' ../../preview/get-env-variables-for-preview-app.ts' ,
147
- ' ../../preview/serve-static-file.ts' ,
148
+ " ../../register-spinner-autostopping.ts" ,
149
+ " ../../get-preview-server-location.ts" ,
150
+ " ../../packageJson.ts" ,
151
+ " ../../preview/get-env-variables-for-preview-app.ts" ,
152
+ " ../../preview/serve-static-file.ts" ,
148
153
] ,
149
- path : ' ../start-dev-server.ts' ,
154
+ path : " ../start-dev-server.ts" ,
150
155
dependentPaths : [
151
- ' ../../preview/get-env-variables-for-preview-app.ts' ,
152
- ' create-dependency-graph.ts' ,
156
+ " ../../preview/get-env-variables-for-preview-app.ts" ,
157
+ " create-dependency-graph.ts" ,
153
158
] ,
154
159
moduleDependencies : [
155
- ' node:http' ,
156
- ' node:path' ,
157
- ' node:url' ,
158
- ' chalk' ,
159
- ' jiti' ,
160
- ' log-symbols' ,
161
- ' ora' ,
160
+ " node:http" ,
161
+ " node:path" ,
162
+ " node:url" ,
163
+ " chalk" ,
164
+ " jiti" ,
165
+ " log-symbols" ,
166
+ " ora" ,
162
167
] ,
163
168
} ,
164
- ' ../../preview/serve-static-file.ts' : {
169
+ " ../../preview/serve-static-file.ts" : {
165
170
dependencyPaths : [ ] ,
166
- dependentPaths : [ ' ../../preview/start-dev-server.ts' ] ,
171
+ dependentPaths : [ " ../../preview/start-dev-server.ts" ] ,
167
172
moduleDependencies : [
168
- ' node:fs' ,
169
- ' node:http' ,
170
- ' node:path' ,
171
- ' node:url' ,
172
- ' mime-types' ,
173
+ " node:fs" ,
174
+ " node:http" ,
175
+ " node:path" ,
176
+ " node:url" ,
177
+ " mime-types" ,
173
178
] ,
174
- path : ' ../../preview/serve-static-file.ts' ,
179
+ path : " ../../preview/serve-static-file.ts" ,
175
180
} ,
176
- ' ../../register-spinner-autostopping.ts' : {
181
+ " ../../register-spinner-autostopping.ts" : {
177
182
dependencyPaths : [ ] ,
178
- dependentPaths : [ ' ../../preview/start-dev-server.ts' ] ,
179
- moduleDependencies : [ ' log-symbols' , ' ora' ] ,
180
- path : ' ../../register-spinner-autostopping.ts' ,
183
+ dependentPaths : [ " ../../preview/start-dev-server.ts" ] ,
184
+ moduleDependencies : [ " log-symbols" , " ora" ] ,
185
+ path : " ../../register-spinner-autostopping.ts" ,
181
186
} ,
182
- ' ../../types/hot-reload-event.ts' : {
187
+ " ../../types/hot-reload-event.ts" : {
183
188
dependencyPaths : [ ] ,
184
- dependentPaths : [ ' ../../types/hot-reload-change.ts' ] ,
185
- moduleDependencies : [ ' chokidar/handler.js' ] ,
186
- path : ' ../../types/hot-reload-event.ts' ,
189
+ dependentPaths : [ " ../../types/hot-reload-change.ts" ] ,
190
+ moduleDependencies : [ " chokidar/handler.js" ] ,
191
+ path : " ../../types/hot-reload-event.ts" ,
187
192
} ,
188
- ' ../../types/hot-reload-change.ts' : {
189
- path : ' ../../types/hot-reload-change.ts' ,
190
- dependencyPaths : [ ' ../../types/hot-reload-event.ts' ] ,
191
- dependentPaths : [ ' setup-hot-reloading.ts' ] ,
193
+ " ../../types/hot-reload-change.ts" : {
194
+ path : " ../../types/hot-reload-change.ts" ,
195
+ dependencyPaths : [ " ../../types/hot-reload-event.ts" ] ,
196
+ dependentPaths : [ " setup-hot-reloading.ts" ] ,
192
197
moduleDependencies : [ ] ,
193
198
} ,
194
199
} satisfies DependencyGraph ) ;
195
200
196
201
expect (
197
202
dependencyGraph ,
198
- ' the initial value for the dependency graph should work with the directory of this testing file' ,
203
+ " the initial value for the dependency graph should work with the directory of this testing file" ,
199
204
) . toEqual ( initialDependencyGraph ) ;
200
205
201
206
await fs . writeFile (
@@ -205,30 +210,30 @@ import {} from './setup-hot-reloading';
205
210
import {} from './get-imported-modules';
206
211
import {} from './create-dependency-graph.ts';
207
212
` ,
208
- ' utf8' ,
213
+ " utf8" ,
209
214
) ;
210
- await updateDependencyGraph ( ' add' , pathToFileForTestingDependencyGraph ) ;
215
+ await updateDependencyGraph ( " add" , pathToFileForTestingDependencyGraph ) ;
211
216
expect (
212
217
dependencyGraph [ pathToFileForTestingDependencyGraph ] ,
213
- ' added file to have proper dependency paths' ,
218
+ " added file to have proper dependency paths" ,
214
219
) . toEqual ( {
215
220
path : pathToFileForTestingDependencyGraph ,
216
221
dependentPaths : [ ] ,
217
222
dependencyPaths : [
218
- toAbsolute ( ' setup-hot-reloading.ts' ) ,
219
- toAbsolute ( ' get-imported-modules.ts' ) ,
220
- toAbsolute ( ' create-dependency-graph.ts' ) ,
223
+ toAbsolute ( " setup-hot-reloading.ts" ) ,
224
+ toAbsolute ( " get-imported-modules.ts" ) ,
225
+ toAbsolute ( " create-dependency-graph.ts" ) ,
221
226
] ,
222
227
moduleDependencies : [ ] ,
223
228
} satisfies DependencyGraph [ number ] ) ;
224
229
expect (
225
- dependencyGraph [ toAbsolute ( ' setup-hot-reloading.ts' ) ] ?. dependentPaths ,
230
+ dependencyGraph [ toAbsolute ( " setup-hot-reloading.ts" ) ] ?. dependentPaths ,
226
231
) . toContain ( pathToFileForTestingDependencyGraph ) ;
227
232
expect (
228
- dependencyGraph [ toAbsolute ( ' get-imported-modules.ts' ) ] ?. dependentPaths ,
233
+ dependencyGraph [ toAbsolute ( " get-imported-modules.ts" ) ] ?. dependentPaths ,
229
234
) . toContain ( pathToFileForTestingDependencyGraph ) ;
230
235
expect (
231
- dependencyGraph [ toAbsolute ( ' create-dependency-graph.ts' ) ] ?. dependentPaths ,
236
+ dependencyGraph [ toAbsolute ( " create-dependency-graph.ts" ) ] ?. dependentPaths ,
232
237
) . toContain ( pathToFileForTestingDependencyGraph ) ;
233
238
234
239
await fs . writeFile (
@@ -237,45 +242,45 @@ import {} from './create-dependency-graph.ts';
237
242
import {} from './setup-hot-reloading';
238
243
import {} from './create-dependency-graph.ts';
239
244
` ,
240
- ' utf8' ,
245
+ " utf8" ,
241
246
) ;
242
- await updateDependencyGraph ( ' change' , pathToFileForTestingDependencyGraph ) ;
247
+ await updateDependencyGraph ( " change" , pathToFileForTestingDependencyGraph ) ;
243
248
expect (
244
249
dependencyGraph [ pathToFileForTestingDependencyGraph ] ,
245
- ' changed file to have updated dependencyPaths' ,
250
+ " changed file to have updated dependencyPaths" ,
246
251
) . toEqual ( {
247
252
path : pathToFileForTestingDependencyGraph ,
248
253
dependentPaths : [ ] ,
249
254
dependencyPaths : [
250
- toAbsolute ( ' setup-hot-reloading.ts' ) ,
251
- toAbsolute ( ' create-dependency-graph.ts' ) ,
255
+ toAbsolute ( " setup-hot-reloading.ts" ) ,
256
+ toAbsolute ( " create-dependency-graph.ts" ) ,
252
257
] ,
253
258
moduleDependencies : [ ] ,
254
259
} satisfies DependencyGraph [ number ] ) ;
255
260
expect (
256
- dependencyGraph [ toAbsolute ( ' setup-hot-reloading.ts' ) ] ?. dependentPaths ,
261
+ dependencyGraph [ toAbsolute ( " setup-hot-reloading.ts" ) ] ?. dependentPaths ,
257
262
) . toContain ( pathToFileForTestingDependencyGraph ) ;
258
263
expect (
259
- dependencyGraph [ toAbsolute ( ' get-imported-modules.ts' ) ] ?. dependentPaths ,
260
- ' when removing dependency on a file, the dependency should have its dependents updated to not have the testing file again' ,
264
+ dependencyGraph [ toAbsolute ( " get-imported-modules.ts" ) ] ?. dependentPaths ,
265
+ " when removing dependency on a file, the dependency should have its dependents updated to not have the testing file again" ,
261
266
) . not . toContain ( pathToFileForTestingDependencyGraph ) ;
262
267
expect (
263
- dependencyGraph [ toAbsolute ( ' create-dependency-graph.ts' ) ] ?. dependentPaths ,
268
+ dependencyGraph [ toAbsolute ( " create-dependency-graph.ts" ) ] ?. dependentPaths ,
264
269
) . toContain ( pathToFileForTestingDependencyGraph ) ;
265
270
266
271
await fs . rm ( pathToFileForTestingDependencyGraph ) ;
267
- await updateDependencyGraph ( ' unlink' , pathToFileForTestingDependencyGraph ) ;
272
+ await updateDependencyGraph ( " unlink" , pathToFileForTestingDependencyGraph ) ;
268
273
expect ( dependencyGraph [ pathToFileForTestingDependencyGraph ] ) . toBeUndefined ( ) ;
269
274
expect (
270
- dependencyGraph [ toAbsolute ( ' setup-hot-reloading.ts' ) ] ?. dependentPaths ,
275
+ dependencyGraph [ toAbsolute ( " setup-hot-reloading.ts" ) ] ?. dependentPaths ,
271
276
"should remove itself from dependents once it's unlinked" ,
272
277
) . not . toContain ( pathToFileForTestingDependencyGraph ) ;
273
278
expect (
274
- dependencyGraph [ toAbsolute ( ' get-imported-modules.ts' ) ] ?. dependentPaths ,
279
+ dependencyGraph [ toAbsolute ( " get-imported-modules.ts" ) ] ?. dependentPaths ,
275
280
"should remove itself from dependents once it's unlinked" ,
276
281
) . not . toContain ( pathToFileForTestingDependencyGraph ) ;
277
282
expect (
278
- dependencyGraph [ toAbsolute ( ' create-dependency-graph.ts' ) ] ?. dependentPaths ,
283
+ dependencyGraph [ toAbsolute ( " create-dependency-graph.ts" ) ] ?. dependentPaths ,
279
284
"should remove itself from dependents once it's unlinked" ,
280
285
) . not . toContain ( pathToFileForTestingDependencyGraph ) ;
281
286
} ) ;
0 commit comments