Skip to content

Commit 5231113

Browse files
Copilotabernier
andcommitted
Import test canvas dimensions from their canonical source
Co-authored-by: abernier <[email protected]>
1 parent f9ff27c commit 5231113

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

packages/fiber/__mocks__/react-use-measure.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as React from 'react'
2+
import { DEFAULT_TEST_CANVAS_WIDTH, DEFAULT_TEST_CANVAS_HEIGHT } from '../../test-renderer/src/createTestCanvas'
23

34
// Export the mocked dimensions so tests can reference them
4-
export const MOCKED_WIDTH = 1280
5-
export const MOCKED_HEIGHT = 800
5+
export const MOCKED_WIDTH = DEFAULT_TEST_CANVAS_WIDTH
6+
export const MOCKED_HEIGHT = DEFAULT_TEST_CANVAS_HEIGHT
67

78
export default function useMeasure() {
89
const element = React.useRef<HTMLElement | null>(null)

packages/test-renderer/src/createTestCanvas.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { WebGL2RenderingContext } from './WebGL2RenderingContext'
22
import type { CreateCanvasParameters } from './types/internal'
33

4-
export const createCanvas = ({ beforeReturn, width = 1280, height = 800 }: CreateCanvasParameters = {}) => {
4+
// Default test canvas dimensions
5+
export const DEFAULT_TEST_CANVAS_WIDTH = 1280
6+
export const DEFAULT_TEST_CANVAS_HEIGHT = 800
7+
8+
export const createCanvas = ({
9+
beforeReturn,
10+
width = DEFAULT_TEST_CANVAS_WIDTH,
11+
height = DEFAULT_TEST_CANVAS_HEIGHT,
12+
}: CreateCanvasParameters = {}) => {
513
let canvas: HTMLCanvasElement
614

715
if (typeof document !== 'undefined' && typeof document.createElement === 'function') {

packages/test-renderer/src/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { extend, _roots as mockRoots, createRoot, reconciler, act, Instance } fr
66
import { toTree } from './helpers/tree'
77
import { toGraph } from './helpers/graph'
88

9-
import { createCanvas } from './createTestCanvas'
9+
import { createCanvas, DEFAULT_TEST_CANVAS_WIDTH, DEFAULT_TEST_CANVAS_HEIGHT } from './createTestCanvas'
1010
import { createEventFirer } from './fireEvent'
1111

1212
import type { CreateOptions, Renderer } from './types/public'
@@ -24,8 +24,8 @@ const create = async (element: React.ReactNode, options?: Partial<CreateOptions>
2424
frameloop: 'never',
2525
// TODO: remove and use default behavior
2626
size: {
27-
width: options?.width ?? 1280,
28-
height: options?.height ?? 800,
27+
width: options?.width ?? DEFAULT_TEST_CANVAS_WIDTH,
28+
height: options?.height ?? DEFAULT_TEST_CANVAS_HEIGHT,
2929
top: 0,
3030
left: 0,
3131
},

0 commit comments

Comments
 (0)