11import { afterAll , beforeAll , beforeEach , describe , expect , it , vi } from "vitest" ;
22
3- const { mockTextureFrom , mockVideoSourceFrom } = vi . hoisted ( ( ) => ( {
4- mockTextureFrom : vi . fn ( ( input : unknown ) => ( { source : input } ) ) ,
5- mockVideoSourceFrom : vi . fn ( ( options : unknown ) => ( { options } ) ) ,
3+ const { mockTextureConstructor , mockVideoSourceConstructor } = vi . hoisted ( ( ) => ( {
4+ mockTextureConstructor : vi . fn ( ) ,
5+ mockVideoSourceConstructor : vi . fn ( ) ,
66} ) ) ;
77
88vi . mock ( "pixi.js" , ( ) => {
@@ -20,14 +20,32 @@ vi.mock("pixi.js", () => {
2020 class MockGraphics { }
2121 class MockBlurFilter { }
2222
23+ class MockVideoSource {
24+ options : unknown ;
25+ autoUpdate = false ;
26+ constructor ( options : unknown ) {
27+ this . options = options ;
28+ mockVideoSourceConstructor ( options ) ;
29+ }
30+ }
31+
32+ class MockTexture {
33+ source : unknown ;
34+ constructor ( options : { source ?: unknown } = { } ) {
35+ this . source = options . source ;
36+ mockTextureConstructor ( options ) ;
37+ }
38+ static from = vi . fn ( ( input : unknown ) => new MockTexture ( { source : input } ) ) ;
39+ }
40+
2341 return {
2442 Application : MockApplication ,
2543 Container : MockContainer ,
2644 Sprite : MockSprite ,
2745 Graphics : MockGraphics ,
2846 BlurFilter : MockBlurFilter ,
29- Texture : { from : mockTextureFrom } ,
30- VideoSource : { from : mockVideoSourceFrom } ,
47+ Texture : MockTexture ,
48+ VideoSource : MockVideoSource ,
3149 } ;
3250} ) ;
3351
@@ -46,8 +64,8 @@ describe("frameRenderer video texture setup", () => {
4664 } ) ;
4765
4866 beforeEach ( ( ) => {
49- mockTextureFrom . mockClear ( ) ;
50- mockVideoSourceFrom . mockClear ( ) ;
67+ mockTextureConstructor . mockClear ( ) ;
68+ mockVideoSourceConstructor . mockClear ( ) ;
5169 } ) ;
5270
5371 it ( "creates VideoSource with autoplay disabled before source construction" , ( ) => {
@@ -78,19 +96,18 @@ describe("frameRenderer video texture setup", () => {
7896
7997 renderer . createTextureFromVideoSource ( videoElement ) ;
8098
81- expect ( mockVideoSourceFrom ) . toHaveBeenCalledTimes ( 1 ) ;
82- expect ( mockVideoSourceFrom ) . toHaveBeenCalledWith (
99+ expect ( mockVideoSourceConstructor ) . toHaveBeenCalledTimes ( 1 ) ;
100+ expect ( mockVideoSourceConstructor ) . toHaveBeenCalledWith (
83101 expect . objectContaining ( {
84102 resource : videoElement ,
85103 autoPlay : false ,
86- autoUpdate : true ,
87104 autoLoad : true ,
88105 muted : true ,
89106 } ) ,
90107 ) ;
91108 expect ( videoElement . defaultMuted ) . toBe ( true ) ;
92109 expect ( videoElement . muted ) . toBe ( true ) ;
93110 expect ( videoElement . volume ) . toBe ( 0 ) ;
94- expect ( mockTextureFrom ) . toHaveBeenCalledTimes ( 1 ) ;
111+ expect ( mockTextureConstructor ) . toHaveBeenCalledTimes ( 1 ) ;
95112 } ) ;
96113} ) ;
0 commit comments