Skip to content

Commit

Permalink
rename files
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Oct 10, 2024
1 parent b463dd4 commit 3c23ccc
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/assertable.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
23 changes: 3 additions & 20 deletions src/jest/index.ts
Original file line number Diff line number Diff line change
@@ -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<R = void, T = {}> {
toRerender: T extends RenderStream<any> | Assertable
? (options?: NextRenderOptions) => Promise<R>
: {
error: "matcher needs to be called on a `takeRender` function, `takeSnapshot` function or `RenderStream` instance";
};

toRenderExactlyTimes: T extends RenderStream<any> | Assertable
? (count: number, options?: NextRenderOptions) => Promise<R>
: {
error: "matcher needs to be called on a `takeRender` function, `takeSnapshot` function or `RenderStream` instance";
};
}

declare global {
namespace jest {
interface Matchers<R = void, T = {}> extends CustomMatchers<R, T> {}
interface Matchers<R = void, T = {}> extends RenderStreamMatchers<R, T> {}
}
}
14 changes: 14 additions & 0 deletions src/jest/ProfiledComponent.ts → src/jest/renderStreamMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<R = void, T = {}> {
toRerender: T extends RenderStream<any> | Assertable
? (options?: NextRenderOptions) => Promise<R>
: {
error: "matcher needs to be called on a `takeRender` function, `takeSnapshot` function or `RenderStream` instance";
};

toRenderExactlyTimes: T extends RenderStream<any> | Assertable
? (count: number, options?: NextRenderOptions) => Promise<R>
: {
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<any> | Assertable;
Expand Down
4 changes: 3 additions & 1 deletion src/renderHookToSnapshotStream.ts
Original file line number Diff line number Diff line change
@@ -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";

Check failure on line 5 in src/renderHookToSnapshotStream.ts

View workflow job for this annotation

GitHub Actions / pkg-pr-new Publish

Cannot find module './profile/Render.js' or its corresponding type declarations.
import { createElement } from "react";
import { Assertable, assertableSymbol, markAssertable } from "./assertable.js";
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function createRenderStream<Snapshot extends ValidSnapshot = void>({
}));
};

const profilerContext: RenderStreamContextValue = {
const renderStreamContext: RenderStreamContextValue = {
renderedComponents: [],
};

Expand All @@ -155,7 +155,7 @@ export function createRenderStream<Snapshot extends ValidSnapshot = void>({
) => {
if (
skipNonTrackingRenders &&
profilerContext.renderedComponents.length === 0
renderStreamContext.renderedComponents.length === 0
) {
return;
}
Expand Down Expand Up @@ -191,9 +191,9 @@ export function createRenderStream<Snapshot extends ValidSnapshot = void>({
baseRender,
snapshot,
domSnapshot,
profilerContext.renderedComponents
renderStreamContext.renderedComponents
);
profilerContext.renderedComponents = [];
renderStreamContext.renderedComponents = [];
stream.renders.push(render);
resolveNextRender?.(render);
} catch (error) {
Expand All @@ -211,7 +211,7 @@ export function createRenderStream<Snapshot extends ValidSnapshot = void>({
let iteratorPosition = 0;
function Wrapper({ children }: { children: React.ReactNode }) {
return (
<RenderStreamContextProvider value={profilerContext}>
<RenderStreamContextProvider value={renderStreamContext}>
<React.Profiler id="test" onRender={profilerOnRender}>
{children}
</React.Profiler>
Expand Down Expand Up @@ -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"
);
}

Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/renderToRenderStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Snapshot extends ValidSnapshot = void> = BaseOptions &
RenderStreamOptions<Snapshot>;
Expand Down

0 comments on commit 3c23ccc

Please sign in to comment.