@khanacademy/wonder-blocks-data 3.1.1 → 4.0.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/CHANGELOG.md +41 -0
- package/dist/es/index.js +375 -335
- package/dist/index.js +527 -461
- package/docs.md +17 -35
- package/package.json +3 -3
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +7 -46
- package/src/__tests__/generated-snapshot.test.js +56 -122
- package/src/components/__tests__/data.test.js +372 -297
- package/src/components/__tests__/intercept-data.test.js +6 -30
- package/src/components/data.js +153 -21
- package/src/components/data.md +38 -69
- package/src/components/gql-router.js +1 -1
- package/src/components/intercept-context.js +6 -2
- package/src/components/intercept-data.js +40 -51
- package/src/components/intercept-data.md +13 -27
- package/src/components/track-data.md +9 -23
- package/src/hooks/__tests__/__snapshots__/use-shared-cache.test.js.snap +17 -0
- package/src/hooks/__tests__/use-gql.test.js +1 -0
- package/src/hooks/__tests__/use-server-effect.test.js +217 -0
- package/src/hooks/__tests__/use-shared-cache.test.js +307 -0
- package/src/hooks/use-gql.js +39 -31
- package/src/hooks/use-server-effect.js +45 -0
- package/src/hooks/use-shared-cache.js +106 -0
- package/src/index.js +15 -19
- package/src/util/__tests__/__snapshots__/scoped-in-memory-cache.test.js.snap +19 -0
- package/src/util/__tests__/request-fulfillment.test.js +42 -85
- package/src/util/__tests__/request-tracking.test.js +72 -191
- package/src/util/__tests__/{result-from-cache-entry.test.js → result-from-cache-response.test.js} +9 -10
- package/src/util/__tests__/scoped-in-memory-cache.test.js +396 -0
- package/src/util/__tests__/ssr-cache.test.js +639 -0
- package/src/util/gql-types.js +5 -10
- package/src/util/request-fulfillment.js +36 -44
- package/src/util/request-tracking.js +62 -75
- package/src/util/{result-from-cache-entry.js → result-from-cache-response.js} +10 -13
- package/src/util/scoped-in-memory-cache.js +149 -0
- package/src/util/ssr-cache.js +206 -0
- package/src/util/types.js +43 -108
- package/src/hooks/__tests__/use-data.test.js +0 -826
- package/src/hooks/use-data.js +0 -143
- package/src/util/__tests__/memory-cache.test.js +0 -446
- package/src/util/__tests__/request-handler.test.js +0 -121
- package/src/util/__tests__/response-cache.test.js +0 -879
- package/src/util/memory-cache.js +0 -187
- package/src/util/request-handler.js +0 -42
- package/src/util/request-handler.md +0 -51
- package/src/util/response-cache.js +0 -213
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import RequestHandler from "../request-handler.js";
|
|
3
|
-
|
|
4
|
-
describe("../request-handler.js", () => {
|
|
5
|
-
afterEach(() => {
|
|
6
|
-
/**
|
|
7
|
-
* This is needed or the JSON.stringify mocks need to be
|
|
8
|
-
* mockImplementationOnce. This is because if the snapshots need
|
|
9
|
-
* to update, they write the inline snapshot and that appears to invoke
|
|
10
|
-
* prettier which in turn, calls JSON.stringify. And if that mock
|
|
11
|
-
* throws, then boom. No snapshot update and a big old confusing test
|
|
12
|
-
* failure.
|
|
13
|
-
*/
|
|
14
|
-
jest.restoreAllMocks();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
describe("@type", () => {
|
|
18
|
-
it("should return value passed in construction", () => {
|
|
19
|
-
// Arrange
|
|
20
|
-
const handler = new RequestHandler("MY_TYPE");
|
|
21
|
-
|
|
22
|
-
// Act
|
|
23
|
-
const result = handler.type;
|
|
24
|
-
|
|
25
|
-
// Assert
|
|
26
|
-
expect(result).toBe("MY_TYPE");
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe("@hydrate", () => {
|
|
31
|
-
it("should return true when constructed with false", () => {
|
|
32
|
-
// Arrange
|
|
33
|
-
const handler = new RequestHandler("MY_TYPE", false);
|
|
34
|
-
|
|
35
|
-
// Act
|
|
36
|
-
const result = handler.hydrate;
|
|
37
|
-
|
|
38
|
-
// Assert
|
|
39
|
-
expect(result).toBeFalse();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("should return true when constructed with true", () => {
|
|
43
|
-
// Arrange
|
|
44
|
-
const handler = new RequestHandler("MY_TYPE", true);
|
|
45
|
-
|
|
46
|
-
// Act
|
|
47
|
-
const result = handler.hydrate;
|
|
48
|
-
|
|
49
|
-
// Assert
|
|
50
|
-
expect(result).toBeTrue();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("should return true by default", () => {
|
|
54
|
-
// Arrange
|
|
55
|
-
const handler = new RequestHandler("MY_TYPE");
|
|
56
|
-
|
|
57
|
-
// Act
|
|
58
|
-
const result = handler.hydrate;
|
|
59
|
-
|
|
60
|
-
// Assert
|
|
61
|
-
expect(result).toBeTrue();
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe("#getKey", () => {
|
|
66
|
-
it("should return a key for given options", () => {
|
|
67
|
-
// Arrange
|
|
68
|
-
const handler = new RequestHandler("MY_TYPE");
|
|
69
|
-
|
|
70
|
-
// Act
|
|
71
|
-
const result = handler.getKey({some: "options"});
|
|
72
|
-
|
|
73
|
-
// Assert
|
|
74
|
-
expect(result).toMatchInlineSnapshot(
|
|
75
|
-
`"{\\"some\\":\\"options\\"}"`,
|
|
76
|
-
);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("should return a key for undefined options", () => {
|
|
80
|
-
// Arrange
|
|
81
|
-
const handler = new RequestHandler("MY_TYPE");
|
|
82
|
-
|
|
83
|
-
// Act
|
|
84
|
-
const result = handler.getKey(undefined);
|
|
85
|
-
|
|
86
|
-
// Assert
|
|
87
|
-
expect(result).toMatchInlineSnapshot(`"undefined"`);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("should throw if JSON.stringify fails", () => {
|
|
91
|
-
// Arrange
|
|
92
|
-
const handler = new RequestHandler("MY_TYPE");
|
|
93
|
-
jest.spyOn(JSON, "stringify").mockImplementation(() => {
|
|
94
|
-
throw new Error("OH NOES!");
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Act
|
|
98
|
-
const underTest = () => handler.getKey({});
|
|
99
|
-
|
|
100
|
-
// Assert
|
|
101
|
-
expect(underTest).toThrowErrorMatchingInlineSnapshot(
|
|
102
|
-
`"Failed to auto-generate key: Error: OH NOES!"`,
|
|
103
|
-
);
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe("#fulfillRequest", () => {
|
|
108
|
-
it("should throw", () => {
|
|
109
|
-
// Arrange
|
|
110
|
-
const handler = new RequestHandler("MY_TYPE");
|
|
111
|
-
|
|
112
|
-
// Act
|
|
113
|
-
const underTest = () => handler.fulfillRequest("options");
|
|
114
|
-
|
|
115
|
-
// Assert
|
|
116
|
-
expect(underTest).toThrowErrorMatchingInlineSnapshot(
|
|
117
|
-
`"Not implemented"`,
|
|
118
|
-
);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
});
|