Initial Sample.

This commit is contained in:
2024-06-03 20:23:50 +05:30
parent ef2b65f673
commit 5269ec3c66
2575 changed files with 282312 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
import type { MatcherFunction } from "expect";
import type { NextRenderOptions } from "../internal/index.js";
export declare const toRerender: MatcherFunction<[options?: NextRenderOptions]>;
export declare const toRenderExactlyTimes: MatcherFunction<[
times: number,
options?: NextRenderOptions
]>;
//# sourceMappingURL=ProfiledComponent.d.ts.map

View File

@@ -0,0 +1,110 @@
import { __assign, __awaiter, __generator } from "tslib";
import { WaitForRenderTimeoutError } from "../internal/index.js";
export var toRerender = function (actual, options) {
return __awaiter(this, void 0, void 0, function () {
var _profiler, profiler, hint, pass, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_profiler = actual;
profiler = "Profiler" in _profiler ? _profiler.Profiler : _profiler;
hint = this.utils.matcherHint("toRerender", "ProfiledComponent", "");
pass = true;
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4 /*yield*/, profiler.peekRender(__assign({ timeout: 100 }, options))];
case 2:
_a.sent();
return [3 /*break*/, 4];
case 3:
e_1 = _a.sent();
if (e_1 instanceof WaitForRenderTimeoutError) {
pass = false;
}
else {
throw e_1;
}
return [3 /*break*/, 4];
case 4: return [2 /*return*/, {
pass: pass,
message: function () {
return (hint +
"\n\nExpected component to".concat(pass ? " not" : "", " rerender, ") +
"but it did".concat(pass ? "" : " not", "."));
},
}];
}
});
});
};
/** to be thrown to "break" test execution and fail it */
var failed = {};
export var toRenderExactlyTimes = function (actual, times, optionsPerRender) {
return __awaiter(this, void 0, void 0, function () {
var _profiler, profiler, options, hint, pass, e_2, e_3, e_4;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_profiler = actual;
profiler = "Profiler" in _profiler ? _profiler.Profiler : _profiler;
options = __assign({ timeout: 100 }, optionsPerRender);
hint = this.utils.matcherHint("toRenderExactlyTimes");
pass = true;
_a.label = 1;
case 1:
_a.trys.push([1, 11, , 12]);
if (profiler.totalRenderCount() > times) {
throw failed;
}
_a.label = 2;
case 2:
_a.trys.push([2, 6, , 7]);
_a.label = 3;
case 3:
if (!(profiler.totalRenderCount() < times)) return [3 /*break*/, 5];
return [4 /*yield*/, profiler.waitForNextRender(options)];
case 4:
_a.sent();
return [3 /*break*/, 3];
case 5: return [3 /*break*/, 7];
case 6:
e_2 = _a.sent();
// timeouts here should just fail the test, rethrow other errors
throw e_2 instanceof WaitForRenderTimeoutError ? failed : e_2;
case 7:
_a.trys.push([7, 9, , 10]);
return [4 /*yield*/, profiler.waitForNextRender(options)];
case 8:
_a.sent();
return [3 /*break*/, 10];
case 9:
e_3 = _a.sent();
// we are expecting a timeout here, so swallow that error, rethrow others
if (!(e_3 instanceof WaitForRenderTimeoutError)) {
throw e_3;
}
return [3 /*break*/, 10];
case 10: return [3 /*break*/, 12];
case 11:
e_4 = _a.sent();
if (e_4 === failed) {
pass = false;
}
else {
throw e_4;
}
return [3 /*break*/, 12];
case 12: return [2 /*return*/, {
pass: pass,
message: function () {
return (hint +
" Expected component to".concat(pass ? " not" : "", " render exactly ").concat(times, ".") +
" It rendered ".concat(profiler.totalRenderCount(), " times."));
},
}];
}
});
});
};
//# sourceMappingURL=ProfiledComponent.js.map

View File

