Skip to content

Commit f3069df

Browse files
committed
fix(react-email): testing data
1 parent c6a61d4 commit f3069df

File tree

1 file changed

+129
-124
lines changed

1 file changed

+129
-124
lines changed
Lines changed: 129 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
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";
33
import {
44
createDependencyGraph,
55
type DependencyGraph,
6-
} from './create-dependency-graph.js';
6+
} from "./create-dependency-graph.js";
77

88
const pathToFileForTestingDependencyGraph = path.join(
99
__dirname,
10-
'.for-dependency-graph.ts',
10+
".for-dependency-graph.ts",
1111
);
1212

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");
1515
return { default: traverse };
1616
});
1717

18-
test('createDependencyGraph()', async () => {
18+
test("createDependencyGraph()", async () => {
1919
if (existsSync(pathToFileForTestingDependencyGraph)) {
2020
await fs.rm(pathToFileForTestingDependencyGraph);
2121
}
@@ -44,158 +44,163 @@ test('createDependencyGraph()', async () => {
4444
};
4545

4646
const initialDependencyGraph = convertPathsToAbsolute({
47-
'../../../../package.json': {
47+
"../../../../package.json": {
4848
dependencyPaths: [],
49-
dependentPaths: ['../../packageJson.ts'],
49+
dependentPaths: ["../../packageJson.ts"],
5050
moduleDependencies: [],
51-
path: '../../../../package.json',
51+
path: "../../../../package.json",
5252
},
53-
'create-dependency-graph.ts': {
54-
path: 'create-dependency-graph.ts',
53+
"create-dependency-graph.ts": {
54+
path: "create-dependency-graph.ts",
5555
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",
5959
],
6060
dependentPaths: [
61-
'create-dependency-graph.spec.ts',
62-
'setup-hot-reloading.ts',
61+
"create-dependency-graph.spec.ts",
62+
"setup-hot-reloading.ts",
6363
],
64-
moduleDependencies: ['node:fs', 'node:path', 'chokidar/handler.js'],
64+
moduleDependencies: ["node:fs", "node:path", "chokidar/handler.js"],
6565
},
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",
7173
},
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+
],
7580
moduleDependencies: [],
76-
path: '../../packageJson.ts',
81+
path: "../../packageJson.ts",
7782
},
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"],
8186
dependentPaths: [],
82-
moduleDependencies: ['node:fs', 'node:path'],
87+
moduleDependencies: ["node:fs", "node:path"],
8388
},
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",
8994
},
90-
'./test/some-file.ts': {
95+
"./test/some-file.ts": {
9196
dependencyPaths: [],
9297
dependentPaths: [],
9398
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",
95100
},
96-
'resolve-path-aliases.ts': {
97-
path: 'resolve-path-aliases.ts',
101+
"resolve-path-aliases.ts": {
102+
path: "resolve-path-aliases.ts",
98103
dependentPaths: [
99-
'create-dependency-graph.ts',
100-
'resolve-path-aliases.spec.ts',
104+
"create-dependency-graph.ts",
105+
"resolve-path-aliases.spec.ts",
101106
],
102107
dependencyPaths: [],
103-
moduleDependencies: ['node:path', 'tsconfig-paths'],
108+
moduleDependencies: ["node:path", "tsconfig-paths"],
104109
},
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"],
108113
dependentPaths: [],
109-
moduleDependencies: ['node:path'],
114+
moduleDependencies: ["node:path"],
110115
},
111-
'get-imported-modules.ts': {
112-
path: 'get-imported-modules',
116+
"get-imported-modules.ts": {
117+
path: "get-imported-modules",
113118
dependentPaths: [
114-
'create-dependency-graph.ts',
115-
'get-imported-modules.spec.ts',
119+
"create-dependency-graph.ts",
120+
"get-imported-modules.spec.ts",
116121
],
117122
dependencyPaths: [],
118-
moduleDependencies: ['@babel/parser', '@babel/traverse'],
123+
moduleDependencies: ["@babel/parser", "@babel/traverse"],
119124
},
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"],
123128
dependentPaths: [],
124-
moduleDependencies: ['node:fs'],
129+
moduleDependencies: ["node:fs"],
125130
},
126-
'setup-hot-reloading.ts': {
127-
path: 'setup-hot-reloading.ts',
131+
"setup-hot-reloading.ts": {
132+
path: "setup-hot-reloading.ts",
128133
dependencyPaths: [
129-
'../../types/hot-reload-change.ts',
130-
'create-dependency-graph.ts',
134+
"../../types/hot-reload-change.ts",
135+
"create-dependency-graph.ts",
131136
],
132137
dependentPaths: [],
133138
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",
139144
],
140145
},
141-
'../start-dev-server.ts': {
146+
"../start-dev-server.ts": {
142147
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",
148153
],
149-
path: '../start-dev-server.ts',
154+
path: "../start-dev-server.ts",
150155
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",
153158
],
154159
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",
162167
],
163168
},
164-
'../../preview/serve-static-file.ts': {
169+
"../../preview/serve-static-file.ts": {
165170
dependencyPaths: [],
166-
dependentPaths: ['../../preview/start-dev-server.ts'],
171+
dependentPaths: ["../../preview/start-dev-server.ts"],
167172
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",
173178
],
174-
path: '../../preview/serve-static-file.ts',
179+
path: "../../preview/serve-static-file.ts",
175180
},
176-
'../../register-spinner-autostopping.ts': {
181+
"../../register-spinner-autostopping.ts": {
177182
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",
181186
},
182-
'../../types/hot-reload-event.ts': {
187+
"../../types/hot-reload-event.ts": {
183188
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",
187192
},
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"],
192197
moduleDependencies: [],
193198
},
194199
} satisfies DependencyGraph);
195200

196201
expect(
197202
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",
199204
).toEqual(initialDependencyGraph);
200205

201206
await fs.writeFile(
@@ -205,30 +210,30 @@ import {} from './setup-hot-reloading';
205210
import {} from './get-imported-modules';
206211
import {} from './create-dependency-graph.ts';
207212
`,
208-
'utf8',
213+
"utf8",
209214
);
210-
await updateDependencyGraph('add', pathToFileForTestingDependencyGraph);
215+
await updateDependencyGraph("add", pathToFileForTestingDependencyGraph);
211216
expect(
212217
dependencyGraph[pathToFileForTestingDependencyGraph],
213-
'added file to have proper dependency paths',
218+
"added file to have proper dependency paths",
214219
).toEqual({
215220
path: pathToFileForTestingDependencyGraph,
216221
dependentPaths: [],
217222
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"),
221226
],
222227
moduleDependencies: [],
223228
} satisfies DependencyGraph[number]);
224229
expect(
225-
dependencyGraph[toAbsolute('setup-hot-reloading.ts')]?.dependentPaths,
230+
dependencyGraph[toAbsolute("setup-hot-reloading.ts")]?.dependentPaths,
226231
).toContain(pathToFileForTestingDependencyGraph);
227232
expect(
228-
dependencyGraph[toAbsolute('get-imported-modules.ts')]?.dependentPaths,
233+
dependencyGraph[toAbsolute("get-imported-modules.ts")]?.dependentPaths,
229234
).toContain(pathToFileForTestingDependencyGraph);
230235
expect(
231-
dependencyGraph[toAbsolute('create-dependency-graph.ts')]?.dependentPaths,
236+
dependencyGraph[toAbsolute("create-dependency-graph.ts")]?.dependentPaths,
232237
).toContain(pathToFileForTestingDependencyGraph);
233238

234239
await fs.writeFile(
@@ -237,45 +242,45 @@ import {} from './create-dependency-graph.ts';
237242
import {} from './setup-hot-reloading';
238243
import {} from './create-dependency-graph.ts';
239244
`,
240-
'utf8',
245+
"utf8",
241246
);
242-
await updateDependencyGraph('change', pathToFileForTestingDependencyGraph);
247+
await updateDependencyGraph("change", pathToFileForTestingDependencyGraph);
243248
expect(
244249
dependencyGraph[pathToFileForTestingDependencyGraph],
245-
'changed file to have updated dependencyPaths',
250+
"changed file to have updated dependencyPaths",
246251
).toEqual({
247252
path: pathToFileForTestingDependencyGraph,
248253
dependentPaths: [],
249254
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"),
252257
],
253258
moduleDependencies: [],
254259
} satisfies DependencyGraph[number]);
255260
expect(
256-
dependencyGraph[toAbsolute('setup-hot-reloading.ts')]?.dependentPaths,
261+
dependencyGraph[toAbsolute("setup-hot-reloading.ts")]?.dependentPaths,
257262
).toContain(pathToFileForTestingDependencyGraph);
258263
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",
261266
).not.toContain(pathToFileForTestingDependencyGraph);
262267
expect(
263-
dependencyGraph[toAbsolute('create-dependency-graph.ts')]?.dependentPaths,
268+
dependencyGraph[toAbsolute("create-dependency-graph.ts")]?.dependentPaths,
264269
).toContain(pathToFileForTestingDependencyGraph);
265270

