@apollo/client 3.11.8 → 3.11.9
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 +6 -0
- package/apollo-client.cjs +2 -2
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/config/jest/setup.js +5 -0
- package/config/jest/setup.js.map +1 -1
- package/core/core.cjs +1 -1
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +1 -1
- package/dev/dev.cjs +1 -1
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +1 -1
- package/package.json +4 -2
- package/react/internal/cache/QueryReference.js +1 -1
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/internal.cjs +2 -2
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +2 -2
- package/testing/internal/ObservableStream.d.ts +11 -15
- package/testing/internal/ObservableStream.js +18 -62
- package/testing/internal/ObservableStream.js.map +1 -1
- package/testing/internal/index.d.ts +1 -2
- package/testing/internal/index.js +1 -2
- package/testing/internal/index.js.map +1 -1
- package/testing/internal/renderHelpers.d.ts +13 -2
- package/testing/internal/renderHelpers.js +20 -12
- package/testing/internal/renderHelpers.js.map +1 -1
- package/testing/matchers/index.js +0 -3
- package/testing/matchers/index.js.map +1 -1
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/version.js +1 -1
- package/testing/internal/profile/Render.d.ts +0 -69
- package/testing/internal/profile/Render.js +0 -144
- package/testing/internal/profile/Render.js.map +0 -1
- package/testing/internal/profile/context.d.ts +0 -10
- package/testing/internal/profile/context.js +0 -14
- package/testing/internal/profile/context.js.map +0 -1
- package/testing/internal/profile/index.d.ts +0 -4
- package/testing/internal/profile/index.js +0 -2
- package/testing/internal/profile/index.js.map +0 -1
- package/testing/internal/profile/profile.d.ts +0 -109
- package/testing/internal/profile/profile.js +0 -304
- package/testing/internal/profile/profile.js.map +0 -1
- package/testing/internal/profile/traces.d.ts +0 -7
- package/testing/internal/profile/traces.js +0 -30
- package/testing/internal/profile/traces.js.map +0 -1
- package/testing/matchers/ProfiledComponent.d.ts +0 -8
- package/testing/matchers/ProfiledComponent.js +0 -110
- package/testing/matchers/ProfiledComponent.js.map +0 -1
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
var _a, _b;
|
|
2
|
-
import { __addDisposableResource, __assign, __awaiter, __disposeResources, __extends, __generator, __rest } from "tslib";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import { TextEncoder, TextDecoder } from "util";
|
|
5
|
-
(_a = global.TextEncoder) !== null && _a !== void 0 ? _a : (global.TextEncoder = TextEncoder);
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
(_b = global.TextDecoder) !== null && _b !== void 0 ? _b : (global.TextDecoder = TextDecoder);
|
|
8
|
-
import { RenderInstance } from "./Render.js";
|
|
9
|
-
import { applyStackTrace, captureStackTrace } from "./traces.js";
|
|
10
|
-
import { ProfilerContextProvider, useProfilerContext } from "./context.js";
|
|
11
|
-
import { disableActWarnings } from "../disposables/index.js";
|
|
12
|
-
/** only used for passing around data internally */
|
|
13
|
-
var _stackTrace = Symbol();
|
|
14
|
-
/** @internal */
|
|
15
|
-
export function profile(_a) {
|
|
16
|
-
var Component = _a.Component, options = __rest(_a, ["Component"]);
|
|
17
|
-
var Profiler = createProfiler(options);
|
|
18
|
-
return Object.assign(function ProfiledComponent(props) {
|
|
19
|
-
return (React.createElement(Profiler, null,
|
|
20
|
-
React.createElement(Component, __assign({}, props))));
|
|
21
|
-
}, {
|
|
22
|
-
mergeSnapshot: Profiler.mergeSnapshot,
|
|
23
|
-
replaceSnapshot: Profiler.replaceSnapshot,
|
|
24
|
-
getCurrentRender: Profiler.getCurrentRender,
|
|
25
|
-
peekRender: Profiler.peekRender,
|
|
26
|
-
takeRender: Profiler.takeRender,
|
|
27
|
-
totalRenderCount: Profiler.totalRenderCount,
|
|
28
|
-
waitForNextRender: Profiler.waitForNextRender,
|
|
29
|
-
get renders() {
|
|
30
|
-
return Profiler.renders;
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
/** @internal */
|
|
35
|
-
export function createProfiler(_a) {
|
|
36
|
-
var _b = _a === void 0 ? {} : _a, onRender = _b.onRender, _c = _b.snapshotDOM, snapshotDOM = _c === void 0 ? false : _c, initialSnapshot = _b.initialSnapshot, skipNonTrackingRenders = _b.skipNonTrackingRenders;
|
|
37
|
-
var nextRender;
|
|
38
|
-
var resolveNextRender;
|
|
39
|
-
var rejectNextRender;
|
|
40
|
-
function resetNextRender() {
|
|
41
|
-
nextRender = resolveNextRender = rejectNextRender = undefined;
|
|
42
|
-
}
|
|
43
|
-
var snapshotRef = { current: initialSnapshot };
|
|
44
|
-
var replaceSnapshot = function (snap) {
|
|
45
|
-
if (typeof snap === "function") {
|
|
46
|
-
if (!initialSnapshot) {
|
|
47
|
-
throw new Error("Cannot use a function to update the snapshot if no initial snapshot was provided.");
|
|
48
|
-
}
|
|
49
|
-
snapshotRef.current = snap(typeof snapshotRef.current === "object" ? __assign({}, snapshotRef.current) : snapshotRef.current);
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
snapshotRef.current = snap;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
var mergeSnapshot = function (partialSnapshot) {
|
|
56
|
-
replaceSnapshot(function (snapshot) { return (__assign(__assign({}, snapshot), (typeof partialSnapshot === "function" ?
|
|
57
|
-
partialSnapshot(snapshot)
|
|
58
|
-
: partialSnapshot))); });
|
|
59
|
-
};
|
|
60
|
-
var profilerContext = {
|
|
61
|
-
renderedComponents: [],
|
|
62
|
-
};
|
|
63
|
-
var profilerOnRender = function (id, phase, actualDuration, baseDuration, startTime, commitTime) {
|
|
64
|
-
if (skipNonTrackingRenders &&
|
|
65
|
-
profilerContext.renderedComponents.length === 0) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
var baseRender = {
|
|
69
|
-
id: id,
|
|
70
|
-
phase: phase,
|
|
71
|
-
actualDuration: actualDuration,
|
|
72
|
-
baseDuration: baseDuration,
|
|
73
|
-
startTime: startTime,
|
|
74
|
-
commitTime: commitTime,
|
|
75
|
-
count: Profiler.renders.length + 1,
|
|
76
|
-
};
|
|
77
|
-
try {
|
|
78
|
-
/*
|
|
79
|
-
* The `onRender` function could contain `expect` calls that throw
|
|
80
|
-
* `JestAssertionError`s - but we are still inside of React, where errors
|
|
81
|
-
* might be swallowed.
|
|
82
|
-
* So we record them and re-throw them in `takeRender`
|
|
83
|
-
* Additionally, we reject the `waitForNextRender` promise.
|
|
84
|
-
*/
|
|
85
|
-
onRender === null || onRender === void 0 ? void 0 : onRender(__assign(__assign({}, baseRender), { replaceSnapshot: replaceSnapshot, mergeSnapshot: mergeSnapshot, snapshot: snapshotRef.current }));
|
|
86
|
-
var snapshot = snapshotRef.current;
|
|
87
|
-
var domSnapshot = snapshotDOM ? window.document.body.innerHTML : undefined;
|
|
88
|
-
var render = new RenderInstance(baseRender, snapshot, domSnapshot, profilerContext.renderedComponents);
|
|
89
|
-
profilerContext.renderedComponents = [];
|
|
90
|
-
Profiler.renders.push(render);
|
|
91
|
-
resolveNextRender === null || resolveNextRender === void 0 ? void 0 : resolveNextRender(render);
|
|
92
|
-
}
|
|
93
|
-
catch (error) {
|
|
94
|
-
Profiler.renders.push({
|
|
95
|
-
phase: "snapshotError",
|
|
96
|
-
count: Profiler.renders.length,
|
|
97
|
-
error: error,
|
|
98
|
-
});
|
|
99
|
-
rejectNextRender === null || rejectNextRender === void 0 ? void 0 : rejectNextRender(error);
|
|
100
|
-
}
|
|
101
|
-
finally {
|
|
102
|
-
resetNextRender();
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
var iteratorPosition = 0;
|
|
106
|
-
var Profiler = Object.assign(function (_a) {
|
|
107
|
-
var children = _a.children;
|
|
108
|
-
return (React.createElement(ProfilerContextProvider, { value: profilerContext },
|
|
109
|
-
React.createElement(React.Profiler, { id: "test", onRender: profilerOnRender }, children)));
|
|
110
|
-
}, {
|
|
111
|
-
replaceSnapshot: replaceSnapshot,
|
|
112
|
-
mergeSnapshot: mergeSnapshot,
|
|
113
|
-
}, {
|
|
114
|
-
renders: new Array(),
|
|
115
|
-
totalRenderCount: function () {
|
|
116
|
-
return Profiler.renders.length;
|
|
117
|
-
},
|
|
118
|
-
peekRender: function () {
|
|
119
|
-
return __awaiter(this, arguments, void 0, function (options) {
|
|
120
|
-
var render;
|
|
121
|
-
var _a;
|
|
122
|
-
if (options === void 0) { options = {}; }
|
|
123
|
-
return __generator(this, function (_b) {
|
|
124
|
-
if (iteratorPosition < Profiler.renders.length) {
|
|
125
|
-
render = Profiler.renders[iteratorPosition];
|
|
126
|
-
if (render.phase === "snapshotError") {
|
|
127
|
-
throw render.error;
|
|
128
|
-
}
|
|
129
|
-
return [2 /*return*/, render];
|
|
130
|
-
}
|
|
131
|
-
return [2 /*return*/, Profiler.waitForNextRender(__assign((_a = {}, _a[_stackTrace] = captureStackTrace(Profiler.peekRender), _a), options))];
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
},
|
|
135
|
-
takeRender: function () {
|
|
136
|
-
return __awaiter(this, arguments, void 0, function (options) {
|
|
137
|
-
var env_1, _disabledActWarnings, error, e_1, e_2;
|
|
138
|
-
var _a;
|
|
139
|
-
if (options === void 0) { options = {}; }
|
|
140
|
-
return __generator(this, function (_b) {
|
|
141
|
-
switch (_b.label) {
|
|
142
|
-
case 0:
|
|
143
|
-
env_1 = { stack: [], error: void 0, hasError: false };
|
|
144
|
-
_b.label = 1;
|
|
145
|
-
case 1:
|
|
146
|
-
_b.trys.push([1, 7, 8, 9]);
|
|
147
|
-
_disabledActWarnings = __addDisposableResource(env_1, disableActWarnings(), false);
|
|
148
|
-
error = undefined;
|
|
149
|
-
_b.label = 2;
|
|
150
|
-
case 2:
|
|
151
|
-
_b.trys.push([2, 4, 5, 6]);
|
|
152
|
-
return [4 /*yield*/, Profiler.peekRender(__assign((_a = {}, _a[_stackTrace] = captureStackTrace(Profiler.takeRender), _a), options))];
|
|
153
|
-
case 3: return [2 /*return*/, _b.sent()];
|
|
154
|
-
case 4:
|
|
155
|
-
e_1 = _b.sent();
|
|
156
|
-
error = e_1;
|
|
157
|
-
throw e_1;
|
|
158
|
-
case 5:
|
|
159
|
-
if (!(error && error instanceof WaitForRenderTimeoutError)) {
|
|
160
|
-
iteratorPosition++;
|
|
161
|
-
}
|
|
162
|
-
return [7 /*endfinally*/];
|
|
163
|
-
case 6: return [3 /*break*/, 9];
|
|
164
|
-
case 7:
|
|
165
|
-
e_2 = _b.sent();
|
|
166
|
-
env_1.error = e_2;
|
|
167
|
-
env_1.hasError = true;
|
|
168
|
-
return [3 /*break*/, 9];
|
|
169
|
-
case 8:
|
|
170
|
-
__disposeResources(env_1);
|
|
171
|
-
return [7 /*endfinally*/];
|
|
172
|
-
case 9: return [2 /*return*/];
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
},
|
|
177
|
-
getCurrentRender: function () {
|
|
178
|
-
// The "current" render should point at the same render that the most
|
|
179
|
-
// recent `takeRender` call returned, so we need to get the "previous"
|
|
180
|
-
// iterator position, otherwise `takeRender` advances the iterator
|
|
181
|
-
// to the next render. This means we need to call `takeRender` at least
|
|
182
|
-
// once before we can get a current render.
|
|
183
|
-
var currentPosition = iteratorPosition - 1;
|
|
184
|
-
if (currentPosition < 0) {
|
|
185
|
-
throw new Error("No current render available. You need to call `takeRender` before you can get the current render.");
|
|
186
|
-
}
|
|
187
|
-
var render = Profiler.renders[currentPosition];
|
|
188
|
-
if (render.phase === "snapshotError") {
|
|
189
|
-
throw render.error;
|
|
190
|
-
}
|
|
191
|
-
return render;
|
|
192
|
-
},
|
|
193
|
-
waitForNextRender: function (_a) {
|
|
194
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.timeout, timeout = _c === void 0 ? 1000 : _c,
|
|
195
|
-
// capture the stack trace here so its stack trace is as close to the calling code as possible
|
|
196
|
-
_d = _stackTrace,
|
|
197
|
-
// capture the stack trace here so its stack trace is as close to the calling code as possible
|
|
198
|
-
_e = _b[_d],
|
|
199
|
-
// capture the stack trace here so its stack trace is as close to the calling code as possible
|
|
200
|
-
stackTrace = _e === void 0 ? captureStackTrace(Profiler.waitForNextRender) : _e;
|
|
201
|
-
if (!nextRender) {
|
|
202
|
-
nextRender = Promise.race([
|
|
203
|
-
new Promise(function (resolve, reject) {
|
|
204
|
-
resolveNextRender = resolve;
|
|
205
|
-
rejectNextRender = reject;
|
|
206
|
-
}),
|
|
207
|
-
new Promise(function (_, reject) {
|
|
208
|
-
return setTimeout(function () {
|
|
209
|
-
reject(applyStackTrace(new WaitForRenderTimeoutError(), stackTrace));
|
|
210
|
-
resetNextRender();
|
|
211
|
-
}, timeout);
|
|
212
|
-
}),
|
|
213
|
-
]);
|
|
214
|
-
}
|
|
215
|
-
return nextRender;
|
|
216
|
-
},
|
|
217
|
-
});
|
|
218
|
-
return Profiler;
|
|
219
|
-
}
|
|
220
|
-
/** @internal */
|
|
221
|
-
var WaitForRenderTimeoutError = /** @class */ (function (_super) {
|
|
222
|
-
__extends(WaitForRenderTimeoutError, _super);
|
|
223
|
-
function WaitForRenderTimeoutError() {
|
|
224
|
-
var _newTarget = this.constructor;
|
|
225
|
-
var _this = _super.call(this, "Exceeded timeout waiting for next render.") || this;
|
|
226
|
-
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
227
|
-
return _this;
|
|
228
|
-
}
|
|
229
|
-
return WaitForRenderTimeoutError;
|
|
230
|
-
}(Error));
|
|
231
|
-
export { WaitForRenderTimeoutError };
|
|
232
|
-
/** @internal */
|
|
233
|
-
export function profileHook(renderCallback) {
|
|
234
|
-
var Profiler = createProfiler();
|
|
235
|
-
var ProfiledHook = function (props) {
|
|
236
|
-
Profiler.replaceSnapshot(renderCallback(props));
|
|
237
|
-
return null;
|
|
238
|
-
};
|
|
239
|
-
return Object.assign(function App(props) {
|
|
240
|
-
return (React.createElement(Profiler, null,
|
|
241
|
-
React.createElement(ProfiledHook, __assign({}, props))));
|
|
242
|
-
}, {
|
|
243
|
-
Profiler: Profiler,
|
|
244
|
-
}, {
|
|
245
|
-
renders: Profiler.renders,
|
|
246
|
-
totalSnapshotCount: Profiler.totalRenderCount,
|
|
247
|
-
peekSnapshot: function (options) {
|
|
248
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
249
|
-
return __generator(this, function (_a) {
|
|
250
|
-
switch (_a.label) {
|
|
251
|
-
case 0: return [4 /*yield*/, Profiler.peekRender(options)];
|
|
252
|
-
case 1: return [2 /*return*/, (_a.sent()).snapshot];
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
});
|
|
256
|
-
},
|
|
257
|
-
takeSnapshot: function (options) {
|
|
258
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
259
|
-
return __generator(this, function (_a) {
|
|
260
|
-
switch (_a.label) {
|
|
261
|
-
case 0: return [4 /*yield*/, Profiler.takeRender(options)];
|
|
262
|
-
case 1: return [2 /*return*/, (_a.sent()).snapshot];
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
},
|
|
267
|
-
getCurrentSnapshot: function () {
|
|
268
|
-
return Profiler.getCurrentRender().snapshot;
|
|
269
|
-
},
|
|
270
|
-
waitForNextSnapshot: function (options) {
|
|
271
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
272
|
-
return __generator(this, function (_a) {
|
|
273
|
-
switch (_a.label) {
|
|
274
|
-
case 0: return [4 /*yield*/, Profiler.waitForNextRender(options)];
|
|
275
|
-
case 1: return [2 /*return*/, (_a.sent()).snapshot];
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
},
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
function resolveR18HookOwner() {
|
|
283
|
-
var _a, _b, _c;
|
|
284
|
-
return (_c = (_b = (_a = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _a === void 0 ? void 0 : _a.ReactCurrentOwner) === null || _b === void 0 ? void 0 : _b.current) === null || _c === void 0 ? void 0 : _c.elementType;
|
|
285
|
-
}
|
|
286
|
-
function resolveR19HookOwner() {
|
|
287
|
-
var _a, _b;
|
|
288
|
-
return (_b = (_a = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE) === null || _a === void 0 ? void 0 : _a.A) === null || _b === void 0 ? void 0 : _b.getOwner().elementType;
|
|
289
|
-
}
|
|
290
|
-
export function useTrackRenders(_a) {
|
|
291
|
-
var _b = _a === void 0 ? {} : _a, name = _b.name;
|
|
292
|
-
var component = name || resolveR18HookOwner() || resolveR19HookOwner();
|
|
293
|
-
if (!component) {
|
|
294
|
-
throw new Error("useTrackRender: Unable to determine component. Please ensure the hook is called inside a rendered component or provide a `name` option.");
|
|
295
|
-
}
|
|
296
|
-
var ctx = useProfilerContext();
|
|
297
|
-
if (!ctx) {
|
|
298
|
-
throw new Error("useTrackComponentRender: A Profiler must be created and rendered to track component renders");
|
|
299
|
-
}
|
|
300
|
-
React.useLayoutEffect(function () {
|
|
301
|
-
ctx.renderedComponents.unshift(component);
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
//# sourceMappingURL=profile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"profile.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/profile.tsx"],"names":[],"mappings":";;AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAEhD,MAAA,MAAM,CAAC,WAAW,oCAAlB,MAAM,CAAC,WAAW,GAAK,WAAW,EAAC;AACnC,aAAa;AACb,MAAA,MAAM,CAAC,WAAW,oCAAlB,MAAM,CAAC,WAAW,GAAK,WAAW,EAAC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B,qBAAM,QAAQ,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAA;gCAAjD,sBAAO,CAAC,SAAyC,CAAC,CAAC,QAAQ,EAAC;;;;SAC7D;KACwC,CAC5C,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB;;IAC1B,OAAO,MAAA,MAAA,MAAC,KAAa,CAAC,kDAAkD,0CACpE,iBAAiB,0CAAE,OAAO,0CAAE,WAAW,CAAC;AAC9C,CAAC;AAED,SAAS,mBAAmB;;IAC1B,OAAO,MAAA,MACL,KACD,CAAC,+DAA+D,0CAAE,CAAC,0CAAE,QAAQ,GAC3E,WAAW,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,EAAgC;QAAhC,qBAA8B,EAAE,KAAA,EAA9B,IAAI,UAAA;IACpC,IAAM,SAAS,GAAG,IAAI,IAAI,mBAAmB,EAAE,IAAI,mBAAmB,EAAE,CAAC;IAEzE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,yIAAyI,CAC1I,CAAC;IACJ,CAAC;IAED,IAAM,GAAG,GAAG,kBAAkB,EAAE,CAAC;IAEjC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,6FAA6F,CAC9F,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,eAAe,CAAC;QACpB,GAAG,CAAC,kBAAkB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport { TextEncoder, TextDecoder } from \"util\";\n\nglobal.TextEncoder ??= TextEncoder;\n// @ts-ignore\nglobal.TextDecoder ??= TextDecoder;\nimport type { Render, BaseRender } from \"./Render.js\";\nimport { RenderInstance } from \"./Render.js\";\nimport { applyStackTrace, captureStackTrace } from \"./traces.js\";\nimport type { ProfilerContextValue } from \"./context.js\";\nimport { ProfilerContextProvider, useProfilerContext } from \"./context.js\";\nimport { disableActWarnings } from \"../disposables/index.js\";\n\ntype ValidSnapshot = void | (object & { /* not a function */ call?: never });\n\n/** only used for passing around data internally */\nconst _stackTrace = Symbol();\n/** @internal */\nexport interface NextRenderOptions {\n timeout?: number;\n [_stackTrace]?: string;\n}\n\n/** @internal */\ninterface ProfilerProps {\n children: React.ReactNode;\n}\n\n/** @internal */\nexport interface Profiler<Snapshot>\n extends React.FC<ProfilerProps>,\n ProfiledComponentFields<Snapshot>,\n ProfiledComponentOnlyFields<Snapshot> {}\n\ninterface ReplaceSnapshot<Snapshot> {\n (newSnapshot: Snapshot): void;\n (updateSnapshot: (lastSnapshot: Readonly<Snapshot>) => Snapshot): void;\n}\n\ninterface MergeSnapshot<Snapshot> {\n (partialSnapshot: Partial<Snapshot>): void;\n (\n updatePartialSnapshot: (\n lastSnapshot: Readonly<Snapshot>\n ) => Partial<Snapshot>\n ): void;\n}\n\ninterface ProfiledComponentOnlyFields<Snapshot> {\n // Allows for partial updating of the snapshot by shallow merging the results\n mergeSnapshot: MergeSnapshot<Snapshot>;\n // Performs a full replacement of the snapshot\n replaceSnapshot: ReplaceSnapshot<Snapshot>;\n}\ninterface ProfiledComponentFields<Snapshot> {\n /**\n * An array of all renders that have happened so far.\n * Errors thrown during component render will be captured here, too.\n */\n renders: Array<\n Render<Snapshot> | { phase: \"snapshotError\"; count: number; error: unknown }\n >;\n /**\n * Peeks the next render from the current iterator position, without advancing the iterator.\n * If no render has happened yet, it will wait for the next render to happen.\n * @throws {WaitForRenderTimeoutError} if no render happens within the timeout\n */\n peekRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n /**\n * Iterates to the next render and returns it.\n * If no render has happened yet, it will wait for the next render to happen.\n * @throws {WaitForRenderTimeoutError} if no render happens within the timeout\n */\n takeRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n /**\n * Returns the total number of renders.\n */\n totalRenderCount(): number;\n /**\n * Returns the current render.\n * @throws {Error} if no render has happened yet\n */\n getCurrentRender(): Render<Snapshot>;\n /**\n * Waits for the next render to happen.\n * Does not advance the render iterator.\n */\n waitForNextRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;\n}\n\nexport interface ProfiledComponent<Snapshot extends ValidSnapshot, Props = {}>\n extends React.FC<Props>,\n ProfiledComponentFields<Snapshot>,\n ProfiledComponentOnlyFields<Snapshot> {}\n\n/** @internal */\nexport function profile<Snapshot extends ValidSnapshot = void, Props = {}>({\n Component,\n ...options\n}: Parameters<typeof createProfiler<Snapshot>>[0] & {\n Component: React.ComponentType<Props>;\n}): ProfiledComponent<Snapshot, Props> {\n const Profiler = createProfiler(options);\n\n return Object.assign(\n function ProfiledComponent(props: Props) {\n return (\n <Profiler>\n <Component {...(props as any)} />\n </Profiler>\n );\n },\n {\n mergeSnapshot: Profiler.mergeSnapshot,\n replaceSnapshot: Profiler.replaceSnapshot,\n getCurrentRender: Profiler.getCurrentRender,\n peekRender: Profiler.peekRender,\n takeRender: Profiler.takeRender,\n totalRenderCount: Profiler.totalRenderCount,\n waitForNextRender: Profiler.waitForNextRender,\n get renders() {\n return Profiler.renders;\n },\n }\n );\n}\n\n/** @internal */\nexport function createProfiler<Snapshot extends ValidSnapshot = void>({\n onRender,\n snapshotDOM = false,\n initialSnapshot,\n skipNonTrackingRenders,\n}: {\n onRender?: (\n info: BaseRender & {\n snapshot: Snapshot;\n replaceSnapshot: ReplaceSnapshot<Snapshot>;\n mergeSnapshot: MergeSnapshot<Snapshot>;\n }\n ) => void;\n snapshotDOM?: boolean;\n initialSnapshot?: Snapshot;\n /**\n * This will skip renders during which no renders tracked by\n * `useTrackRenders` occured.\n */\n skipNonTrackingRenders?: boolean;\n} = {}) {\n let nextRender: Promise<Render<Snapshot>> | undefined;\n let resolveNextRender: ((render: Render<Snapshot>) => void) | undefined;\n let rejectNextRender: ((error: unknown) => void) | undefined;\n function resetNextRender() {\n nextRender = resolveNextRender = rejectNextRender = undefined;\n }\n const snapshotRef = { current: initialSnapshot };\n const replaceSnapshot: ReplaceSnapshot<Snapshot> = (snap) => {\n if (typeof snap === \"function\") {\n if (!initialSnapshot) {\n throw new Error(\n \"Cannot use a function to update the snapshot if no initial snapshot was provided.\"\n );\n }\n snapshotRef.current = snap(\n typeof snapshotRef.current === \"object\" ?\n // \"cheap best effort\" to prevent accidental mutation of the last snapshot\n { ...snapshotRef.current! }\n : snapshotRef.current!\n );\n } else {\n snapshotRef.current = snap;\n }\n };\n\n const mergeSnapshot: MergeSnapshot<Snapshot> = (partialSnapshot) => {\n replaceSnapshot((snapshot) => ({\n ...snapshot,\n ...(typeof partialSnapshot === \"function\" ?\n partialSnapshot(snapshot)\n : partialSnapshot),\n }));\n };\n\n const profilerContext: ProfilerContextValue = {\n renderedComponents: [],\n };\n\n const profilerOnRender: React.ProfilerOnRenderCallback = (\n id,\n phase,\n actualDuration,\n baseDuration,\n startTime,\n commitTime\n ) => {\n if (\n skipNonTrackingRenders &&\n profilerContext.renderedComponents.length === 0\n ) {\n return;\n }\n const baseRender = {\n id,\n phase,\n actualDuration,\n baseDuration,\n startTime,\n commitTime,\n count: Profiler.renders.length + 1,\n };\n try {\n /*\n * The `onRender` function could contain `expect` calls that throw\n * `JestAssertionError`s - but we are still inside of React, where errors\n * might be swallowed.\n * So we record them and re-throw them in `takeRender`\n * Additionally, we reject the `waitForNextRender` promise.\n */\n onRender?.({\n ...baseRender,\n replaceSnapshot,\n mergeSnapshot,\n snapshot: snapshotRef.current!,\n });\n\n const snapshot = snapshotRef.current as Snapshot;\n const domSnapshot =\n snapshotDOM ? window.document.body.innerHTML : undefined;\n const render = new RenderInstance(\n baseRender,\n snapshot,\n domSnapshot,\n profilerContext.renderedComponents\n );\n profilerContext.renderedComponents = [];\n Profiler.renders.push(render);\n resolveNextRender?.(render);\n } catch (error) {\n Profiler.renders.push({\n phase: \"snapshotError\",\n count: Profiler.renders.length,\n error,\n });\n rejectNextRender?.(error);\n } finally {\n resetNextRender();\n }\n };\n\n let iteratorPosition = 0;\n const Profiler: Profiler<Snapshot> = Object.assign(\n ({ children }: ProfilerProps) => {\n return (\n <ProfilerContextProvider value={profilerContext}>\n <React.Profiler id=\"test\" onRender={profilerOnRender}>\n {children}\n </React.Profiler>\n </ProfilerContextProvider>\n );\n },\n {\n replaceSnapshot,\n mergeSnapshot,\n } satisfies ProfiledComponentOnlyFields<Snapshot>,\n {\n renders: new Array<\n | Render<Snapshot>\n | { phase: \"snapshotError\"; count: number; error: unknown }\n >(),\n totalRenderCount() {\n return Profiler.renders.length;\n },\n async peekRender(options: NextRenderOptions = {}) {\n if (iteratorPosition < Profiler.renders.length) {\n const render = Profiler.renders[iteratorPosition];\n\n if (render.phase === \"snapshotError\") {\n throw render.error;\n }\n\n return render;\n }\n return Profiler.waitForNextRender({\n [_stackTrace]: captureStackTrace(Profiler.peekRender),\n ...options,\n });\n },\n async takeRender(options: NextRenderOptions = {}) {\n // In many cases we do not control the resolution of the suspended\n // promise which results in noisy tests when the profiler due to\n // repeated act warnings.\n using _disabledActWarnings = disableActWarnings();\n\n let error: unknown = undefined;\n\n try {\n return await Profiler.peekRender({\n [_stackTrace]: captureStackTrace(Profiler.takeRender),\n ...options,\n });\n } catch (e) {\n error = e;\n throw e;\n } finally {\n if (!(error && error instanceof WaitForRenderTimeoutError)) {\n iteratorPosition++;\n }\n }\n },\n getCurrentRender() {\n // The \"current\" render should point at the same render that the most\n // recent `takeRender` call returned, so we need to get the \"previous\"\n // iterator position, otherwise `takeRender` advances the iterator\n // to the next render. This means we need to call `takeRender` at least\n // once before we can get a current render.\n const currentPosition = iteratorPosition - 1;\n\n if (currentPosition < 0) {\n throw new Error(\n \"No current render available. You need to call `takeRender` before you can get the current render.\"\n );\n }\n\n const render = Profiler.renders[currentPosition];\n\n if (render.phase === \"snapshotError\") {\n throw render.error;\n }\n return render;\n },\n waitForNextRender({\n timeout = 1000,\n // capture the stack trace here so its stack trace is as close to the calling code as possible\n [_stackTrace]: stackTrace = captureStackTrace(\n Profiler.waitForNextRender\n ),\n }: NextRenderOptions = {}) {\n if (!nextRender) {\n nextRender = Promise.race<Render<Snapshot>>([\n new Promise<Render<Snapshot>>((resolve, reject) => {\n resolveNextRender = resolve;\n rejectNextRender = reject;\n }),\n new Promise<Render<Snapshot>>((_, reject) =>\n setTimeout(() => {\n reject(\n applyStackTrace(new WaitForRenderTimeoutError(), stackTrace)\n );\n resetNextRender();\n }, timeout)\n ),\n ]);\n }\n return nextRender;\n },\n } satisfies ProfiledComponentFields<Snapshot>\n );\n return Profiler;\n}\n\n/** @internal */\nexport class WaitForRenderTimeoutError extends Error {\n constructor() {\n super(\"Exceeded timeout waiting for next render.\");\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\ntype StringReplaceRenderWithSnapshot<T extends string> =\n T extends `${infer Pre}Render${infer Post}` ? `${Pre}Snapshot${Post}` : T;\n\ntype ResultReplaceRenderWithSnapshot<T> =\n T extends (...args: infer Args) => Render<infer Snapshot> ?\n (...args: Args) => Snapshot\n : T extends (...args: infer Args) => Promise<Render<infer Snapshot>> ?\n (...args: Args) => Promise<Snapshot>\n : T;\n\ntype ProfiledHookFields<ReturnValue> =\n ProfiledComponentFields<ReturnValue> extends infer PC ?\n {\n [K in keyof PC as StringReplaceRenderWithSnapshot<\n K & string\n >]: ResultReplaceRenderWithSnapshot<PC[K]>;\n }\n : never;\n\n/** @internal */\nexport interface ProfiledHook<Props, ReturnValue>\n extends React.FC<Props>,\n ProfiledHookFields<ReturnValue> {\n Profiler: Profiler<ReturnValue>;\n}\n\n/** @internal */\nexport function profileHook<ReturnValue extends ValidSnapshot, Props>(\n renderCallback: (props: Props) => ReturnValue\n): ProfiledHook<Props, ReturnValue> {\n const Profiler = createProfiler<ReturnValue>();\n\n const ProfiledHook = (props: Props) => {\n Profiler.replaceSnapshot(renderCallback(props));\n return null;\n };\n\n return Object.assign(\n function App(props: Props) {\n return (\n <Profiler>\n <ProfiledHook {...(props as any)} />\n </Profiler>\n );\n },\n {\n Profiler,\n },\n {\n renders: Profiler.renders,\n totalSnapshotCount: Profiler.totalRenderCount,\n async peekSnapshot(options) {\n return (await Profiler.peekRender(options)).snapshot;\n },\n async takeSnapshot(options) {\n return (await Profiler.takeRender(options)).snapshot;\n },\n getCurrentSnapshot() {\n return Profiler.getCurrentRender().snapshot;\n },\n async waitForNextSnapshot(options) {\n return (await Profiler.waitForNextRender(options)).snapshot;\n },\n } satisfies ProfiledHookFields<ReturnValue>\n );\n}\n\nfunction resolveR18HookOwner(): React.ComponentType | undefined {\n return (React as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED\n ?.ReactCurrentOwner?.current?.elementType;\n}\n\nfunction resolveR19HookOwner(): React.ComponentType | undefined {\n return (\n React as any\n ).__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE?.A?.getOwner()\n .elementType;\n}\n\nexport function useTrackRenders({ name }: { name?: string } = {}) {\n const component = name || resolveR18HookOwner() || resolveR19HookOwner();\n\n if (!component) {\n throw new Error(\n \"useTrackRender: Unable to determine component. Please ensure the hook is called inside a rendered component or provide a `name` option.\"\n );\n }\n\n const ctx = useProfilerContext();\n\n if (!ctx) {\n throw new Error(\n \"useTrackComponentRender: A Profiler must be created and rendered to track component renders\"\n );\n }\n\n React.useLayoutEffect(() => {\n ctx.renderedComponents.unshift(component);\n });\n}\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Captures a StackTrace and (if passed) cuts off
|
|
3
|
-
* the first lines including the calling function.
|
|
4
|
-
*/
|
|
5
|
-
export declare function captureStackTrace(callingFunction?: string | (() => {})): string;
|
|
6
|
-
export declare function applyStackTrace(error: Error, stackTrace: string): Error;
|
|
7
|
-
//# sourceMappingURL=traces.d.ts.map
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Captures a StackTrace and (if passed) cuts off
|
|
3
|
-
* the first lines including the calling function.
|
|
4
|
-
*/
|
|
5
|
-
export function captureStackTrace(callingFunction) {
|
|
6
|
-
var stack = "";
|
|
7
|
-
try {
|
|
8
|
-
throw new Error("");
|
|
9
|
-
}
|
|
10
|
-
catch (e) {
|
|
11
|
-
(stack = e.stack);
|
|
12
|
-
}
|
|
13
|
-
var callerName = typeof callingFunction === "string" ? callingFunction
|
|
14
|
-
: callingFunction ? callingFunction.name
|
|
15
|
-
: undefined;
|
|
16
|
-
if (callerName && stack.includes(callerName)) {
|
|
17
|
-
var lines = stack.split("\n");
|
|
18
|
-
stack = lines
|
|
19
|
-
.slice(
|
|
20
|
-
// @ts-expect-error this is too old of a TS target, but node has it
|
|
21
|
-
lines.findLastIndex(function (line) { return line.includes(callerName); }) + 1)
|
|
22
|
-
.join("\n");
|
|
23
|
-
}
|
|
24
|
-
return stack;
|
|
25
|
-
}
|
|
26
|
-
export function applyStackTrace(error, stackTrace) {
|
|
27
|
-
error.stack = error.message + "\n" + stackTrace;
|
|
28
|
-
return error;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=traces.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"traces.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/traces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,eAAqC;IACrE,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,IAAI,CAAC;QACH,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC,CAAC;IACtB,CAAC;IAAC,OAAO,CAAM,EAAE,CAAC;QAChB,CAAG,KAAK,GAAK,CAAC,MAAN,CAAO,CAAC;IAClB,CAAC;IAED,IAAM,UAAU,GACd,OAAO,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe;QACrD,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,IAAI;YACxC,CAAC,CAAC,SAAS,CAAC;IAEd,IAAI,UAAU,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7C,IAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEhC,KAAK,GAAG,KAAK;aACV,KAAK;QACJ,mEAAmE;QACnE,KAAK,CAAC,aAAa,CAAC,UAAC,IAAY,IAAK,OAAA,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAzB,CAAyB,CAAC,GAAG,CAAC,CACrE;aACA,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAY,EAAE,UAAkB;IAC9D,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,OAAO,GAAG,IAAI,GAAG,UAAU,CAAC;IAChD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Captures a StackTrace and (if passed) cuts off\n * the first lines including the calling function.\n */\nexport function captureStackTrace(callingFunction?: string | (() => {})) {\n let stack = \"\";\n try {\n throw new Error(\"\");\n } catch (e: any) {\n ({ stack } = e);\n }\n\n const callerName =\n typeof callingFunction === \"string\" ? callingFunction\n : callingFunction ? callingFunction.name\n : undefined;\n\n if (callerName && stack.includes(callerName)) {\n const lines = stack.split(\"\\n\");\n\n stack = lines\n .slice(\n // @ts-expect-error this is too old of a TS target, but node has it\n lines.findLastIndex((line: string) => line.includes(callerName)) + 1\n )\n .join(\"\\n\");\n }\n\n return stack;\n}\n\nexport function applyStackTrace(error: Error, stackTrace: string) {\n error.stack = error.message + \"\\n\" + stackTrace;\n return error;\n}\n"]}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { MatcherFunction } from "expect";
|
|
2
|
-
import type { NextRenderOptions } from "../internal/index.js";
|
|
3
|
-
export declare const toRerender: MatcherFunction<[options?: NextRenderOptions]>;
|
|
4
|
-
export declare const toRenderExactlyTimes: MatcherFunction<[
|
|
5
|
-
times: number,
|
|
6
|
-
options?: NextRenderOptions
|
|
7
|
-
]>;
|
|
8
|
-
//# sourceMappingURL=ProfiledComponent.d.ts.map
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
|
-
import { WaitForRenderTimeoutError } from "../internal/index.js";
|
|
3
|
-
export var toRerender = function (actual, options) {
|
|
4
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
5
|
-
var _profiler, profiler, hint, pass, e_1;
|
|
6
|
-
return __generator(this, function (_a) {
|
|
7
|
-
switch (_a.label) {
|
|
8
|
-
case 0:
|
|
9
|
-
_profiler = actual;
|
|
10
|
-
profiler = "Profiler" in _profiler ? _profiler.Profiler : _profiler;
|
|
11
|
-
hint = this.utils.matcherHint("toRerender", "ProfiledComponent", "");
|
|
12
|
-
pass = true;
|
|
13
|
-
_a.label = 1;
|
|
14
|
-
case 1:
|
|
15
|
-
_a.trys.push([1, 3, , 4]);
|
|
16
|
-
return [4 /*yield*/, profiler.peekRender(__assign({ timeout: 100 }, options))];
|
|
17
|
-
case 2:
|
|
18
|
-
_a.sent();
|
|
19
|
-
return [3 /*break*/, 4];
|
|
20
|
-
case 3:
|
|
21
|
-
e_1 = _a.sent();
|
|
22
|
-
if (e_1 instanceof WaitForRenderTimeoutError) {
|
|
23
|
-
pass = false;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
throw e_1;
|
|
27
|
-
}
|
|
28
|
-
return [3 /*break*/, 4];
|
|
29
|
-
case 4: return [2 /*return*/, {
|
|
30
|
-
pass: pass,
|
|
31
|
-
message: function () {
|
|
32
|
-
return (hint +
|
|
33
|
-
"\n\nExpected component to".concat(pass ? " not" : "", " rerender, ") +
|
|
34
|
-
"but it did".concat(pass ? "" : " not", "."));
|
|
35
|
-
},
|
|
36
|
-
}];
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
/** to be thrown to "break" test execution and fail it */
|
|
42
|
-
var failed = {};
|
|
43
|
-
export var toRenderExactlyTimes = function (actual, times, optionsPerRender) {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
45
|
-
var _profiler, profiler, options, hint, pass, e_2, e_3, e_4;
|
|
46
|
-
return __generator(this, function (_a) {
|
|
47
|
-
switch (_a.label) {
|
|
48
|
-
case 0:
|
|
49
|
-
_profiler = actual;
|
|
50
|
-
profiler = "Profiler" in _profiler ? _profiler.Profiler : _profiler;
|
|
51
|
-
options = __assign({ timeout: 100 }, optionsPerRender);
|
|
52
|
-
hint = this.utils.matcherHint("toRenderExactlyTimes");
|
|
53
|
-
pass = true;
|
|
54
|
-
_a.label = 1;
|
|
55
|
-
case 1:
|
|
56
|
-
_a.trys.push([1, 11, , 12]);
|
|
57
|
-
if (profiler.totalRenderCount() > times) {
|
|
58
|
-
throw failed;
|
|
59
|
-
}
|
|
60
|
-
_a.label = 2;
|
|
61
|
-
case 2:
|
|
62
|
-
_a.trys.push([2, 6, , 7]);
|
|
63
|
-
_a.label = 3;
|
|
64
|
-
case 3:
|
|
65
|
-
if (!(profiler.totalRenderCount() < times)) return [3 /*break*/, 5];
|
|
66
|
-
return [4 /*yield*/, profiler.waitForNextRender(options)];
|
|
67
|
-
case 4:
|
|
68
|
-
_a.sent();
|
|
69
|
-
return [3 /*break*/, 3];
|
|
70
|
-
case 5: return [3 /*break*/, 7];
|
|
71
|
-
case 6:
|
|
72
|
-
e_2 = _a.sent();
|
|
73
|
-
// timeouts here should just fail the test, rethrow other errors
|
|
74
|
-
throw e_2 instanceof WaitForRenderTimeoutError ? failed : e_2;
|
|
75
|
-
case 7:
|
|
76
|
-
_a.trys.push([7, 9, , 10]);
|
|
77
|
-
return [4 /*yield*/, profiler.waitForNextRender(options)];
|
|
78
|
-
case 8:
|
|
79
|
-
_a.sent();
|
|
80
|
-
return [3 /*break*/, 10];
|
|
81
|
-
case 9:
|
|
82
|
-
e_3 = _a.sent();
|
|
83
|
-
// we are expecting a timeout here, so swallow that error, rethrow others
|
|
84
|
-
if (!(e_3 instanceof WaitForRenderTimeoutError)) {
|
|
85
|
-
throw e_3;
|
|
86
|
-
}
|
|
87
|
-
return [3 /*break*/, 10];
|
|
88
|
-
case 10: return [3 /*break*/, 12];
|
|
89
|
-
case 11:
|
|
90
|
-
e_4 = _a.sent();
|
|
91
|
-
if (e_4 === failed) {
|
|
92
|
-
pass = false;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
throw e_4;
|
|
96
|
-
}
|
|
97
|
-
return [3 /*break*/, 12];
|
|
98
|
-
case 12: return [2 /*return*/, {
|
|
99
|
-
pass: pass,
|
|
100
|
-
message: function () {
|
|
101
|
-
return (hint +
|
|
102
|
-
" Expected component to".concat(pass ? " not" : "", " render exactly ").concat(times, ".") +
|
|
103
|
-
" It rendered ".concat(profiler.totalRenderCount(), " times."));
|
|
104
|
-
},
|
|
105
|
-
}];
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
//# sourceMappingURL=ProfiledComponent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProfiledComponent.js","sourceRoot":"","sources":["../../../src/testing/matchers/ProfiledComponent.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAQjE,MAAM,CAAC,IAAM,UAAU,GACrB,UAAgB,MAAM,EAAE,OAAO;;;;;;oBACvB,SAAS,GAAG,MAGQ,CAAC;oBACrB,QAAQ,GAAG,UAAU,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;oBACpE,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,EAAE,mBAAmB,EAAE,EAAE,CAAC,CAAC;oBACvE,IAAI,GAAG,IAAI,CAAC;;;;oBAEd,qBAAM,QAAQ,CAAC,UAAU,YAAG,OAAO,EAAE,GAAG,IAAK,OAAO,EAAG,EAAA;;oBAAvD,SAAuD,CAAC;;;;oBAExD,IAAI,GAAC,YAAY,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iBAAiB,CAAC,OAAO,CAAC,EAAA;;oBAAzC,SAAyC,CAAC;;;;oBAE1C,yEAAyE;oBACzE,IAAI,CAAC,CAAC,GAAC,YAAY,yBAAyB,CAAC,EAAE,CAAC;wBAC9C,MAAM,GAAC,CAAC;oBACV,CAAC;;;;;oBAGH,IAAI,GAAC,KAAK,MAAM,EAAE,CAAC;wBACjB,IAAI,GAAG,KAAK,CAAC;oBACf,CAAC;yBAAM,CAAC;wBACN,MAAM,GAAC,CAAC;oBACV,CAAC;;yBAEH,sBAAO;wBACL,IAAI,MAAA;wBACJ,OAAO;4BACL,OAAO,CACL,IAAI;gCACJ,gCAAyB,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,6BAAmB,KAAK,MAAG;gCACtE,uBAAgB,QAAQ,CAAC,gBAAgB,EAAE,YAAS,CACrD,CAAC;wBACJ,CAAC;qBACF,EAAC;;;;CACH,CAAC","sourcesContent":["import type { MatcherFunction } from \"expect\";\nimport { WaitForRenderTimeoutError } from \"../internal/index.js\";\nimport type {\n NextRenderOptions,\n Profiler,\n ProfiledComponent,\n ProfiledHook,\n} from \"../internal/index.js\";\n\nexport const toRerender: MatcherFunction<[options?: NextRenderOptions]> =\n async function (actual, options) {\n const _profiler = actual as\n | Profiler<any>\n | ProfiledComponent<any, any>\n | ProfiledHook<any, any>;\n const profiler = \"Profiler\" in _profiler ? _profiler.Profiler : _profiler;\n const hint = this.utils.matcherHint(\"toRerender\", \"ProfiledComponent\", \"\");\n let pass = true;\n try {\n await profiler.peekRender({ timeout: 100, ...options });\n } catch (e) {\n if (e instanceof WaitForRenderTimeoutError) {\n pass = false;\n } else {\n throw e;\n }\n }\n\n return {\n pass,\n message() {\n return (\n hint +\n `\\n\\nExpected component to${pass ? \" not\" : \"\"} rerender, ` +\n `but it did${pass ? \"\" : \" not\"}.`\n );\n },\n };\n };\n\n/** to be thrown to \"break\" test execution and fail it */\nconst failed = {};\n\nexport const toRenderExactlyTimes: MatcherFunction<\n [times: number, options?: NextRenderOptions]\n> = async function (actual, times, optionsPerRender) {\n const _profiler = actual as\n | Profiler<any>\n | ProfiledComponent<any, any>\n | ProfiledHook<any, any>;\n const profiler = \"Profiler\" in _profiler ? _profiler.Profiler : _profiler;\n const options = { timeout: 100, ...optionsPerRender };\n const hint = this.utils.matcherHint(\"toRenderExactlyTimes\");\n let pass = true;\n try {\n if (profiler.totalRenderCount() > times) {\n throw failed;\n }\n try {\n while (profiler.totalRenderCount() < times) {\n await profiler.waitForNextRender(options);\n }\n } catch (e) {\n // timeouts here should just fail the test, rethrow other errors\n throw e instanceof WaitForRenderTimeoutError ? failed : e;\n }\n try {\n await profiler.waitForNextRender(options);\n } catch (e) {\n // we are expecting a timeout here, so swallow that error, rethrow others\n if (!(e instanceof WaitForRenderTimeoutError)) {\n throw e;\n }\n }\n } catch (e) {\n if (e === failed) {\n pass = false;\n } else {\n throw e;\n }\n }\n return {\n pass,\n message() {\n return (\n hint +\n ` Expected component to${pass ? \" not\" : \"\"} render exactly ${times}.` +\n ` It rendered ${profiler.totalRenderCount()} times.`\n );\n },\n };\n};\n"]}
|