@@ -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,yBAAyB,EAAE,CAAC;wBAC3C,IAAI,GAAG,KAAK,CAAC;oBACf,CAAC;yBAAM,CAAC;wBACN,MAAM,GAAC,CAAC;oBACV,CAAC;;wBAGH,sBAAO;wBACL,IAAI,MAAA;wBACJ,OAAO;4BACL,OAAO,CACL,IAAI;gCACJ,mCAA4B,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,gBAAa;gCAC3D,oBAAa,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,MAAG,CACnC,CAAC;wBACJ,CAAC;qBACF,EAAC;;;;CACH,CAAC;AAEJ,yDAAyD;AACzD,IAAM,MAAM,GAAG,EAAE,CAAC;AAElB,MAAM,CAAC,IAAM,oBAAoB,GAE7B,UAAgB,MAAM,EAAE,KAAK,EAAE,gBAAgB;;;;;;oBAC3C,SAAS,GAAG,MAGQ,CAAC;oBACrB,QAAQ,GAAG,UAAU,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;oBACpE,OAAO,cAAK,OAAO,EAAE,GAAG,IAAK,gBAAgB,CAAE,CAAC;oBAChD,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,sBAAsB,CAAC,CAAC;oBACxD,IAAI,GAAG,IAAI,CAAC;;;;oBAEd,IAAI,QAAQ,CAAC,gBAAgB,EAAE,GAAG,KAAK,EAAE,CAAC;wBACxC,MAAM,MAAM,CAAC;oBACf,CAAC;;;;;;yBAEQ,CAAA,QAAQ,CAAC,gBAAgB,EAAE,GAAG,KAAK,CAAA;oBACxC,qBAAM,QAAQ,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAA;;oBAAzC,SAAyC,CAAC;;;;;oBAG5C,gEAAgE;oBAChE,MAAM,GAAC,YAAY,yBAAyB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAC,CAAC;;;oBAG1D,qBAAM,QAAQ,CAAC,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"]}

View File

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,15 @@
import { expect } from "@jest/globals";
import { toMatchDocument } from "./toMatchDocument.js";
import { toHaveSuspenseCacheEntryUsing } from "./toHaveSuspenseCacheEntryUsing.js";
import { toRerender, toRenderExactlyTimes } from "./ProfiledComponent.js";
import { toBeGarbageCollected } from "./toBeGarbageCollected.js";
import { toBeDisposed } from "./toBeDisposed.js";
expect.extend({
toBeDisposed: toBeDisposed,
toHaveSuspenseCacheEntryUsing: toHaveSuspenseCacheEntryUsing,
toMatchDocument: toMatchDocument,
toRerender: toRerender,
toRenderExactlyTimes: toRenderExactlyTimes,
toBeGarbageCollected: toBeGarbageCollected,
});
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testing/matchers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,CAAC,MAAM,CAAC;IACZ,YAAY,cAAA;IACZ,6BAA6B,+BAAA;IAC7B,eAAe,iBAAA;IACf,UAAU,YAAA;IACV,oBAAoB,sBAAA;IACpB,oBAAoB,sBAAA;CACrB,CAAC,CAAC","sourcesContent":["import { expect } from \"@jest/globals\";\nimport { toMatchDocument } from \"./toMatchDocument.js\";\nimport { toHaveSuspenseCacheEntryUsing } from \"./toHaveSuspenseCacheEntryUsing.js\";\nimport { toRerender, toRenderExactlyTimes } from \"./ProfiledComponent.js\";\nimport { toBeGarbageCollected } from \"./toBeGarbageCollected.js\";\nimport { toBeDisposed } from \"./toBeDisposed.js\";\n\nexpect.extend({\n toBeDisposed,\n toHaveSuspenseCacheEntryUsing,\n toMatchDocument,\n toRerender,\n toRenderExactlyTimes,\n toBeGarbageCollected,\n});\n"]}

View File

@@ -0,0 +1,3 @@
import type { MatcherFunction } from "expect";
export declare const toBeDisposed: MatcherFunction<[]>;
//# sourceMappingURL=toBeDisposed.d.ts.map

View File

