@apollo/client-ai-apps 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.git-blame-ignore-revs +2 -0
- package/.github/workflows/pr.yaml +23 -15
- package/.github/workflows/release.yaml +46 -46
- package/.prettierrc +9 -0
- package/dist/apollo_client/client.d.ts +1 -2
- package/dist/apollo_client/link/ToolCallLink.d.ts +26 -0
- package/dist/hooks/useToolEffect.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +75 -25
- package/dist/vite/absolute_asset_imports_plugin.d.ts +4 -0
- package/dist/vite/index.d.ts +1 -0
- package/dist/vite/index.js +90 -25
- package/package.json +5 -2
- package/scripts/dev.mjs +3 -1
- package/src/apollo_client/client.test.ts +226 -13
- package/src/apollo_client/client.ts +44 -30
- package/src/apollo_client/link/ToolCallLink.ts +49 -0
- package/src/apollo_client/provider.tsx +8 -2
- package/src/hooks/useCallTool.ts +8 -3
- package/src/hooks/useOpenAiGlobal.test.ts +3 -1
- package/src/hooks/useOpenAiGlobal.ts +8 -2
- package/src/hooks/useSendFollowUpMessage.test.ts +3 -1
- package/src/hooks/useToolEffect.test.tsx +25 -9
- package/src/hooks/useToolEffect.tsx +24 -5
- package/src/index.ts +1 -0
- package/src/types/openai.ts +5 -2
- package/src/vite/absolute_asset_imports_plugin.test.ts +102 -0
- package/src/vite/absolute_asset_imports_plugin.ts +22 -0
- package/src/vite/application_manifest_plugin.test.ts +195 -72
- package/src/vite/application_manifest_plugin.ts +88 -28
- package/src/vite/index.ts +1 -0
|
@@ -4,6 +4,8 @@ import fs from "fs";
|
|
|
4
4
|
import * as glob from "glob";
|
|
5
5
|
import path from "path";
|
|
6
6
|
|
|
7
|
+
const root = process.cwd();
|
|
8
|
+
|
|
7
9
|
vi.mock(import("fs"), async (importOriginal) => {
|
|
8
10
|
const actual = await importOriginal();
|
|
9
11
|
return {
|
|
@@ -21,7 +23,9 @@ vi.mock(import("path"), async (importOriginal) => {
|
|
|
21
23
|
return {
|
|
22
24
|
default: {
|
|
23
25
|
...actual.default,
|
|
24
|
-
resolve: vi.fn()
|
|
26
|
+
resolve: vi.fn((...args) =>
|
|
27
|
+
args.map((a, i) => (i === 0 ? a : a.replace(/^\//, ""))).join("/")
|
|
28
|
+
),
|
|
25
29
|
dirname: vi.fn(),
|
|
26
30
|
},
|
|
27
31
|
};
|
|
@@ -43,7 +47,7 @@ describe("buildStart", () => {
|
|
|
43
47
|
vi.spyOn(fs, "readFileSync").mockImplementation((path) => {
|
|
44
48
|
if (path === "package.json") {
|
|
45
49
|
return JSON.stringify({});
|
|
46
|
-
} else if (path === "my-component.tsx") {
|
|
50
|
+
} else if (path === root + "/my-component.tsx") {
|
|
47
51
|
return `
|
|
48
52
|
const MY_QUERY = gql\`query HelloWorldQuery($name: string!) @tool(name: "hello-world", description: "This is an awesome tool!", extraInputs: [{
|
|
49
53
|
name: "doStuff",
|
|
@@ -53,12 +57,17 @@ describe("buildStart", () => {
|
|
|
53
57
|
`;
|
|
54
58
|
}
|
|
55
59
|
});
|
|
56
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
57
|
-
|
|
60
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
61
|
+
Promise.resolve(["my-component.tsx"])
|
|
62
|
+
);
|
|
58
63
|
vi.spyOn(fs, "writeFileSync");
|
|
59
64
|
|
|
60
65
|
const plugin = ApplicationManifestPlugin();
|
|
61
|
-
plugin.configResolved({
|
|
66
|
+
plugin.configResolved({
|
|
67
|
+
command: "serve",
|
|
68
|
+
server: {},
|
|
69
|
+
build: { outDir: "/dist" },
|
|
70
|
+
});
|
|
62
71
|
await plugin.buildStart();
|
|
63
72
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
64
73
|
|
|
@@ -66,8 +75,8 @@ describe("buildStart", () => {
|
|
|
66
75
|
let contentObj = JSON.parse(content);
|
|
67
76
|
contentObj.hash = "abc";
|
|
68
77
|
|
|
69
|
-
expect(fs.writeFileSync).
|
|
70
|
-
expect(file).toBe("
|
|
78
|
+
expect(fs.writeFileSync).toHaveBeenCalledTimes(2);
|
|
79
|
+
expect(file).toBe(root + "/dist/.application-manifest.json");
|
|
71
80
|
expect(contentObj).toMatchInlineSnapshot(`
|
|
72
81
|
{
|
|
73
82
|
"csp": {
|
|
@@ -119,7 +128,9 @@ describe("buildStart", () => {
|
|
|
119
128
|
`;
|
|
120
129
|
}
|
|
121
130
|
});
|
|
122
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
131
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
132
|
+
Promise.resolve(["my-component.tsx"])
|
|
133
|
+
);
|
|
123
134
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
124
135
|
vi.spyOn(fs, "writeFileSync");
|
|
125
136
|
|
|
@@ -134,18 +145,23 @@ describe("buildStart", () => {
|
|
|
134
145
|
vi.spyOn(fs, "readFileSync").mockImplementation((path) => {
|
|
135
146
|
if (path === "package.json") {
|
|
136
147
|
return JSON.stringify({});
|
|
137
|
-
} else if (path === "my-component.tsx") {
|
|
148
|
+
} else if (path === root + "/my-component.tsx") {
|
|
138
149
|
return `
|
|
139
150
|
const MY_QUERY = \`query HelloWorldQuery @tool(name: "hello-world", description: "This is an awesome tool!") { helloWorld }\`;
|
|
140
151
|
`;
|
|
141
152
|
}
|
|
142
153
|
});
|
|
143
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
144
|
-
|
|
154
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
155
|
+
Promise.resolve(["my-component.tsx"])
|
|
156
|
+
);
|
|
145
157
|
vi.spyOn(fs, "writeFileSync");
|
|
146
158
|
|
|
147
159
|
const plugin = ApplicationManifestPlugin();
|
|
148
|
-
plugin.configResolved({
|
|
160
|
+
plugin.configResolved({
|
|
161
|
+
command: "serve",
|
|
162
|
+
server: {},
|
|
163
|
+
build: { outDir: "/dist" },
|
|
164
|
+
});
|
|
149
165
|
await plugin.buildStart();
|
|
150
166
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
151
167
|
|
|
@@ -153,8 +169,8 @@ describe("buildStart", () => {
|
|
|
153
169
|
let contentObj = JSON.parse(content);
|
|
154
170
|
contentObj.hash = "abc";
|
|
155
171
|
|
|
156
|
-
expect(fs.writeFileSync).
|
|
157
|
-
expect(file).toBe("
|
|
172
|
+
expect(fs.writeFileSync).toHaveBeenCalledTimes(2);
|
|
173
|
+
expect(file).toBe(root + "/dist/.application-manifest.json");
|
|
158
174
|
expect(contentObj).toMatchInlineSnapshot(`
|
|
159
175
|
{
|
|
160
176
|
"csp": {
|
|
@@ -174,18 +190,23 @@ describe("buildStart", () => {
|
|
|
174
190
|
vi.spyOn(fs, "readFileSync").mockImplementation((path) => {
|
|
175
191
|
if (path === "package.json") {
|
|
176
192
|
return JSON.stringify({});
|
|
177
|
-
} else if (path === "my-component.tsx") {
|
|
193
|
+
} else if (path === root + "/my-component.tsx") {
|
|
178
194
|
return `
|
|
179
195
|
const MY_QUERY = gql\`query HelloWorldQuery { helloWorld }\`;
|
|
180
196
|
`;
|
|
181
197
|
}
|
|
182
198
|
});
|
|
183
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
184
|
-
|
|
199
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
200
|
+
Promise.resolve(["my-component.tsx"])
|
|
201
|
+
);
|
|
185
202
|
vi.spyOn(fs, "writeFileSync");
|
|
186
203
|
|
|
187
204
|
const plugin = ApplicationManifestPlugin();
|
|
188
|
-
plugin.configResolved({
|
|
205
|
+
plugin.configResolved({
|
|
206
|
+
command: "serve",
|
|
207
|
+
server: {},
|
|
208
|
+
build: { outDir: "/dist" },
|
|
209
|
+
});
|
|
189
210
|
await plugin.buildStart();
|
|
190
211
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
191
212
|
|
|
@@ -193,8 +214,8 @@ describe("buildStart", () => {
|
|
|
193
214
|
let contentObj = JSON.parse(content);
|
|
194
215
|
contentObj.hash = "abc";
|
|
195
216
|
|
|
196
|
-
expect(fs.writeFileSync).
|
|
197
|
-
expect(file).toBe("
|
|
217
|
+
expect(fs.writeFileSync).toHaveBeenCalledTimes(2);
|
|
218
|
+
expect(file).toBe(root + "/dist/.application-manifest.json");
|
|
198
219
|
expect(contentObj).toMatchInlineSnapshot(`
|
|
199
220
|
{
|
|
200
221
|
"csp": {
|
|
@@ -226,18 +247,23 @@ describe("buildStart", () => {
|
|
|
226
247
|
vi.spyOn(fs, "readFileSync").mockImplementation((path) => {
|
|
227
248
|
if (path === "package.json") {
|
|
228
249
|
return JSON.stringify({});
|
|
229
|
-
} else if (path === "my-component.tsx") {
|
|
250
|
+
} else if (path === root + "/my-component.tsx") {
|
|
230
251
|
return `
|
|
231
252
|
const MY_QUERY = gql\`query HelloWorldQuery @prefetch { helloWorld }\`;
|
|
232
253
|
`;
|
|
233
254
|
}
|
|
234
255
|
});
|
|
235
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
236
|
-
|
|
256
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
257
|
+
Promise.resolve(["my-component.tsx"])
|
|
258
|
+
);
|
|
237
259
|
vi.spyOn(fs, "writeFileSync");
|
|
238
260
|
|
|
239
261
|
const plugin = ApplicationManifestPlugin();
|
|
240
|
-
plugin.configResolved({
|
|
262
|
+
plugin.configResolved({
|
|
263
|
+
command: "serve",
|
|
264
|
+
server: {},
|
|
265
|
+
build: { outDir: "/dist" },
|
|
266
|
+
});
|
|
241
267
|
await plugin.buildStart();
|
|
242
268
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
243
269
|
|
|
@@ -245,8 +271,8 @@ describe("buildStart", () => {
|
|
|
245
271
|
let contentObj = JSON.parse(content);
|
|
246
272
|
contentObj.hash = "abc";
|
|
247
273
|
|
|
248
|
-
expect(fs.writeFileSync).
|
|
249
|
-
expect(file).toBe("
|
|
274
|
+
expect(fs.writeFileSync).toHaveBeenCalledTimes(2);
|
|
275
|
+
expect(file).toBe(root + "/dist/.application-manifest.json");
|
|
250
276
|
expect(contentObj).toMatchInlineSnapshot(`
|
|
251
277
|
{
|
|
252
278
|
"csp": {
|
|
@@ -286,13 +312,17 @@ describe("buildStart", () => {
|
|
|
286
312
|
`;
|
|
287
313
|
}
|
|
288
314
|
});
|
|
289
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
315
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
316
|
+
Promise.resolve(["my-component.tsx"])
|
|
317
|
+
);
|
|
290
318
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
291
319
|
vi.spyOn(fs, "writeFileSync");
|
|
292
320
|
|
|
293
321
|
const plugin = ApplicationManifestPlugin();
|
|
294
322
|
plugin.configResolved({ command: "serve", server: {} });
|
|
295
|
-
await expect(
|
|
323
|
+
await expect(
|
|
324
|
+
async () => await plugin.buildStart()
|
|
325
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
296
326
|
`[Error: Found multiple operations marked as \`@prefetch\`. You can only mark 1 operation with \`@prefetch\`.]`
|
|
297
327
|
);
|
|
298
328
|
});
|
|
@@ -301,18 +331,23 @@ describe("buildStart", () => {
|
|
|
301
331
|
vi.spyOn(fs, "readFileSync").mockImplementation((path) => {
|
|
302
332
|
if (path === "package.json") {
|
|
303
333
|
return JSON.stringify({});
|
|
304
|
-
} else if (path === "my-component.tsx") {
|
|
334
|
+
} else if (path === root + "/my-component.tsx") {
|
|
305
335
|
return `
|
|
306
336
|
const MY_QUERY = gql\`mutation HelloWorldQuery @tool(name: "hello-world", description: "This is an awesome tool!") { helloWorld }\`;
|
|
307
337
|
`;
|
|
308
338
|
}
|
|
309
339
|
});
|
|
310
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
311
|
-
|
|
340
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
341
|
+
Promise.resolve(["my-component.tsx"])
|
|
342
|
+
);
|
|
312
343
|
vi.spyOn(fs, "writeFileSync");
|
|
313
344
|
|
|
314
345
|
const plugin = ApplicationManifestPlugin();
|
|
315
|
-
plugin.configResolved({
|
|
346
|
+
plugin.configResolved({
|
|
347
|
+
command: "serve",
|
|
348
|
+
server: {},
|
|
349
|
+
build: { outDir: "/dist" },
|
|
350
|
+
});
|
|
316
351
|
await plugin.buildStart();
|
|
317
352
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
318
353
|
|
|
@@ -320,8 +355,8 @@ describe("buildStart", () => {
|
|
|
320
355
|
let contentObj = JSON.parse(content);
|
|
321
356
|
contentObj.hash = "abc";
|
|
322
357
|
|
|
323
|
-
expect(fs.writeFileSync).
|
|
324
|
-
expect(file).toBe("
|
|
358
|
+
expect(fs.writeFileSync).toHaveBeenCalledTimes(2);
|
|
359
|
+
expect(file).toBe(root + "/dist/.application-manifest.json");
|
|
325
360
|
expect(contentObj).toMatchInlineSnapshot(`
|
|
326
361
|
{
|
|
327
362
|
"csp": {
|
|
@@ -364,14 +399,18 @@ describe("buildStart", () => {
|
|
|
364
399
|
`;
|
|
365
400
|
}
|
|
366
401
|
});
|
|
367
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
402
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
403
|
+
Promise.resolve(["my-component.tsx"])
|
|
404
|
+
);
|
|
368
405
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
369
406
|
vi.spyOn(fs, "writeFileSync");
|
|
370
407
|
|
|
371
408
|
const plugin = ApplicationManifestPlugin();
|
|
372
409
|
plugin.configResolved({ command: "serve", server: {} });
|
|
373
410
|
|
|
374
|
-
await expect(
|
|
411
|
+
await expect(
|
|
412
|
+
async () => await plugin.buildStart()
|
|
413
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
375
414
|
`[Error: Found an unsupported operation type. Only Query and Mutation are supported.]`
|
|
376
415
|
);
|
|
377
416
|
});
|
|
@@ -390,12 +429,19 @@ describe("buildStart", () => {
|
|
|
390
429
|
`;
|
|
391
430
|
}
|
|
392
431
|
});
|
|
393
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
432
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
433
|
+
Promise.resolve(["my-component.tsx"])
|
|
434
|
+
);
|
|
394
435
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
395
436
|
vi.spyOn(fs, "writeFileSync");
|
|
396
437
|
|
|
397
438
|
const plugin = ApplicationManifestPlugin();
|
|
398
|
-
plugin.configResolved({
|
|
439
|
+
plugin.configResolved({
|
|
440
|
+
command: "serve",
|
|
441
|
+
mode: "staging",
|
|
442
|
+
server: {},
|
|
443
|
+
build: { outDir: "/dist" },
|
|
444
|
+
});
|
|
399
445
|
await plugin.buildStart();
|
|
400
446
|
|
|
401
447
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
@@ -414,12 +460,18 @@ describe("buildStart", () => {
|
|
|
414
460
|
`;
|
|
415
461
|
}
|
|
416
462
|
});
|
|
417
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
463
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
464
|
+
Promise.resolve(["my-component.tsx"])
|
|
465
|
+
);
|
|
418
466
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
419
467
|
vi.spyOn(fs, "writeFileSync");
|
|
420
468
|
|
|
421
469
|
const plugin = ApplicationManifestPlugin();
|
|
422
|
-
plugin.configResolved({
|
|
470
|
+
plugin.configResolved({
|
|
471
|
+
command: "serve",
|
|
472
|
+
server: { https: {}, port: "5678" },
|
|
473
|
+
build: { outDir: "/dist" },
|
|
474
|
+
});
|
|
423
475
|
await plugin.buildStart();
|
|
424
476
|
|
|
425
477
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
@@ -438,12 +490,18 @@ describe("buildStart", () => {
|
|
|
438
490
|
`;
|
|
439
491
|
}
|
|
440
492
|
});
|
|
441
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
493
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
494
|
+
Promise.resolve(["my-component.tsx"])
|
|
495
|
+
);
|
|
442
496
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
443
497
|
vi.spyOn(fs, "writeFileSync");
|
|
444
498
|
|
|
445
499
|
const plugin = ApplicationManifestPlugin();
|
|
446
|
-
plugin.configResolved({
|
|
500
|
+
plugin.configResolved({
|
|
501
|
+
command: "serve",
|
|
502
|
+
server: { port: "5678", host: "awesome.com" },
|
|
503
|
+
build: { outDir: "/dist" },
|
|
504
|
+
});
|
|
447
505
|
await plugin.buildStart();
|
|
448
506
|
|
|
449
507
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
@@ -462,14 +520,18 @@ describe("buildStart", () => {
|
|
|
462
520
|
`;
|
|
463
521
|
}
|
|
464
522
|
});
|
|
465
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
523
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
524
|
+
Promise.resolve(["my-component.tsx"])
|
|
525
|
+
);
|
|
466
526
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
467
527
|
vi.spyOn(fs, "writeFileSync");
|
|
468
528
|
|
|
469
529
|
const plugin = ApplicationManifestPlugin();
|
|
470
530
|
plugin.configResolved({ command: "serve", server: {} });
|
|
471
531
|
|
|
472
|
-
await expect(
|
|
532
|
+
await expect(
|
|
533
|
+
async () => await plugin.buildStart()
|
|
534
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
473
535
|
`[Error: 'name' argument must be supplied for @tool]`
|
|
474
536
|
);
|
|
475
537
|
});
|
|
@@ -484,14 +546,18 @@ describe("buildStart", () => {
|
|
|
484
546
|
`;
|
|
485
547
|
}
|
|
486
548
|
});
|
|
487
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
549
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
550
|
+
Promise.resolve(["my-component.tsx"])
|
|
551
|
+
);
|
|
488
552
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
489
553
|
vi.spyOn(fs, "writeFileSync");
|
|
490
554
|
|
|
491
555
|
const plugin = ApplicationManifestPlugin();
|
|
492
556
|
plugin.configResolved({ command: "serve", server: {} });
|
|
493
557
|
|
|
494
|
-
await expect(
|
|
558
|
+
await expect(
|
|
559
|
+
async () => await plugin.buildStart()
|
|
560
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
495
561
|
`[Error: 'description' argument must be supplied for @tool]`
|
|
496
562
|
);
|
|
497
563
|
});
|
|
@@ -506,14 +572,18 @@ describe("buildStart", () => {
|
|
|
506
572
|
`;
|
|
507
573
|
}
|
|
508
574
|
});
|
|
509
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
575
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
576
|
+
Promise.resolve(["my-component.tsx"])
|
|
577
|
+
);
|
|
510
578
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
511
579
|
vi.spyOn(fs, "writeFileSync");
|
|
512
580
|
|
|
513
581
|
const plugin = ApplicationManifestPlugin();
|
|
514
582
|
plugin.configResolved({ command: "serve", server: {} });
|
|
515
583
|
|
|
516
|
-
await expect(
|
|
584
|
+
await expect(
|
|
585
|
+
async () => await plugin.buildStart()
|
|
586
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
517
587
|
`[Error: Expected argument 'name' to be of type 'StringValue' but found 'BooleanValue' instead.]`
|
|
518
588
|
);
|
|
519
589
|
});
|
|
@@ -528,14 +598,18 @@ describe("buildStart", () => {
|
|
|
528
598
|
`;
|
|
529
599
|
}
|
|
530
600
|
});
|
|
531
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
601
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
602
|
+
Promise.resolve(["my-component.tsx"])
|
|
603
|
+
);
|
|
532
604
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
533
605
|
vi.spyOn(fs, "writeFileSync");
|
|
534
606
|
|
|
535
607
|
const plugin = ApplicationManifestPlugin();
|
|
536
608
|
plugin.configResolved({ command: "serve", server: {} });
|
|
537
609
|
|
|
538
|
-
await expect(
|
|
610
|
+
await expect(
|
|
611
|
+
async () => await plugin.buildStart()
|
|
612
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
539
613
|
`[Error: Expected argument 'description' to be of type 'StringValue' but found 'BooleanValue' instead.]`
|
|
540
614
|
);
|
|
541
615
|
});
|
|
@@ -550,14 +624,18 @@ describe("buildStart", () => {
|
|
|
550
624
|
`;
|
|
551
625
|
}
|
|
552
626
|
});
|
|
553
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
627
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
628
|
+
Promise.resolve(["my-component.tsx"])
|
|
629
|
+
);
|
|
554
630
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
555
631
|
vi.spyOn(fs, "writeFileSync");
|
|
556
632
|
|
|
557
633
|
const plugin = ApplicationManifestPlugin();
|
|
558
634
|
plugin.configResolved({ command: "serve", server: {} });
|
|
559
635
|
|
|
560
|
-
await expect(
|
|
636
|
+
await expect(
|
|
637
|
+
async () => await plugin.buildStart()
|
|
638
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
561
639
|
`[Error: Expected argument 'extraInputs' to be of type 'ListValue' but found 'BooleanValue' instead.]`
|
|
562
640
|
);
|
|
563
641
|
});
|
|
@@ -574,14 +652,18 @@ describe("buildStart", () => {
|
|
|
574
652
|
`;
|
|
575
653
|
}
|
|
576
654
|
});
|
|
577
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
655
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
656
|
+
Promise.resolve(["my-component.tsx"])
|
|
657
|
+
);
|
|
578
658
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
579
659
|
vi.spyOn(fs, "writeFileSync");
|
|
580
660
|
|
|
581
661
|
const plugin = ApplicationManifestPlugin();
|
|
582
662
|
plugin.configResolved({ command: "serve", server: {} });
|
|
583
663
|
|
|
584
|
-
await expect(
|
|
664
|
+
await expect(
|
|
665
|
+
async () => await plugin.buildStart()
|
|
666
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
585
667
|
`[Error: Error when parsing directive values: unexpected type 'FloatValue']`
|
|
586
668
|
);
|
|
587
669
|
});
|
|
@@ -590,7 +672,7 @@ describe("buildStart", () => {
|
|
|
590
672
|
vi.spyOn(fs, "readFileSync").mockImplementation((path) => {
|
|
591
673
|
if (path === "package.json") {
|
|
592
674
|
return JSON.stringify({});
|
|
593
|
-
} else if (path === "my-component.tsx") {
|
|
675
|
+
} else if (path === root + "/my-component.tsx") {
|
|
594
676
|
return `
|
|
595
677
|
const MY_QUERY = gql\`
|
|
596
678
|
fragment A on User { firstName }
|
|
@@ -607,12 +689,17 @@ describe("buildStart", () => {
|
|
|
607
689
|
`;
|
|
608
690
|
}
|
|
609
691
|
});
|
|
610
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
611
|
-
|
|
692
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
693
|
+
Promise.resolve(["my-component.tsx"])
|
|
694
|
+
);
|
|
612
695
|
vi.spyOn(fs, "writeFileSync");
|
|
613
696
|
|
|
614
697
|
const plugin = ApplicationManifestPlugin();
|
|
615
|
-
plugin.configResolved({
|
|
698
|
+
plugin.configResolved({
|
|
699
|
+
command: "serve",
|
|
700
|
+
server: {},
|
|
701
|
+
build: { outDir: "/dist" },
|
|
702
|
+
});
|
|
616
703
|
await plugin.buildStart();
|
|
617
704
|
let [file, content] = (fs.writeFileSync as unknown as Mock).mock.calls[0];
|
|
618
705
|
|
|
@@ -620,8 +707,8 @@ describe("buildStart", () => {
|
|
|
620
707
|
let contentObj = JSON.parse(content);
|
|
621
708
|
contentObj.hash = "abc";
|
|
622
709
|
|
|
623
|
-
expect(fs.writeFileSync).
|
|
624
|
-
expect(file).toBe(
|
|
710
|
+
expect(fs.writeFileSync).toHaveBeenCalledTimes(2);
|
|
711
|
+
expect(file).toBe(`${root}/dist/.application-manifest.json`);
|
|
625
712
|
expect(contentObj).toMatchInlineSnapshot(`
|
|
626
713
|
{
|
|
627
714
|
"csp": {
|
|
@@ -692,13 +779,20 @@ describe("writeBundle", () => {
|
|
|
692
779
|
`;
|
|
693
780
|
}
|
|
694
781
|
});
|
|
695
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
782
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
783
|
+
Promise.resolve(["my-component.tsx"])
|
|
784
|
+
);
|
|
696
785
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
697
786
|
vi.spyOn(path, "dirname").mockImplementation(() => "/dist");
|
|
698
787
|
vi.spyOn(fs, "writeFileSync");
|
|
699
788
|
|
|
700
789
|
const plugin = ApplicationManifestPlugin();
|
|
701
|
-
plugin.configResolved({
|
|
790
|
+
plugin.configResolved({
|
|
791
|
+
command: "build",
|
|
792
|
+
mode: "staging",
|
|
793
|
+
server: {},
|
|
794
|
+
build: { outDir: "/dist/" },
|
|
795
|
+
});
|
|
702
796
|
await plugin.buildStart();
|
|
703
797
|
await plugin.writeBundle();
|
|
704
798
|
|
|
@@ -718,13 +812,20 @@ describe("writeBundle", () => {
|
|
|
718
812
|
`;
|
|
719
813
|
}
|
|
720
814
|
});
|
|
721
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
815
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
816
|
+
Promise.resolve(["my-component.tsx"])
|
|
817
|
+
);
|
|
722
818
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
723
819
|
vi.spyOn(path, "dirname").mockImplementation(() => "/dist");
|
|
724
820
|
vi.spyOn(fs, "writeFileSync");
|
|
725
821
|
|
|
726
822
|
const plugin = ApplicationManifestPlugin();
|
|
727
|
-
plugin.configResolved({
|
|
823
|
+
plugin.configResolved({
|
|
824
|
+
command: "build",
|
|
825
|
+
mode: "production",
|
|
826
|
+
server: {},
|
|
827
|
+
build: { outDir: "/dist/" },
|
|
828
|
+
});
|
|
728
829
|
await plugin.buildStart();
|
|
729
830
|
await plugin.writeBundle();
|
|
730
831
|
|
|
@@ -744,16 +845,25 @@ describe("writeBundle", () => {
|
|
|
744
845
|
`;
|
|
745
846
|
}
|
|
746
847
|
});
|
|
747
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
848
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
849
|
+
Promise.resolve(["my-component.tsx"])
|
|
850
|
+
);
|
|
748
851
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
749
852
|
vi.spyOn(path, "dirname").mockImplementation(() => "/dist");
|
|
750
853
|
vi.spyOn(fs, "writeFileSync");
|
|
751
854
|
|
|
752
855
|
const plugin = ApplicationManifestPlugin();
|
|
753
|
-
plugin.configResolved({
|
|
856
|
+
plugin.configResolved({
|
|
857
|
+
command: "build",
|
|
858
|
+
mode: "staging",
|
|
859
|
+
server: {},
|
|
860
|
+
build: { outDir: "/dist/" },
|
|
861
|
+
});
|
|
754
862
|
await plugin.buildStart();
|
|
755
863
|
|
|
756
|
-
await expect(
|
|
864
|
+
await expect(
|
|
865
|
+
async () => await plugin.writeBundle()
|
|
866
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
757
867
|
`[Error: No entry point found for mode "staging". Entry points other than "development" and "production" must be defined in package.json file.]`
|
|
758
868
|
);
|
|
759
869
|
});
|
|
@@ -768,13 +878,20 @@ describe("writeBundle", () => {
|
|
|
768
878
|
`;
|
|
769
879
|
}
|
|
770
880
|
});
|
|
771
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
881
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
882
|
+
Promise.resolve(["my-component.tsx"])
|
|
883
|
+
);
|
|
772
884
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
773
885
|
vi.spyOn(path, "dirname").mockImplementation(() => "/dist");
|
|
774
886
|
vi.spyOn(fs, "writeFileSync");
|
|
775
887
|
|
|
776
888
|
const plugin = ApplicationManifestPlugin();
|
|
777
|
-
plugin.configResolved({
|
|
889
|
+
plugin.configResolved({
|
|
890
|
+
command: "build",
|
|
891
|
+
mode: "production",
|
|
892
|
+
server: {},
|
|
893
|
+
build: { outDir: "/dist/" },
|
|
894
|
+
});
|
|
778
895
|
await plugin.buildStart();
|
|
779
896
|
await plugin.writeBundle();
|
|
780
897
|
|
|
@@ -797,7 +914,9 @@ describe("configureServer", () => {
|
|
|
797
914
|
`;
|
|
798
915
|
}
|
|
799
916
|
});
|
|
800
|
-
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
917
|
+
vi.spyOn(glob, "glob").mockImplementation(() =>
|
|
918
|
+
Promise.resolve(["my-component.tsx"])
|
|
919
|
+
);
|
|
801
920
|
vi.spyOn(path, "resolve").mockImplementation((_, file) => file);
|
|
802
921
|
vi.spyOn(fs, "writeFileSync");
|
|
803
922
|
|
|
@@ -819,12 +938,16 @@ describe("configureServer", () => {
|
|
|
819
938
|
server.watcher.init();
|
|
820
939
|
|
|
821
940
|
const plugin = ApplicationManifestPlugin();
|
|
822
|
-
plugin.configResolved({
|
|
941
|
+
plugin.configResolved({
|
|
942
|
+
command: "serve",
|
|
943
|
+
server: {},
|
|
944
|
+
build: { outDir: "/dist" },
|
|
945
|
+
});
|
|
823
946
|
await plugin.buildStart();
|
|
824
947
|
await plugin.configureServer(server);
|
|
825
948
|
await server.watcher.trigger("package.json");
|
|
826
949
|
await server.watcher.trigger("my-component.tsx");
|
|
827
950
|
|
|
828
|
-
expect(fs.writeFileSync).toBeCalledTimes(
|
|
951
|
+
expect(fs.writeFileSync).toBeCalledTimes(6);
|
|
829
952
|
});
|
|
830
953
|
});
|