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,10 @@
/// <reference types="node" />
/**
* Temporarily disable act warnings.
*
* https://github.com/reactwg/react-18/discussions/102
*/
export declare function disableActWarnings(): {
prevActEnv: any;
} & Disposable;
//# sourceMappingURL=disableActWarnings.d.ts.map

View File

@@ -0,0 +1,15 @@
import { withCleanup } from "./withCleanup.js";
/**
* Temporarily disable act warnings.
*
* https://github.com/reactwg/react-18/discussions/102
*/
export function disableActWarnings() {
var prev = { prevActEnv: globalThis.IS_REACT_ACT_ENVIRONMENT };
globalThis.IS_REACT_ACT_ENVIRONMENT = false;
return withCleanup(prev, function (_a) {
var prevActEnv = _a.prevActEnv;
globalThis.IS_REACT_ACT_ENVIRONMENT = prevActEnv;
});
}
//# sourceMappingURL=disableActWarnings.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"disableActWarnings.js","sourceRoot":"","sources":["../../../../src/testing/internal/disposables/disableActWarnings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,UAAU,kBAAkB;IAChC,IAAM,IAAI,GAAG,EAAE,UAAU,EAAG,UAAkB,CAAC,wBAAwB,EAAE,CAAC;IACzE,UAAkB,CAAC,wBAAwB,GAAG,KAAK,CAAC;IAErD,OAAO,WAAW,CAAC,IAAI,EAAE,UAAC,EAAc;YAAZ,UAAU,gBAAA;QACnC,UAAkB,CAAC,wBAAwB,GAAG,UAAU,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { withCleanup } from \"./withCleanup.js\";\n\n/**\n * Temporarily disable act warnings.\n *\n * https://github.com/reactwg/react-18/discussions/102\n */\nexport function disableActWarnings() {\n const prev = { prevActEnv: (globalThis as any).IS_REACT_ACT_ENVIRONMENT };\n (globalThis as any).IS_REACT_ACT_ENVIRONMENT = false;\n\n return withCleanup(prev, ({ prevActEnv }) => {\n (globalThis as any).IS_REACT_ACT_ENVIRONMENT = prevActEnv;\n });\n}\n"]}

View File

@@ -0,0 +1,4 @@
export { disableActWarnings } from "./disableActWarnings.js";
export { spyOnConsole } from "./spyOnConsole.js";
export { withCleanup } from "./withCleanup.js";
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,4 @@
export { disableActWarnings } from "./disableActWarnings.js";
export { spyOnConsole } from "./spyOnConsole.js";
export { withCleanup } from "./withCleanup.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/testing/internal/disposables/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["export { disableActWarnings } from \"./disableActWarnings.js\";\nexport { spyOnConsole } from \"./spyOnConsole.js\";\nexport { withCleanup } from \"./withCleanup.js\";\n"]}

View File

@@ -0,0 +1,11 @@
/// <reference types="node" />
/// <reference types="jest" />
type ConsoleMethod = "log" | "info" | "warn" | "error" | "debug";
type Spies<Keys extends ConsoleMethod[]> = Record<Keys[number], jest.SpyInstance<void, any[], any>>;
/** @internal */
export declare function spyOnConsole<Keys extends ConsoleMethod[]>(...spyOn: Keys): Spies<Keys> & Disposable;
export declare namespace spyOnConsole {
var takeSnapshots: <Keys extends ConsoleMethod[]>(...spyOn: Keys) => Spies<Keys> & Disposable;
}
export {};
//# sourceMappingURL=spyOnConsole.d.ts.map

View File