@@ -0,0 +1,26 @@
import { InternalQueryReference, unwrapQueryRef, } from "../../react/internal/index.js";
function isQueryRef(queryRef) {
try {
return unwrapQueryRef(queryRef) instanceof InternalQueryReference;
}
catch (e) {
return false;
}
}
export var toBeDisposed = function (queryRef) {
var _this = this;
var hint = this.utils.matcherHint("toBeDisposed", "queryRef", "", {
isNot: this.isNot,
});
if (!isQueryRef(queryRef)) {
throw new Error("\n".concat(hint, "\n\nmust be called with a valid QueryReference"));
}
var pass = unwrapQueryRef(queryRef).disposed;
return {
pass: pass,
message: function () {
return "".concat(hint, "\n\nExpected queryRef ").concat(_this.isNot ? "not " : "", "to be disposed, but it was").concat(_this.isNot ? "" : " not", ".");
},
};
};
//# sourceMappingURL=toBeDisposed.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"toBeDisposed.js","sourceRoot":"","sources":["../../../src/testing/matchers/toBeDisposed.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,sBAAsB,EACtB,cAAc,GACf,MAAM,+BAA+B,CAAC;AAEvC,SAAS,UAAU,CAAC,QAAiB;IACnC,IAAI,CAAC;QACH,OAAO,cAAc,CAAC,QAAe,CAAC,YAAY,sBAAsB,CAAC;IAC3E,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,IAAM,YAAY,GAAwB,UAAU,QAAQ;IAAlB,iBAmBhD;IAlBC,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,cAAc,EAAE,UAAU,EAAE,EAAE,EAAE;QAClE,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC,CAAC;IAEH,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,YAAK,IAAI,mDAAgD,CAAC,CAAC;IAC7E,CAAC;IAED,IAAM,IAAI,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC;IAE/C,OAAO;QACL,IAAI,MAAA;QACJ,OAAO,EAAE;YACP,OAAO,UAAG,IAAI,mCACZ,KAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,uCACG,KAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,MAAG,CAAC;QAC3D,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { MatcherFunction } from \"expect\";\nimport type { QueryReference } from \"../../react/internal/index.js\";\nimport {\n InternalQueryReference,\n unwrapQueryRef,\n} from \"../../react/internal/index.js\";\n\nfunction isQueryRef(queryRef: unknown): queryRef is QueryReference {\n try {\n return unwrapQueryRef(queryRef as any) instanceof InternalQueryReference;\n } catch (e) {\n return false;\n }\n}\n\nexport const toBeDisposed: MatcherFunction<[]> = function (queryRef) {\n const hint = this.utils.matcherHint(\"toBeDisposed\", \"queryRef\", \"\", {\n isNot: this.isNot,\n });\n\n if (!isQueryRef(queryRef)) {\n throw new Error(`\\n${hint}\\n\\nmust be called with a valid QueryReference`);\n }\n\n const pass = unwrapQueryRef(queryRef).disposed;\n\n return {\n pass,\n message: () => {\n return `${hint}\\n\\nExpected queryRef ${\n this.isNot ? \"not \" : \"\"\n }to be disposed, but it was${this.isNot ? \"\" : \" not\"}.`;\n },\n };\n};\n"]}

View File

@@ -0,0 +1,8 @@
import type { MatcherFunction } from "expect";
declare class WeakRef<T extends WeakKey> {
constructor(target: T);
deref(): T | undefined;
}
export declare const toBeGarbageCollected: MatcherFunction<[weakRef: WeakRef<any>]>;
export {};
//# sourceMappingURL=toBeGarbageCollected.d.ts.map

View File

