1const REPORT_URL = '/gold_rpc/report'; 2const pngPrefx = 'data:image/png;base64,' 3 4function reportCanvas(canvas, testname, config) { 5 // toDataURL returns a base64 encoded string with a data prefix. We only 6 // want the PNG data itself, so we strip that off before submitting it. 7 const b64 = canvas.toDataURL('image/png') 8 .substring(pngPrefx.length); 9 return fetch(REPORT_URL, { 10 method: 'POST', 11 mode: 'no-cors', 12 headers: { 13 'Content-Type': 'application/json', 14 }, 15 body: JSON.stringify({ 16 'b64_data': b64, 17 'name': testname, 18 'config': config, 19 }) 20 }).then((resp) => { 21 expect(resp.status).toEqual(201); // StatusCreated 22 console.log(`${testname}: ${resp.statusText}`); 23 }); 24} 25 26function reportError(done) { 27 return (e) => { 28 fail(e); 29 done(); 30 }; 31} 32 33// A wrapper to catch and print a stacktrace to the logs. 34// Exceptions normally shows up in the browser console, 35// but not in the logs that appear on the bots AND a thrown 36// exception will normally cause a test to time out. 37// This wrapper mitigates both those pain points. 38function catchException(done, fn) { 39 return () => { 40 try { 41 fn() 42 } catch (e) { 43 console.log('Failed with the following error', e); 44 expect(e).toBeFalsy(); 45 debugger; 46 done(); 47 } 48 // We don't call done with finally because 49 // that would make the break the asynchronous nature 50 // of fn(). 51 } 52} 53