From 3c23cccaf5a8ef1fcbb824253420bf33b4a15fe7 Mon Sep 17 00:00:00 2001 From: Lenz Weber-Tronic Date: Thu, 10 Oct 2024 11:07:44 +0200 Subject: [PATCH] rename files --- src/assertable.ts | 2 +- src/index.ts | 6 ++--- src/jest/index.ts | 23 +++---------------- ...edComponent.ts => renderStreamMatchers.ts} | 14 +++++++++++ src/renderHookToSnapshotStream.ts | 4 +++- src/{profile => renderStream}/Render.tsx | 0 src/{profile => renderStream}/context.tsx | 0 .../createRenderStream.tsx} | 12 +++++----- .../disableActWarnings.ts | 0 src/{profile => renderStream}/traces.ts | 0 src/renderToRenderStream.ts | 6 ++--- 11 files changed, 33 insertions(+), 34 deletions(-) rename src/jest/{ProfiledComponent.ts => renderStreamMatchers.ts} (82%) rename src/{profile => renderStream}/Render.tsx (100%) rename src/{profile => renderStream}/context.tsx (100%) rename src/{profile/profile.tsx => renderStream/createRenderStream.tsx} (96%) rename src/{profile => renderStream}/disableActWarnings.ts (100%) rename src/{profile => renderStream}/traces.ts (100%) diff --git a/src/assertable.ts b/src/assertable.ts index a912e5245..003614645 100644 --- a/src/assertable.ts +++ b/src/assertable.ts @@ -1,4 +1,4 @@ -import { RenderStream } from "./profile/profile.js"; +import { RenderStream } from "./renderStream/createRenderStream.js"; export const assertableSymbol = Symbol.for( "@testing-library/react-render-stream:assertable" diff --git a/src/index.ts b/src/index.ts index d2379b326..1a3ca066b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,14 +3,14 @@ export type { RenderStream, RenderStreamWithRenderFn, RenderStreamOptions, -} from "./profile/profile.js"; +} from "./renderStream/createRenderStream.js"; export { createRenderStream, useTrackRenders, WaitForRenderTimeoutError, -} from "./profile/profile.js"; +} from "./renderStream/createRenderStream.js"; -export type { SyncScreen } from "./profile/Render.js"; +export type { SyncScreen } from "./renderStream/Render.js"; export { renderToRenderStream } from "./renderToRenderStream.js"; export type { RenderStreamWithRenderResult } from "./renderToRenderStream.js"; diff --git a/src/jest/index.ts b/src/jest/index.ts index da9257408..0387e4c96 100644 --- a/src/jest/index.ts +++ b/src/jest/index.ts @@ -1,31 +1,14 @@ import { expect } from "@jest/globals"; -import { toRerender, toRenderExactlyTimes } from "./ProfiledComponent.js"; -import type { - NextRenderOptions, - RenderStream, - Assertable, -} from "@testing-library/react-render-stream"; +import { toRerender, toRenderExactlyTimes } from "./renderStreamMatchers.js"; +import type { RenderStreamMatchers } from "./renderStreamMatchers.js"; expect.extend({ toRerender, toRenderExactlyTimes, }); -interface CustomMatchers { - toRerender: T extends RenderStream | Assertable - ? (options?: NextRenderOptions) => Promise - : { - error: "matcher needs to be called on a `takeRender` function, `takeSnapshot` function or `RenderStream` instance"; - }; - - toRenderExactlyTimes: T extends RenderStream | Assertable - ? (count: number, options?: NextRenderOptions) => Promise - : { - error: "matcher needs to be called on a `takeRender` function, `takeSnapshot` function or `RenderStream` instance"; - }; -} declare global { namespace jest { - interface Matchers extends CustomMatchers {} + interface Matchers extends RenderStreamMatchers {} } } diff --git a/src/jest/ProfiledComponent.ts b/src/jest/renderStreamMatchers.ts similarity index 82% rename from src/jest/ProfiledComponent.ts rename to src/jest/renderStreamMatchers.ts index 1ae639087..039b4afaf 100644 --- a/src/jest/ProfiledComponent.ts +++ b/src/jest/renderStreamMatchers.ts @@ -9,6 +9,20 @@ import type { // this will bundle the `Symbol.for` call twice, but we keep it private import { assertableSymbol } from "../assertable.js"; +export interface RenderStreamMatchers { + toRerender: T extends RenderStream | Assertable + ? (options?: NextRenderOptions) => Promise + : { + error: "matcher needs to be called on a `takeRender` function, `takeSnapshot` function or `RenderStream` instance"; + }; + + toRenderExactlyTimes: T extends RenderStream | Assertable + ? (count: number, options?: NextRenderOptions) => Promise + : { + error: "matcher needs to be called on a `takeRender` function, `takeSnapshot` function or `RenderStream` instance"; + }; +} + export const toRerender: MatcherFunction<[options?: NextRenderOptions]> = async function (actual, options) { const _stream = actual as RenderStream | Assertable; diff --git a/src/renderHookToSnapshotStream.ts b/src/renderHookToSnapshotStream.ts index 5662466f0..43b693950 100644 --- a/src/renderHookToSnapshotStream.ts +++ b/src/renderHookToSnapshotStream.ts @@ -1,5 +1,7 @@ import { RenderHookOptions } from "@testing-library/react"; -import { createRenderStream, NextRenderOptions } from "./profile/profile.js"; +import { createRenderStream } from "./renderStream/createRenderStream.js"; +import type { NextRenderOptions } from "./renderStream/createRenderStream.js"; + import { Render } from "./profile/Render.js"; import { createElement } from "react"; import { Assertable, assertableSymbol, markAssertable } from "./assertable.js"; diff --git a/src/profile/Render.tsx b/src/renderStream/Render.tsx similarity index 100% rename from src/profile/Render.tsx rename to src/renderStream/Render.tsx diff --git a/src/profile/context.tsx b/src/renderStream/context.tsx similarity index 100% rename from src/profile/context.tsx rename to src/renderStream/context.tsx diff --git a/src/profile/profile.tsx b/src/renderStream/createRenderStream.tsx similarity index 96% rename from src/profile/profile.tsx rename to src/renderStream/createRenderStream.tsx index 84399b053..efc12488a 100644 --- a/src/profile/profile.tsx +++ b/src/renderStream/createRenderStream.tsx @@ -141,7 +141,7 @@ export function createRenderStream({ })); }; - const profilerContext: RenderStreamContextValue = { + const renderStreamContext: RenderStreamContextValue = { renderedComponents: [], }; @@ -155,7 +155,7 @@ export function createRenderStream({ ) => { if ( skipNonTrackingRenders && - profilerContext.renderedComponents.length === 0 + renderStreamContext.renderedComponents.length === 0 ) { return; } @@ -191,9 +191,9 @@ export function createRenderStream({ baseRender, snapshot, domSnapshot, - profilerContext.renderedComponents + renderStreamContext.renderedComponents ); - profilerContext.renderedComponents = []; + renderStreamContext.renderedComponents = []; stream.renders.push(render); resolveNextRender?.(render); } catch (error) { @@ -211,7 +211,7 @@ export function createRenderStream({ let iteratorPosition = 0; function Wrapper({ children }: { children: React.ReactNode }) { return ( - + {children} @@ -373,7 +373,7 @@ export function useTrackRenders({ name }: { name?: string } = {}) { if (!ctx) { throw new Error( - "useTrackComponentRender: A Profiler must be created and rendered to track component renders" + "useTrackComponentRender: A Render Stream must be created and rendered to track component renders" ); } diff --git a/src/profile/disableActWarnings.ts b/src/renderStream/disableActWarnings.ts similarity index 100% rename from src/profile/disableActWarnings.ts rename to src/renderStream/disableActWarnings.ts diff --git a/src/profile/traces.ts b/src/renderStream/traces.ts similarity index 100% rename from src/profile/traces.ts rename to src/renderStream/traces.ts diff --git a/src/renderToRenderStream.ts b/src/renderToRenderStream.ts index b4a249bfc..860b1b489 100644 --- a/src/renderToRenderStream.ts +++ b/src/renderToRenderStream.ts @@ -2,12 +2,12 @@ import { type RenderOptions as BaseOptions, type RenderResult as BaseResult, } from "@testing-library/react"; -import { - createRenderStream, +import { createRenderStream } from "./renderStream/createRenderStream.js"; +import type { RenderStreamOptions, RenderStream, ValidSnapshot, -} from "./profile/profile.js"; +} from "./renderStream/createRenderStream.js"; type RenderOptions = BaseOptions & RenderStreamOptions;