@@ -0,0 +1,48 @@
import { __awaiter, __generator } from "tslib";
export var toBeGarbageCollected = function (actual) {
return __awaiter(this, void 0, void 0, function () {
var hint, pass, interval, timeout;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
hint = this.utils.matcherHint("toBeGarbageCollected");
if (!(actual instanceof WeakRef)) {
throw new Error(hint +
"\n\n" +
"Expected value to be a WeakRef, but it was a ".concat(typeof actual, "."));
}
pass = false;
return [4 /*yield*/, Promise.race([
new Promise(function (resolve) {
timeout = setTimeout(resolve, 1000);
}),
new Promise(function (resolve) {
interval = setInterval(function () {
global.gc();
pass = actual.deref() === undefined;
if (pass) {
resolve();
}
}, 1);
}),
])];
case 1:
_a.sent();
clearInterval(interval);
clearTimeout(timeout);
return [2 /*return*/, {
pass: pass,
message: function () {
if (pass) {
return (hint +
"\n\n" +
"Expected value to not be cache-collected, but it was.");
}
return (hint + "\n\n Expected value to be cache-collected, but it was not.");
},
}];
}
});
});
};
//# sourceMappingURL=toBeGarbageCollected.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"toBeGarbageCollected.js","sourceRoot":"","sources":["../../../src/testing/matchers/toBeGarbageCollected.ts"],"names":[],"mappings":";AASA,MAAM,CAAC,IAAM,oBAAoB,GAC/B,UAAgB,MAAM;;;;;;oBACd,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,sBAAsB,CAAC,CAAC;oBAE5D,IAAI,CAAC,CAAC,MAAM,YAAY,OAAO,CAAC,EAAE,CAAC;wBACjC,MAAM,IAAI,KAAK,CACb,IAAI;4BACF,MAAM;4BACN,uDAAgD,OAAO,MAAM,MAAG,CACnE,CAAC;oBACJ,CAAC;oBAEG,IAAI,GAAG,KAAK,CAAC;oBAGjB,qBAAM,OAAO,CAAC,IAAI,CAAC;4BACjB,IAAI,OAAO,CAAO,UAAC,OAAO;gCACxB,OAAO,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;4BACtC,CAAC,CAAC;4BACF,IAAI,OAAO,CAAO,UAAC,OAAO;gCACxB,QAAQ,GAAG,WAAW,CAAC;oCACrB,MAAM,CAAC,EAAG,EAAE,CAAC;oCACb,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,SAAS,CAAC;oCACpC,IAAI,IAAI,EAAE,CAAC;wCACT,OAAO,EAAE,CAAC;oCACZ,CAAC;gCACH,CAAC,EAAE,CAAC,CAAC,CAAC;4BACR,CAAC,CAAC;yBACH,CAAC,EAAA;;oBAbF,SAaE,CAAC;oBAEH,aAAa,CAAC,QAAQ,CAAC,CAAC;oBACxB,YAAY,CAAC,OAAO,CAAC,CAAC;oBAEtB,sBAAO;4BACL,IAAI,MAAA;4BACJ,OAAO,EAAE;gCACP,IAAI,IAAI,EAAE,CAAC;oCACT,OAAO,CACL,IAAI;wCACJ,MAAM;wCACN,uDAAuD,CACxD,CAAC;gCACJ,CAAC;gCAED,OAAO,CACL,IAAI,GAAG,4DAA4D,CACpE,CAAC;4BACJ,CAAC;yBACF,EAAC;;;;CACH,CAAC","sourcesContent":["import type { MatcherFunction } from \"expect\";\n\n// this is necessary because this file is picked up by `tsc` (it's not a test),\n// but our main `tsconfig.json` doesn't include `\"ES2021.WeakRef\"` on purpose\ndeclare class WeakRef<T extends WeakKey> {\n constructor(target: T);\n deref(): T | undefined;\n}\n\nexport const toBeGarbageCollected: MatcherFunction<[weakRef: WeakRef<any>]> =\n async function (actual) {\n const hint = this.utils.matcherHint(\"toBeGarbageCollected\");\n\n if (!(actual instanceof WeakRef)) {\n throw new Error(\n hint +\n \"\\n\\n\" +\n `Expected value to be a WeakRef, but it was a ${typeof actual}.`\n );\n }\n\n let pass = false;\n let interval: NodeJS.Timeout | undefined;\n let timeout: NodeJS.Timeout | undefined;\n await Promise.race([\n new Promise<void>((resolve) => {\n timeout = setTimeout(resolve, 1000);\n }),\n new Promise<void>((resolve) => {\n interval = setInterval(() => {\n global.gc!();\n pass = actual.deref() === undefined;\n if (pass) {\n resolve();\n }\n }, 1);\n }),\n ]);\n\n clearInterval(interval);\n clearTimeout(timeout);\n\n return {\n pass,\n message: () => {\n if (pass) {\n return (\n hint +\n \"\\n\\n\" +\n \"Expected value to not be cache-collected, but it was.\"\n );\n }\n\n return (\n hint + \"\\n\\n Expected value to be cache-collected, but it was not.\"\n );\n },\n };\n };\n"]}

View File

@@ -0,0 +1,11 @@
import type { MatcherFunction } from "expect";
import type { DocumentNode } from "graphql";
import type { OperationVariables } from "../../core/index.js";
export declare const toHaveSuspenseCacheEntryUsing: MatcherFunction<[
query: DocumentNode,
options: {
variables?: OperationVariables;
queryKey?: string | number | any[];
}
]>;
//# sourceMappingURL=toHaveSuspenseCacheEntryUsing.d.ts.map

