@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,69 +0,0 @@
|
|
|
1
|
-
import { screen } from "@testing-library/dom";
|
|
2
|
-
/** @internal */
|
|
3
|
-
export interface BaseRender {
|
|
4
|
-
id: string;
|
|
5
|
-
phase: "mount" | "update" | "nested-update";
|
|
6
|
-
actualDuration: number;
|
|
7
|
-
baseDuration: number;
|
|
8
|
-
startTime: number;
|
|
9
|
-
commitTime: number;
|
|
10
|
-
/**
|
|
11
|
-
* The number of renders that have happened so far (including this render).
|
|
12
|
-
*/
|
|
13
|
-
count: number;
|
|
14
|
-
}
|
|
15
|
-
type Screen = typeof screen;
|
|
16
|
-
/** @internal */
|
|
17
|
-
export type SyncScreen = {
|
|
18
|
-
[K in keyof Screen]: K extends `find${string}` ? {
|
|
19
|
-
/** @deprecated A snapshot is static, so avoid async queries! */
|
|
20
|
-
(...args: Parameters<Screen[K]>): ReturnType<Screen[K]>;
|
|
21
|
-
} : Screen[K];
|
|
22
|
-
};
|
|
23
|
-
/** @internal */
|
|
24
|
-
export interface Render<Snapshot> extends BaseRender {
|
|
25
|
-
/**
|
|
26
|
-
* The snapshot, as returned by the `takeSnapshot` option of `profile`.
|
|
27
|
-
* (If using `profileHook`, this is the return value of the hook.)
|
|
28
|
-
*/
|
|
29
|
-
snapshot: Snapshot;
|
|
30
|
-
/**
|
|
31
|
-
* A DOM snapshot of the rendered component, if the `snapshotDOM`
|
|
32
|
-
* option of `profile` was enabled.
|
|
33
|
-
*/
|
|
34
|
-
readonly domSnapshot: HTMLElement;
|
|
35
|
-
/**
|
|
36
|
-
* Returns a callback to receive a `screen` instance that is scoped to the
|
|
37
|
-
* DOM snapshot of this `Render` instance.
|
|
38
|
-
* Note: this is used as a callback to prevent linter errors.
|
|
39
|
-
* @example
|
|
40
|
-
* ```diff
|
|
41
|
-
* const { withinDOM } = RenderedComponent.takeRender();
|
|
42
|
-
* -expect(screen.getByText("foo")).toBeInTheDocument();
|
|
43
|
-
* +expect(withinDOM().getByText("foo")).toBeInTheDocument();
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
withinDOM: () => SyncScreen;
|
|
47
|
-
renderedComponents: Array<string | React.ComponentType>;
|
|
48
|
-
}
|
|
49
|
-
/** @internal */
|
|
50
|
-
export declare class RenderInstance<Snapshot> implements Render<Snapshot> {
|
|
51
|
-
snapshot: Snapshot;
|
|
52
|
-
private stringifiedDOM;
|
|
53
|
-
renderedComponents: Array<string | React.ComponentType>;
|
|
54
|
-
id: string;
|
|
55
|
-
phase: "mount" | "update" | "nested-update";
|
|
56
|
-
actualDuration: number;
|
|
57
|
-
baseDuration: number;
|
|
58
|
-
startTime: number;
|
|
59
|
-
commitTime: number;
|
|
60
|
-
count: number;
|
|
61
|
-
constructor(baseRender: BaseRender, snapshot: Snapshot, stringifiedDOM: string | undefined, renderedComponents: Array<string | React.ComponentType>);
|
|
62
|
-
private _domSnapshot;
|
|
63
|
-
get domSnapshot(): HTMLElement;
|
|
64
|
-
get withinDOM(): () => SyncScreen;
|
|
65
|
-
}
|
|
66
|
-
/** @internal */
|
|
67
|
-
export declare function errorOnDomInteraction(): void;
|
|
68
|
-
export {};
|
|
69
|
-
//# sourceMappingURL=Render.d.ts.map
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
import { __spreadArray } from "tslib";
|
|
3
|
-
/*
|
|
4
|
-
Something in this file does not compile correctly while measuring code coverage
|
|
5
|
-
and will lead to a
|
|
6
|
-
Uncaught [ReferenceError: cov_1zb8w312au is not defined]
|
|
7
|
-
if we do not ignore this file in code coverage.
|
|
8
|
-
|
|
9
|
-
As we only use this file in our internal tests, we can safely ignore it.
|
|
10
|
-
*/
|
|
11
|
-
import { within, screen } from "@testing-library/dom";
|
|
12
|
-
import { JSDOM, VirtualConsole } from "jsdom";
|
|
13
|
-
import { applyStackTrace, captureStackTrace } from "./traces.js";
|
|
14
|
-
/** @internal */
|
|
15
|
-
var RenderInstance = /** @class */ (function () {
|
|
16
|
-
function RenderInstance(baseRender, snapshot, stringifiedDOM, renderedComponents) {
|
|
17
|
-
this.snapshot = snapshot;
|
|
18
|
-
this.stringifiedDOM = stringifiedDOM;
|
|
19
|
-
this.renderedComponents = renderedComponents;
|
|
20
|
-
this.id = baseRender.id;
|
|
21
|
-
this.phase = baseRender.phase;
|
|
22
|
-
this.actualDuration = baseRender.actualDuration;
|
|
23
|
-
this.baseDuration = baseRender.baseDuration;
|
|
24
|
-
this.startTime = baseRender.startTime;
|
|
25
|
-
this.commitTime = baseRender.commitTime;
|
|
26
|
-
this.count = baseRender.count;
|
|
27
|
-
}
|
|
28
|
-
Object.defineProperty(RenderInstance.prototype, "domSnapshot", {
|
|
29
|
-
get: function () {
|
|
30
|
-
if (this._domSnapshot)
|
|
31
|
-
return this._domSnapshot;
|
|
32
|
-
if (!this.stringifiedDOM) {
|
|
33
|
-
throw new Error("DOM snapshot is not available - please set the `snapshotDOM` option");
|
|
34
|
-
}
|
|
35
|
-
var virtualConsole = new VirtualConsole();
|
|
36
|
-
var stackTrace = captureStackTrace("RenderInstance.get");
|
|
37
|
-
virtualConsole.on("jsdomError", function (error) {
|
|
38
|
-
throw applyStackTrace(error, stackTrace);
|
|
39
|
-
});
|
|
40
|
-
var snapDOM = new JSDOM(this.stringifiedDOM, {
|
|
41
|
-
runScripts: "dangerously",
|
|
42
|
-
virtualConsole: virtualConsole,
|
|
43
|
-
});
|
|
44
|
-
var document = snapDOM.window.document;
|
|
45
|
-
var body = document.body;
|
|
46
|
-
var script = document.createElement("script");
|
|
47
|
-
script.type = "text/javascript";
|
|
48
|
-
script.text = "\n ".concat(errorOnDomInteraction.toString(), ";\n ").concat(errorOnDomInteraction.name, "();\n ");
|
|
49
|
-
body.appendChild(script);
|
|
50
|
-
body.removeChild(script);
|
|
51
|
-
return (this._domSnapshot = body);
|
|
52
|
-
},
|
|
53
|
-
enumerable: false,
|
|
54
|
-
configurable: true
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(RenderInstance.prototype, "withinDOM", {
|
|
57
|
-
get: function () {
|
|
58
|
-
var _this = this;
|
|
59
|
-
var snapScreen = Object.assign(within(this.domSnapshot), {
|
|
60
|
-
debug: function () {
|
|
61
|
-
var _a = [];
|
|
62
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
63
|
-
_a[_i] = arguments[_i];
|
|
64
|
-
}
|
|
65
|
-
var _b = _a[0], dom = _b === void 0 ? _this.domSnapshot : _b, rest = _a.slice(1);
|
|
66
|
-
return screen.debug.apply(screen, __spreadArray([dom], rest, false));
|
|
67
|
-
},
|
|
68
|
-
logTestingPlaygroundURL: function () {
|
|
69
|
-
var _a = [];
|
|
70
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
71
|
-
_a[_i] = arguments[_i];
|
|
72
|
-
}
|
|
73
|
-
var _b = _a[0], dom = _b === void 0 ? _this.domSnapshot : _b, rest = _a.slice(1);
|
|
74
|
-
return screen.logTestingPlaygroundURL.apply(screen, __spreadArray([dom], rest, false));
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
return function () { return snapScreen; };
|
|
78
|
-
},
|
|
79
|
-
enumerable: false,
|
|
80
|
-
configurable: true
|
|
81
|
-
});
|
|
82
|
-
return RenderInstance;
|
|
83
|
-
}());
|
|
84
|
-
export { RenderInstance };
|
|
85
|
-
/** @internal */
|
|
86
|
-
export function errorOnDomInteraction() {
|
|
87
|
-
var events = [
|
|
88
|
-
"auxclick",
|
|
89
|
-
"blur",
|
|
90
|
-
"change",
|
|
91
|
-
"click",
|
|
92
|
-
"copy",
|
|
93
|
-
"cut",
|
|
94
|
-
"dblclick",
|
|
95
|
-
"drag",
|
|
96
|
-
"dragend",
|
|
97
|
-
"dragenter",
|
|
98
|
-
"dragleave",
|
|
99
|
-
"dragover",
|
|
100
|
-
"dragstart",
|
|
101
|
-
"drop",
|
|
102
|
-
"focus",
|
|
103
|
-
"focusin",
|
|
104
|
-
"focusout",
|
|
105
|
-
"input",
|
|
106
|
-
"keydown",
|
|
107
|
-
"keypress",
|
|
108
|
-
"keyup",
|
|
109
|
-
"mousedown",
|
|
110
|
-
"mouseenter",
|
|
111
|
-
"mouseleave",
|
|
112
|
-
"mousemove",
|
|
113
|
-
"mouseout",
|
|
114
|
-
"mouseover",
|
|
115
|
-
"mouseup",
|
|
116
|
-
"paste",
|
|
117
|
-
"pointercancel",
|
|
118
|
-
"pointerdown",
|
|
119
|
-
"pointerenter",
|
|
120
|
-
"pointerleave",
|
|
121
|
-
"pointermove",
|
|
122
|
-
"pointerout",
|
|
123
|
-
"pointerover",
|
|
124
|
-
"pointerup",
|
|
125
|
-
"scroll",
|
|
126
|
-
"select",
|
|
127
|
-
"selectionchange",
|
|
128
|
-
"selectstart",
|
|
129
|
-
"submit",
|
|
130
|
-
"toggle",
|
|
131
|
-
"touchcancel",
|
|
132
|
-
"touchend",
|
|
133
|
-
"touchmove",
|
|
134
|
-
"touchstart",
|
|
135
|
-
"wheel",
|
|
136
|
-
];
|
|
137
|
-
function warnOnDomInteraction() {
|
|
138
|
-
throw new Error("\n DOM interaction with a snapshot detected in test.\n Please don't interact with the DOM you get from `withinDOM`,\n but still use `screen' to get elements for simulating user interaction.\n ");
|
|
139
|
-
}
|
|
140
|
-
events.forEach(function (event) {
|
|
141
|
-
document.addEventListener(event, warnOnDomInteraction);
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
//# sourceMappingURL=Render.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Render.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/Render.tsx"],"names":[],"mappings":"AAAA,0BAA0B;;AAE1B;;;;;;;EAOE;AAEF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M,iBAAyB,GAAG,GAAK,IAAI;gBAA3C,CAA4C;aAClD,CAAC,CAAC;YACH,OAAO,cAAM,OAAA,UAAU,EAAV,CAAU,CAAC;QAC1B,CAAC;;;OAAA;IACH,qBAAC;AAAD,CAAC,AAtED,IAsEC;;AACD,gBAAgB;AAChB,MAAM,UAAU,qBAAqB;IACnC,IAAM,MAAM,GAAkC;QAC5C,UAAU;QACV,MAAM;QACN,QAAQ;QACR,OAAO;QACP,MAAM;QACN,KAAK;QACL,UAAU;QACV,MAAM;QACN,SAAS;QACT,WAAW;QACX,WAAW;QACX,UAAU;QACV,WAAW;QACX,MAAM;QACN,OAAO;QACP,SAAS;QACT,UAAU;QACV,OAAO;QACP,SAAS;QACT,UAAU;QACV,OAAO;QACP,WAAW;QACX,YAAY;QACZ,YAAY;QACZ,WAAW;QACX,UAAU;QACV,WAAW;QACX,SAAS;QACT,OAAO;QACP,eAAe;QACf,aAAa;QACb,cAAc;QACd,cAAc;QACd,aAAa;QACb,YAAY;QACZ,aAAa;QACb,WAAW;QACX,QAAQ;QACR,QAAQ;QACR,iBAAiB;QACjB,aAAa;QACb,QAAQ;QACR,QAAQ;QACR,aAAa;QACb,UAAU;QACV,WAAW;QACX,YAAY;QACZ,OAAO;KACR,CAAC;IACF,SAAS,oBAAoB;QAC3B,MAAM,IAAI,KAAK,CAAC,8MAIf,CAAC,CAAC;IACL,CAAC;IACD,MAAM,CAAC,OAAO,CAAC,UAAC,KAAK;QACnB,QAAQ,CAAC,gBAAgB,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/* istanbul ignore file */\n\n/*\nSomething in this file does not compile correctly while measuring code coverage\nand will lead to a\n Uncaught [ReferenceError: cov_1zb8w312au is not defined]\nif we do not ignore this file in code coverage.\n\nAs we only use this file in our internal tests, we can safely ignore it.\n*/\n\nimport { within, screen } from \"@testing-library/dom\";\nimport { JSDOM, VirtualConsole } from \"jsdom\";\nimport { applyStackTrace, captureStackTrace } from \"./traces.js\";\n\n/** @internal */\nexport interface BaseRender {\n id: string;\n phase: \"mount\" | \"update\" | \"nested-update\";\n actualDuration: number;\n baseDuration: number;\n startTime: number;\n commitTime: number;\n /**\n * The number of renders that have happened so far (including this render).\n */\n count: number;\n}\n\ntype Screen = typeof screen;\n/** @internal */\nexport type SyncScreen = {\n [K in keyof Screen]: K extends `find${string}` ?\n {\n /** @deprecated A snapshot is static, so avoid async queries! */\n (...args: Parameters<Screen[K]>): ReturnType<Screen[K]>;\n }\n : Screen[K];\n};\n\n/** @internal */\nexport interface Render<Snapshot> extends BaseRender {\n /**\n * The snapshot, as returned by the `takeSnapshot` option of `profile`.\n * (If using `profileHook`, this is the return value of the hook.)\n */\n snapshot: Snapshot;\n /**\n * A DOM snapshot of the rendered component, if the `snapshotDOM`\n * option of `profile` was enabled.\n */\n readonly domSnapshot: HTMLElement;\n /**\n * Returns a callback to receive a `screen` instance that is scoped to the\n * DOM snapshot of this `Render` instance.\n * Note: this is used as a callback to prevent linter errors.\n * @example\n * ```diff\n * const { withinDOM } = RenderedComponent.takeRender();\n * -expect(screen.getByText(\"foo\")).toBeInTheDocument();\n * +expect(withinDOM().getByText(\"foo\")).toBeInTheDocument();\n * ```\n */\n withinDOM: () => SyncScreen;\n\n renderedComponents: Array<string | React.ComponentType>;\n}\n\n/** @internal */\nexport class RenderInstance<Snapshot> implements Render<Snapshot> {\n id: string;\n phase: \"mount\" | \"update\" | \"nested-update\";\n actualDuration: number;\n baseDuration: number;\n startTime: number;\n commitTime: number;\n count: number;\n\n constructor(\n baseRender: BaseRender,\n public snapshot: Snapshot,\n private stringifiedDOM: string | undefined,\n public renderedComponents: Array<string | React.ComponentType>\n ) {\n this.id = baseRender.id;\n this.phase = baseRender.phase;\n this.actualDuration = baseRender.actualDuration;\n this.baseDuration = baseRender.baseDuration;\n this.startTime = baseRender.startTime;\n this.commitTime = baseRender.commitTime;\n this.count = baseRender.count;\n }\n\n private _domSnapshot: HTMLElement | undefined;\n get domSnapshot() {\n if (this._domSnapshot) return this._domSnapshot;\n if (!this.stringifiedDOM) {\n throw new Error(\n \"DOM snapshot is not available - please set the `snapshotDOM` option\"\n );\n }\n\n const virtualConsole = new VirtualConsole();\n const stackTrace = captureStackTrace(\"RenderInstance.get\");\n virtualConsole.on(\"jsdomError\", (error) => {\n throw applyStackTrace(error, stackTrace);\n });\n\n const snapDOM = new JSDOM(this.stringifiedDOM, {\n runScripts: \"dangerously\",\n virtualConsole,\n });\n const document = snapDOM.window.document;\n const body = document.body;\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n script.text = `\n ${errorOnDomInteraction.toString()};\n ${errorOnDomInteraction.name}();\n `;\n body.appendChild(script);\n body.removeChild(script);\n\n return (this._domSnapshot = body);\n }\n\n get withinDOM(): () => SyncScreen {\n const snapScreen = Object.assign(within(this.domSnapshot), {\n debug: (\n ...[dom = this.domSnapshot, ...rest]: Parameters<typeof screen.debug>\n ) => screen.debug(dom, ...rest),\n logTestingPlaygroundURL: (\n ...[dom = this.domSnapshot, ...rest]: Parameters<\n typeof screen.logTestingPlaygroundURL\n >\n ) => screen.logTestingPlaygroundURL(dom, ...rest),\n });\n return () => snapScreen;\n }\n}\n/** @internal */\nexport function errorOnDomInteraction() {\n const events: Array<keyof DocumentEventMap> = [\n \"auxclick\",\n \"blur\",\n \"change\",\n \"click\",\n \"copy\",\n \"cut\",\n \"dblclick\",\n \"drag\",\n \"dragend\",\n \"dragenter\",\n \"dragleave\",\n \"dragover\",\n \"dragstart\",\n \"drop\",\n \"focus\",\n \"focusin\",\n \"focusout\",\n \"input\",\n \"keydown\",\n \"keypress\",\n \"keyup\",\n \"mousedown\",\n \"mouseenter\",\n \"mouseleave\",\n \"mousemove\",\n \"mouseout\",\n \"mouseover\",\n \"mouseup\",\n \"paste\",\n \"pointercancel\",\n \"pointerdown\",\n \"pointerenter\",\n \"pointerleave\",\n \"pointermove\",\n \"pointerout\",\n \"pointerover\",\n \"pointerup\",\n \"scroll\",\n \"select\",\n \"selectionchange\",\n \"selectstart\",\n \"submit\",\n \"toggle\",\n \"touchcancel\",\n \"touchend\",\n \"touchmove\",\n \"touchstart\",\n \"wheel\",\n ];\n function warnOnDomInteraction() {\n throw new Error(`\n DOM interaction with a snapshot detected in test.\n Please don't interact with the DOM you get from \\`withinDOM\\`,\n but still use \\`screen\\' to get elements for simulating user interaction.\n `);\n }\n events.forEach((event) => {\n document.addEventListener(event, warnOnDomInteraction);\n });\n}\n"]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
export interface ProfilerContextValue {
|
|
3
|
-
renderedComponents: Array<React.ComponentType | string>;
|
|
4
|
-
}
|
|
5
|
-
export declare function ProfilerContextProvider({ children, value, }: {
|
|
6
|
-
children: React.ReactNode;
|
|
7
|
-
value: ProfilerContextValue;
|
|
8
|
-
}): React.JSX.Element;
|
|
9
|
-
export declare function useProfilerContext(): ProfilerContextValue | undefined;
|
|
10
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
var ProfilerContext = React.createContext(undefined);
|
|
3
|
-
export function ProfilerContextProvider(_a) {
|
|
4
|
-
var children = _a.children, value = _a.value;
|
|
5
|
-
var parentContext = useProfilerContext();
|
|
6
|
-
if (parentContext) {
|
|
7
|
-
throw new Error("Profilers should not be nested in the same tree");
|
|
8
|
-
}
|
|
9
|
-
return (React.createElement(ProfilerContext.Provider, { value: value }, children));
|
|
10
|
-
}
|
|
11
|
-
export function useProfilerContext() {
|
|
12
|
-
return React.useContext(ProfilerContext);
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,IAAM,eAAe,GAAG,KAAK,CAAC,aAAa,CACzC,SAAS,CACV,CAAC;AAEF,MAAM,UAAU,uBAAuB,CAAC,EAMvC;QALC,QAAQ,cAAA,EACR,KAAK,WAAA;IAKL,IAAM,aAAa,GAAG,kBAAkB,EAAE,CAAC;IAE3C,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,CACL,oBAAC,eAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IACnC,QAAQ,CACgB,CAC5B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,kBAAkB;IAChC,OAAO,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import * as React from \"react\";\n\nexport interface ProfilerContextValue {\n renderedComponents: Array<React.ComponentType | string>;\n}\n\nconst ProfilerContext = React.createContext<ProfilerContextValue | undefined>(\n undefined\n);\n\nexport function ProfilerContextProvider({\n children,\n value,\n}: {\n children: React.ReactNode;\n value: ProfilerContextValue;\n}) {\n const parentContext = useProfilerContext();\n\n if (parentContext) {\n throw new Error(\"Profilers should not be nested in the same tree\");\n }\n\n return (\n <ProfilerContext.Provider value={value}>\n {children}\n </ProfilerContext.Provider>\n );\n}\n\nexport function useProfilerContext() {\n return React.useContext(ProfilerContext);\n}\n"]}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export type { NextRenderOptions, Profiler, ProfiledComponent, ProfiledHook, } from "./profile.js";
|
|
2
|
-
export { createProfiler, profile, profileHook, useTrackRenders, WaitForRenderTimeoutError, } from "./profile.js";
|
|
3
|
-
export type { SyncScreen } from "./Render.js";
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/testing/internal/profile/index.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,cAAc,EACd,OAAO,EACP,WAAW,EACX,eAAe,EACf,yBAAyB,GAC1B,MAAM,cAAc,CAAC","sourcesContent":["export type {\n NextRenderOptions,\n Profiler,\n ProfiledComponent,\n ProfiledHook,\n} from \"./profile.js\";\nexport {\n createProfiler,\n profile,\n profileHook,\n useTrackRenders,\n WaitForRenderTimeoutError,\n} from \"./profile.js\";\n\nexport type { SyncScreen } from \"./Render.js\";\n"]}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import type { Render, BaseRender } from "./Render.js";
|
|
3
|
-
type ValidSnapshot = void | (object & {
|
|
4
|
-
call?: never;
|
|
5
|
-
});
|
|
6
|
-
/** only used for passing around data internally */
|
|
7
|
-
declare const _stackTrace: unique symbol;
|
|
8
|
-
/** @internal */
|
|
9
|
-
export interface NextRenderOptions {
|
|
10
|
-
timeout?: number;
|
|
11
|
-
[_stackTrace]?: string;
|
|
12
|
-
}
|
|
13
|
-
/** @internal */
|
|
14
|
-
interface ProfilerProps {
|
|
15
|
-
children: React.ReactNode;
|
|
16
|
-
}
|
|
17
|
-
/** @internal */
|
|
18
|
-
export interface Profiler<Snapshot> extends React.FC<ProfilerProps>, ProfiledComponentFields<Snapshot>, ProfiledComponentOnlyFields<Snapshot> {
|
|
19
|
-
}
|
|
20
|
-
interface ReplaceSnapshot<Snapshot> {
|
|
21
|
-
(newSnapshot: Snapshot): void;
|
|
22
|
-
(updateSnapshot: (lastSnapshot: Readonly<Snapshot>) => Snapshot): void;
|
|
23
|
-
}
|
|
24
|
-
interface MergeSnapshot<Snapshot> {
|
|
25
|
-
(partialSnapshot: Partial<Snapshot>): void;
|
|
26
|
-
(updatePartialSnapshot: (lastSnapshot: Readonly<Snapshot>) => Partial<Snapshot>): void;
|
|
27
|
-
}
|
|
28
|
-
interface ProfiledComponentOnlyFields<Snapshot> {
|
|
29
|
-
mergeSnapshot: MergeSnapshot<Snapshot>;
|
|
30
|
-
replaceSnapshot: ReplaceSnapshot<Snapshot>;
|
|
31
|
-
}
|
|
32
|
-
interface ProfiledComponentFields<Snapshot> {
|
|
33
|
-
/**
|
|
34
|
-
* An array of all renders that have happened so far.
|
|
35
|
-
* Errors thrown during component render will be captured here, too.
|
|
36
|
-
*/
|
|
37
|
-
renders: Array<Render<Snapshot> | {
|
|
38
|
-
phase: "snapshotError";
|
|
39
|
-
count: number;
|
|
40
|
-
error: unknown;
|
|
41
|
-
}>;
|
|
42
|
-
/**
|
|
43
|
-
* Peeks the next render from the current iterator position, without advancing the iterator.
|
|
44
|
-
* If no render has happened yet, it will wait for the next render to happen.
|
|
45
|
-
* @throws {WaitForRenderTimeoutError} if no render happens within the timeout
|
|
46
|
-
*/
|
|
47
|
-
peekRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;
|
|
48
|
-
/**
|
|
49
|
-
* Iterates to the next render and returns it.
|
|
50
|
-
* If no render has happened yet, it will wait for the next render to happen.
|
|
51
|
-
* @throws {WaitForRenderTimeoutError} if no render happens within the timeout
|
|
52
|
-
*/
|
|
53
|
-
takeRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;
|
|
54
|
-
/**
|
|
55
|
-
* Returns the total number of renders.
|
|
56
|
-
*/
|
|
57
|
-
totalRenderCount(): number;
|
|
58
|
-
/**
|
|
59
|
-
* Returns the current render.
|
|
60
|
-
* @throws {Error} if no render has happened yet
|
|
61
|
-
*/
|
|
62
|
-
getCurrentRender(): Render<Snapshot>;
|
|
63
|
-
/**
|
|
64
|
-
* Waits for the next render to happen.
|
|
65
|
-
* Does not advance the render iterator.
|
|
66
|
-
*/
|
|
67
|
-
waitForNextRender(options?: NextRenderOptions): Promise<Render<Snapshot>>;
|
|
68
|
-
}
|
|
69
|
-
export interface ProfiledComponent<Snapshot extends ValidSnapshot, Props = {}> extends React.FC<Props>, ProfiledComponentFields<Snapshot>, ProfiledComponentOnlyFields<Snapshot> {
|
|
70
|
-
}
|
|
71
|
-
/** @internal */
|
|
72
|
-
export declare function profile<Snapshot extends ValidSnapshot = void, Props = {}>({ Component, ...options }: Parameters<typeof createProfiler<Snapshot>>[0] & {
|
|
73
|
-
Component: React.ComponentType<Props>;
|
|
74
|
-
}): ProfiledComponent<Snapshot, Props>;
|
|
75
|
-
/** @internal */
|
|
76
|
-
export declare function createProfiler<Snapshot extends ValidSnapshot = void>({ onRender, snapshotDOM, initialSnapshot, skipNonTrackingRenders, }?: {
|
|
77
|
-
onRender?: (info: BaseRender & {
|
|
78
|
-
snapshot: Snapshot;
|
|
79
|
-
replaceSnapshot: ReplaceSnapshot<Snapshot>;
|
|
80
|
-
mergeSnapshot: MergeSnapshot<Snapshot>;
|
|
81
|
-
}) => void;
|
|
82
|
-
snapshotDOM?: boolean;
|
|
83
|
-
initialSnapshot?: Snapshot;
|
|
84
|
-
/**
|
|
85
|
-
* This will skip renders during which no renders tracked by
|
|
86
|
-
* `useTrackRenders` occured.
|
|
87
|
-
*/
|
|
88
|
-
skipNonTrackingRenders?: boolean;
|
|
89
|
-
}): Profiler<Snapshot>;
|
|
90
|
-
/** @internal */
|
|
91
|
-
export declare class WaitForRenderTimeoutError extends Error {
|
|
92
|
-
constructor();
|
|
93
|
-
}
|
|
94
|
-
type StringReplaceRenderWithSnapshot<T extends string> = T extends `${infer Pre}Render${infer Post}` ? `${Pre}Snapshot${Post}` : T;
|
|
95
|
-
type ResultReplaceRenderWithSnapshot<T> = T extends (...args: infer Args) => Render<infer Snapshot> ? (...args: Args) => Snapshot : T extends (...args: infer Args) => Promise<Render<infer Snapshot>> ? (...args: Args) => Promise<Snapshot> : T;
|
|
96
|
-
type ProfiledHookFields<ReturnValue> = ProfiledComponentFields<ReturnValue> extends infer PC ? {
|
|
97
|
-
[K in keyof PC as StringReplaceRenderWithSnapshot<K & string>]: ResultReplaceRenderWithSnapshot<PC[K]>;
|
|
98
|
-
} : never;
|
|
99
|
-
/** @internal */
|
|
100
|
-
export interface ProfiledHook<Props, ReturnValue> extends React.FC<Props>, ProfiledHookFields<ReturnValue> {
|
|
101
|
-
Profiler: Profiler<ReturnValue>;
|
|
102
|
-
}
|
|
103
|
-
/** @internal */
|
|
104
|
-
export declare function profileHook<ReturnValue extends ValidSnapshot, Props>(renderCallback: (props: Props) => ReturnValue): ProfiledHook<Props, ReturnValue>;
|
|
105
|
-
export declare function useTrackRenders({ name }?: {
|
|
106
|
-
name?: string;
|
|
107
|
-
}): void;
|
|
108
|
-
export {};
|
|
109
|
-
//# sourceMappingURL=profile.d.ts.map
|