11import { vi } from 'vitest' ;
22import { mockP5 , mockP5Prototype } from '../../js/mocks' ;
3+ import dom from '../../../src/dom/dom' ;
34import {
45 default as media ,
56 MediaElement
@@ -10,6 +11,7 @@ import { default as pixels } from '../../../src/image/pixels';
1011suite ( 'p5.MediaElement' , ( ) => {
1112 beforeAll ( ( ) => {
1213 media ( mockP5 , mockP5Prototype ) ;
14+ dom ( mockP5 , mockP5Prototype ) ;
1315 pixels ( mockP5 , mockP5Prototype ) ;
1416 navigator . mediaDevices . getUserMedia = vi
1517 . fn ( )
@@ -96,11 +98,11 @@ suite('p5.MediaElement', () => {
9698 } ) ;
9799 } ) ;
98100
99- test . todo ( 'should work with updatePixels()' , function ( done ) {
101+ test ( 'should work with updatePixels()' , function ( done ) {
100102 let loaded = false ;
101103 let prevElt ;
102- const imgElt = myp5 . createImg ( '/test/unit/assets/cat.jpg' , '' ) ;
103- const testElement = myp5 . createVideo ( '/test/unit/assets/cat.webm' , ( ) => {
104+ const imgElt = mockP5Prototype . createImg ( '/test/unit/assets/cat.jpg' , '' ) ;
105+ const testElement = mockP5Prototype . createVideo ( '/test/unit/assets/cat.webm' , ( ) => {
104106 loaded = true ;
105107 // Workaround for headless tests, where the video data isn't loading
106108 // correctly: mock the video element using an image for this test
@@ -109,9 +111,9 @@ suite('p5.MediaElement', () => {
109111 } ) ;
110112
111113 let drewUpdatedPixels = false ;
112- myp5 . draw = function ( ) {
114+ mockP5Prototype . draw = function ( ) {
113115 if ( ! loaded ) return ;
114- myp5 . background ( 255 ) ;
116+ mockP5Prototype . background ( 255 ) ;
115117
116118 if ( ! drewUpdatedPixels ) {
117119 // First, update pixels and check that it draws the updated
@@ -125,27 +127,27 @@ suite('p5.MediaElement', () => {
125127 testElement . pixels [ i + 3 ] = 255 ;
126128 }
127129 testElement . updatePixels ( ) ;
128- myp5 . image ( testElement , 0 , 0 ) ;
130+ mockP5Prototype . image ( testElement , 0 , 0 ) ;
129131
130132 // The element should have drawn using the updated red pixels
131- myp5 . loadPixels ( ) ;
132- assert . deepEqual ( [ ...myp5 . pixels . slice ( 0 , 4 ) ] , [ 255 , 0 , 0 , 255 ] ) ;
133+ mockP5Prototype . loadPixels ( ) ;
134+ assert . deepEqual ( [ ...mockP5Prototype . pixels . slice ( 0 , 4 ) ] , [ 255 , 0 , 0 , 255 ] ) ;
133135
134136 // Mark that we've done the first check so we can see whether
135137 // the video still updates on the next frame
136138 drewUpdatedPixels = true ;
137139 } else {
138140 // Next, make sure it still updates with the real pixels from
139141 // the next frame of the video on the next frame of animation
140- myp5 . image ( testElement , 0 , 0 ) ;
142+ mockP5Prototype . image ( testElement , 0 , 0 ) ;
141143
142- myp5 . loadPixels ( ) ;
144+ mockP5Prototype . loadPixels ( ) ;
143145 testElement . loadPixels ( ) ;
144146 expect ( [ ...testElement . pixels . slice ( 0 , 4 ) ] ) . to . not . deep . equal ( [
145147 255 , 0 , 0 , 255
146148 ] ) ;
147149 assert . deepEqual (
148- [ ...myp5 . pixels . slice ( 0 , 4 ) ] ,
150+ [ ...mockP5Prototype . pixels . slice ( 0 , 4 ) ] ,
149151 [ ...testElement . pixels . slice ( 0 , 4 ) ]
150152 ) ;
151153 testElement . elt = prevElt ;
0 commit comments