266271
await fs.rm(pathToFileForTestingDependencyGraph);
267-
await updateDependencyGraph('unlink', pathToFileForTestingDependencyGraph);
272+
await updateDependencyGraph("unlink", pathToFileForTestingDependencyGraph);
268273
expect(dependencyGraph[pathToFileForTestingDependencyGraph]).toBeUndefined();
269274
expect(
270-
dependencyGraph[toAbsolute('setup-hot-reloading.ts')]?.dependentPaths,
275+
dependencyGraph[toAbsolute("setup-hot-reloading.ts")]?.dependentPaths,
271276
"should remove itself from dependents once it's unlinked",
272277
).not.toContain(pathToFileForTestingDependencyGraph);
273278
expect(
274-
dependencyGraph[toAbsolute('get-imported-modules.ts')]?.dependentPaths,
279+
dependencyGraph[toAbsolute("get-imported-modules.ts")]?.dependentPaths,
275280
"should remove itself from dependents once it's unlinked",
276281
).not.toContain(pathToFileForTestingDependencyGraph);
277282
expect(
278-
dependencyGraph[toAbsolute('create-dependency-graph.ts')]?.dependentPaths,
283+
dependencyGraph[toAbsolute("create-dependency-graph.ts")]?.dependentPaths,
279284
"should remove itself from dependents once it's unlinked",
280285
).not.toContain(pathToFileForTestingDependencyGraph);
281286
});

0 commit comments

Comments
 (0)