@@ -127,51 +127,36 @@ suite('Core', function() {
127127 } ) ;
128128
129129 suite ( 'new p5() / global mode' , function ( ) {
130- var P5_SCRIPT_URL = '../../lib/p5.js' ;
131- var P5_SCRIPT_TAG = '<script src="' + P5_SCRIPT_URL + '"></script>' ;
132130 var iframe ;
133131
134- function createP5Iframe ( html ) {
135- html = html || P5_SCRIPT_TAG ;
136-
137- iframe = document . createElement ( 'iframe' ) ;
138-
139- document . body . appendChild ( iframe ) ;
140- iframe . setAttribute ( 'style' , 'visibility: hidden' ) ;
141-
142- iframe . contentDocument . open ( ) ;
143- iframe . contentDocument . write ( html ) ;
144- iframe . contentDocument . close ( ) ;
145- }
146-
147132 teardown ( function ( ) {
148133 if ( iframe ) {
149- iframe . parentNode . removeChild ( iframe ) ;
134+ iframe . teardown ( ) ;
150135 iframe = null ;
151136 }
152137 } ) ;
153138
154139 test ( 'is triggered when "setup" is in window' , function ( ) {
155140 return new Promise ( function ( resolve , reject ) {
156- createP5Iframe ( ) ;
157- iframe . contentWindow . setup = function ( ) {
141+ iframe = createP5Iframe ( ) ;
142+ iframe . elt . contentWindow . setup = function ( ) {
158143 resolve ( ) ;
159144 } ;
160145 } ) ;
161146 } ) ;
162147
163148 test ( 'is triggered when "draw" is in window' , function ( ) {
164149 return new Promise ( function ( resolve , reject ) {
165- createP5Iframe ( ) ;
166- iframe . contentWindow . draw = function ( ) {
150+ iframe = createP5Iframe ( ) ;
151+ iframe . elt . contentWindow . draw = function ( ) {
167152 resolve ( ) ;
168153 } ;
169154 } ) ;
170155 } ) ;
171156
172157 test ( 'works when p5.js is loaded asynchronously' , function ( ) {
173158 return new Promise ( function ( resolve , reject ) {
174- createP5Iframe ( `
159+ iframe = createP5Iframe ( `
175160 <script>
176161 window.onload = function() {
177162 var script = document.createElement('script');
@@ -181,13 +166,13 @@ suite('Core', function() {
181166 }
182167 </script>` ) ;
183168
184- iframe . contentWindow . setup = resolve ;
169+ iframe . elt . contentWindow . setup = resolve ;
185170 } ) ;
186171 } ) ;
187172
188173 test ( 'works on-demand' , function ( ) {
189174 return new Promise ( function ( resolve , reject ) {
190- createP5Iframe (
175+ iframe = createP5Iframe (
191176 [
192177 P5_SCRIPT_TAG ,
193178 '<script>' ,
@@ -199,9 +184,9 @@ suite('Core', function() {
199184 '</script>'
200185 ] . join ( '\n' )
201186 ) ;
202- iframe . contentWindow . onDoneLoading = resolve ;
187+ iframe . elt . contentWindow . onDoneLoading = resolve ;
203188 } ) . then ( function ( ) {
204- var win = iframe . contentWindow ;
189+ var win = iframe . elt . contentWindow ;
205190 assert . equal ( typeof win . myURL , 'string' ) ;
206191 assert . strictEqual ( win . setupCalled , true ) ;
207192 assert . strictEqual ( win . originalP5Instance , win . p5 . instance ) ;
0 commit comments