View File

@@ -0,0 +1,24 @@
import { __spreadArray } from "tslib";
import { ApolloClient } from "../../core/index.js";
import { canonicalStringify } from "../../cache/index.js";
import { getSuspenseCache } from "../../react/internal/index.js";
export var toHaveSuspenseCacheEntryUsing = function (client, query, _a) {
var _b;
var _c = _a === void 0 ? Object.create(null) : _a, variables = _c.variables, _d = _c.queryKey, queryKey = _d === void 0 ? [] : _d;
if (!(client instanceof ApolloClient)) {
throw new Error("Actual must be an instance of `ApolloClient`");
}
var suspenseCache = getSuspenseCache(client);
var cacheKey = __spreadArray([
query,
canonicalStringify(variables)
], [].concat(queryKey), true);
var queryRef = (_b = suspenseCache["queryRefs"].lookupArray(cacheKey)) === null || _b === void 0 ? void 0 : _b.current;
return {
pass: !!queryRef,
message: function () {
return "Expected suspense cache ".concat(queryRef ? "not " : "", "to have cache entry using key");
},
};
};
//# sourceMappingURL=toHaveSuspenseCacheEntryUsing.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"toHaveSuspenseCacheEntryUsing.js","sourceRoot":"","sources":["../../../src/testing/matchers/toHaveSuspenseCacheEntryUsing.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGjE,MAAM,CAAC,IAAM,6BAA6B,GAQtC,UACF,MAAM,EACN,KAAK,EACL,EAAkD;;QAAlD,qBAA+B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAA,EAAhD,SAAS,eAAA,EAAE,gBAAa,EAAb,QAAQ,mBAAG,EAAE,KAAA;IAE1B,IAAI,CAAC,CAAC,MAAM,YAAY,YAAY,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IAED,IAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE/C,IAAM,QAAQ;QACZ,KAAK;QACL,kBAAkB,CAAC,SAAS,CAAC;OACzB,EAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,OAClC,CAAC;IACF,IAAM,QAAQ,GAAG,MAAA,aAAa,CAAC,WAAW,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,0CAAE,OAAO,CAAC;IAE3E,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,QAAQ;QAChB,OAAO,EAAE;YACP,OAAO,kCACL,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,kCACO,CAAC;QAClC,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { MatcherFunction } from \"expect\";\nimport type { DocumentNode } from \"graphql\";\nimport type { OperationVariables } from \"../../core/index.js\";\nimport { ApolloClient } from \"../../core/index.js\";\nimport { canonicalStringify } from \"../../cache/index.js\";\nimport { getSuspenseCache } from \"../../react/internal/index.js\";\nimport type { CacheKey } from \"../../react/internal/index.js\";\n\nexport const toHaveSuspenseCacheEntryUsing: MatcherFunction<\n [\n query: DocumentNode,\n options: {\n variables?: OperationVariables;\n queryKey?: string | number | any[];\n },\n ]\n> = function (\n client,\n query,\n { variables, queryKey = [] } = Object.create(null)\n) {\n if (!(client instanceof ApolloClient)) {\n throw new Error(\"Actual must be an instance of `ApolloClient`\");\n }\n\n const suspenseCache = getSuspenseCache(client);\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n const queryRef = suspenseCache[\"queryRefs\"].lookupArray(cacheKey)?.current;\n\n return {\n pass: !!queryRef,\n message: () => {\n return `Expected suspense cache ${\n queryRef ? \"not \" : \"\"\n }to have cache entry using key`;\n },\n };\n};\n"]}

View File

@@ -0,0 +1,4 @@
import type { DocumentNode } from "../../core/index.js";
import type { MatcherFunction } from "expect";
export declare const toMatchDocument: MatcherFunction<[document: DocumentNode]>;
//# sourceMappingURL=toMatchDocument.d.ts.map

View File