@@ -0,0 +1,35 @@
import { withCleanup } from "./withCleanup.js";
var noOp = function () { };
var restore = function (spy) { return spy.mockRestore(); };
/** @internal */
export function spyOnConsole() {
var spyOn = [];
for (var _i = 0; _i < arguments.length; _i++) {
spyOn[_i] = arguments[_i];
}
var spies = {};
for (var _a = 0, spyOn_1 = spyOn; _a < spyOn_1.length; _a++) {
var key = spyOn_1[_a];
// @ts-ignore
spies[key] = jest.spyOn(console, key).mockImplementation(noOp);
}
return withCleanup(spies, function (spies) {
for (var _i = 0, _a = Object.values(spies); _i < _a.length; _i++) {
var spy = _a[_i];
restore(spy);
}
});
}
spyOnConsole.takeSnapshots = function () {
var spyOn = [];
for (var _i = 0; _i < arguments.length; _i++) {
spyOn[_i] = arguments[_i];
}
return withCleanup(spyOnConsole.apply(void 0, spyOn), function (spies) {
for (var _i = 0, _a = Object.values(spies); _i < _a.length; _i++) {
var spy = _a[_i];
expect(spy).toMatchSnapshot();
}
});
};
//# sourceMappingURL=spyOnConsole.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"spyOnConsole.js","sourceRoot":"","sources":["../../../../src/testing/internal/disposables/spyOnConsole.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,IAAM,IAAI,GAAG,cAAO,CAAC,CAAC;AACtB,IAAM,OAAO,GAAG,UAAC,GAAqB,IAAK,OAAA,GAAG,CAAC,WAAW,EAAE,EAAjB,CAAiB,CAAC;AAS7D,gBAAgB;AAChB,MAAM,UAAU,YAAY;IAC1B,eAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,0BAAc;;IAEd,IAAM,KAAK,GAAG,EAAiB,CAAC;IAChC,KAAkB,UAAK,EAAL,eAAK,EAAL,mBAAK,EAAL,IAAK,EAAE,CAAC;QAArB,IAAM,GAAG,cAAA;QACZ,aAAa;QACb,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,WAAW,CAAC,KAAK,EAAE,UAAC,KAAK;QAC9B,KAAkB,UAA0C,EAA1C,KAAA,MAAM,CAAC,MAAM,CAAC,KAAK,CAAuB,EAA1C,cAA0C,EAA1C,IAA0C,EAAE,CAAC;YAA1D,IAAM,GAAG,SAAA;YACZ,OAAO,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,YAAY,CAAC,aAAa,GAAG;IAC3B,eAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,0BAAc;;IAEd,OAAA,WAAW,CAAC,YAAY,eAAI,KAAK,GAAG,UAAC,KAAK;QACxC,KAAkB,UAA0C,EAA1C,KAAA,MAAM,CAAC,MAAM,CAAC,KAAK,CAAuB,EAA1C,cAA0C,EAA1C,IAA0C,EAAE,CAAC;YAA1D,IAAM,GAAG,SAAA;YACZ,MAAM,CAAC,GAAG,CAAC,CAAC,eAAe,EAAE,CAAC;QAChC,CAAC;IACH,CAAC,CAAC;AAJF,CAIE,CAAC","sourcesContent":["import { withCleanup } from \"./withCleanup.js\";\n\nconst noOp = () => {};\nconst restore = (spy: jest.SpyInstance) => spy.mockRestore();\n\ntype ConsoleMethod = \"log\" | \"info\" | \"warn\" | \"error\" | \"debug\";\n\ntype Spies<Keys extends ConsoleMethod[]> = Record<\n Keys[number],\n jest.SpyInstance<void, any[], any>\n>;\n\n/** @internal */\nexport function spyOnConsole<Keys extends ConsoleMethod[]>(\n ...spyOn: Keys\n): Spies<Keys> & Disposable {\n const spies = {} as Spies<Keys>;\n for (const key of spyOn) {\n // @ts-ignore\n spies[key] = jest.spyOn(console, key).mockImplementation(noOp);\n }\n return withCleanup(spies, (spies) => {\n for (const spy of Object.values(spies) as jest.SpyInstance[]) {\n restore(spy);\n }\n });\n}\n\nspyOnConsole.takeSnapshots = <Keys extends ConsoleMethod[]>(\n ...spyOn: Keys\n): Spies<Keys> & Disposable =>\n withCleanup(spyOnConsole(...spyOn), (spies) => {\n for (const spy of Object.values(spies) as jest.SpyInstance[]) {\n expect(spy).toMatchSnapshot();\n }\n });\n"]}

View File

@@ -0,0 +1,4 @@
/// <reference types="node" />
/** @internal */
export declare function withCleanup<T extends object>(item: T, cleanup: (item: T) => void): T & Disposable;
//# sourceMappingURL=withCleanup.d.ts.map

View File

@@ -0,0 +1,14 @@
import { __assign } from "tslib";
/** @internal */
export function withCleanup(item, cleanup) {
var _a;
return __assign(__assign({}, item), (_a = {}, _a[Symbol.dispose] = function () {
cleanup(item);
// if `item` already has a cleanup function, we also need to call the original cleanup function
// (e.g. if something is wrapped in `withCleanup` twice)
if (Symbol.dispose in item) {
item[Symbol.dispose]();
}
}, _a));
}
//# sourceMappingURL=withCleanup.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"withCleanup.js","sourceRoot":"","sources":["../../../../src/testing/internal/disposables/withCleanup.ts"],"names":[],"mappings":";AAAA,gBAAgB;AAChB,MAAM,UAAU,WAAW,CACzB,IAAO,EACP,OAA0B;;IAE1B,6BACK,IAAI,aACP,GAAC,MAAM,CAAC,OAAO,IAAf;QACE,OAAO,CAAC,IAAI,CAAC,CAAC;QACd,+FAA+F;QAC/F,wDAAwD;QACxD,IAAI,MAAM,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;YAC1B,IAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACzC,CAAC;IACH,CAAC,OACD;AACJ,CAAC","sourcesContent":["/** @internal */\nexport function withCleanup<T extends object>(\n item: T,\n cleanup: (item: T) => void\n): T & Disposable {\n return {\n ...item,\n [Symbol.dispose]() {\n cleanup(item);\n // if `item` already has a cleanup function, we also need to call the original cleanup function\n // (e.g. if something is wrapped in `withCleanup` twice)\n if (Symbol.dispose in item) {\n (item as Disposable)[Symbol.dispose]();\n }\n },\n };\n}\n"]}