@@ -0,0 +1,33 @@
import { checkDocument, print } from "../../utilities/index.js";
export var toMatchDocument = function (actual, document) {
var _this = this;
var hint = this.utils.matcherHint("toMatchDocument");
var actualDocument = print(validateDocument(actual, hint +
"\n\n".concat(this.utils.RECEIVED_COLOR("received"), " document must be a parsed document.")));
var expectedDocument = print(validateDocument(document, hint +
"\n\n".concat(this.utils.EXPECTED_COLOR("expected"), " document must be a parsed document.")));
var pass = actualDocument === expectedDocument;
return {
pass: pass,
message: function () {
var hint = _this.utils.matcherHint("toMatchDocument", undefined, undefined, { isNot: _this.isNot });
if (pass) {
return (hint +
"\n\n" +
"Received:\n\n" +
_this.utils.RECEIVED_COLOR(actualDocument));
}
return (hint + "\n\n" + _this.utils.diff(expectedDocument, actualDocument));
},
};
};
function validateDocument(document, message) {
try {
checkDocument(document);
}
catch (e) {
throw new Error(message);
}
return document;
}
//# sourceMappingURL=toMatchDocument.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"toMatchDocument.js","sourceRoot":"","sources":["../../../src/testing/matchers/toMatchDocument.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAIhE,MAAM,CAAC,IAAM,eAAe,GAC1B,UAAU,MAAM,EAAE,QAAQ;IAA1B,iBA+CC;IA9CC,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;IACvD,IAAM,cAAc,GAAG,KAAK,CAC1B,gBAAgB,CACd,MAAM,EACN,IAAI;QACF,cAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAC9B,UAAU,CACX,yCAAsC,CAC1C,CACF,CAAC;IACF,IAAM,gBAAgB,GAAG,KAAK,CAC5B,gBAAgB,CACd,QAAQ,EACR,IAAI;QACF,cAAO,IAAI,CAAC,KAAK,CAAC,cAAc,CAC9B,UAAU,CACX,yCAAsC,CAC1C,CACF,CAAC;IAEF,IAAM,IAAI,GAAG,cAAc,KAAK,gBAAgB,CAAC;IAEjD,OAAO;QACL,IAAI,MAAA;QACJ,OAAO,EAAE;YACP,IAAM,IAAI,GAAG,KAAI,CAAC,KAAK,CAAC,WAAW,CACjC,iBAAiB,EACjB,SAAS,EACT,SAAS,EACT,EAAE,KAAK,EAAE,KAAI,CAAC,KAAK,EAAE,CACtB,CAAC;YAEF,IAAI,IAAI,EAAE,CAAC;gBACT,OAAO,CACL,IAAI;oBACJ,MAAM;oBACN,eAAe;oBACf,KAAI,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAC1C,CAAC;YACJ,CAAC;YAED,OAAO,CACL,IAAI,GAAG,MAAM,GAAG,KAAI,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAClE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEJ,SAAS,gBAAgB,CAAC,QAAiB,EAAE,OAAe;IAC1D,IAAI,CAAC;QACH,aAAa,CAAC,QAAwB,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,QAAwB,CAAC;AAClC,CAAC","sourcesContent":["import { checkDocument, print } from \"../../utilities/index.js\";\nimport type { DocumentNode } from \"../../core/index.js\";\nimport type { MatcherFunction } from \"expect\";\n\nexport const toMatchDocument: MatcherFunction<[document: DocumentNode]> =\n function (actual, document) {\n const hint = this.utils.matcherHint(\"toMatchDocument\");\n const actualDocument = print(\n validateDocument(\n actual,\n hint +\n `\\n\\n${this.utils.RECEIVED_COLOR(\n \"received\"\n )} document must be a parsed document.`\n )\n );\n const expectedDocument = print(\n validateDocument(\n document,\n hint +\n `\\n\\n${this.utils.EXPECTED_COLOR(\n \"expected\"\n )} document must be a parsed document.`\n )\n );\n\n const pass = actualDocument === expectedDocument;\n\n return {\n pass,\n message: () => {\n const hint = this.utils.matcherHint(\n \"toMatchDocument\",\n undefined,\n undefined,\n { isNot: this.isNot }\n );\n\n if (pass) {\n return (\n hint +\n \"\\n\\n\" +\n \"Received:\\n\\n\" +\n this.utils.RECEIVED_COLOR(actualDocument)\n );\n }\n\n return (\n hint + \"\\n\\n\" + this.utils.diff(expectedDocument, actualDocument)\n );\n },\n };\n };\n\nfunction validateDocument(document: unknown, message: string) {\n try {\n checkDocument(document as DocumentNode);\n } catch (e) {\n throw new Error(message);\n }\n\n return document as DocumentNode;\n}\n"]}