| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Copyright 2017 Google Inc. All rights reserved. | 
					
						
							|  |  |  |  * Modifications copyright (c) Microsoft Corporation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-19 21:32:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-26 16:05:58 -07:00
										 |  |  | import { it, expect } from './fixtures'; | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-11 10:02:07 -07:00
										 |  |  | it('should fire', async ({page, server, isWebKit}) => { | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  |   const [error] = await Promise.all([ | 
					
						
							|  |  |  |     page.waitForEvent('pageerror'), | 
					
						
							|  |  |  |     page.goto(server.PREFIX + '/error.html'), | 
					
						
							|  |  |  |   ]); | 
					
						
							|  |  |  |   expect(error.name).toBe('Error'); | 
					
						
							|  |  |  |   expect(error.message).toBe('Fancy error!'); | 
					
						
							| 
									
										
										
										
											2020-08-11 15:50:53 -07:00
										 |  |  |   let stack = await page.evaluate(() => window['e'].stack); | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  |   // Note that WebKit reports the stack of the 'throw' statement instead of the Error constructor call.
 | 
					
						
							| 
									
										
										
										
											2020-09-11 10:02:07 -07:00
										 |  |  |   if (isWebKit) | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  |     stack = stack.replace('14:25', '15:19'); | 
					
						
							|  |  |  |   expect(error.stack).toBe(stack); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-26 16:05:58 -07:00
										 |  |  | it('should contain sourceURL', (test, { browserName }) => { | 
					
						
							|  |  |  |   test.fail(browserName === 'webkit'); | 
					
						
							| 
									
										
										
										
											2020-08-28 13:53:47 -07:00
										 |  |  | }, async ({page, server}) => { | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  |   const [error] = await Promise.all([ | 
					
						
							|  |  |  |     page.waitForEvent('pageerror'), | 
					
						
							|  |  |  |     page.goto(server.PREFIX + '/error.html'), | 
					
						
							|  |  |  |   ]); | 
					
						
							|  |  |  |   expect(error.stack).toContain('myscript.js'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-11 10:02:07 -07:00
										 |  |  | it('should handle odd values', async ({page, isFirefox}) => { | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  |   const cases = [ | 
					
						
							|  |  |  |     [null, 'null'], | 
					
						
							|  |  |  |     [undefined, 'undefined'], | 
					
						
							|  |  |  |     [0, '0'], | 
					
						
							|  |  |  |     ['', ''], | 
					
						
							|  |  |  |   ]; | 
					
						
							|  |  |  |   for (const [value, message] of cases) { | 
					
						
							|  |  |  |     const [error] = await Promise.all([ | 
					
						
							|  |  |  |       page.waitForEvent('pageerror'), | 
					
						
							|  |  |  |       page.evaluate(value => setTimeout(() => { throw value; }, 0), value), | 
					
						
							|  |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2020-09-11 10:02:07 -07:00
										 |  |  |     expect(error.message).toBe(isFirefox ? 'uncaught exception: ' + message : message); | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-26 16:05:58 -07:00
										 |  |  | it('should handle object', (test, { browserName }) => { | 
					
						
							|  |  |  |   test.fixme(browserName === 'firefox'); | 
					
						
							| 
									
										
										
										
											2020-09-11 10:02:07 -07:00
										 |  |  | }, async ({page, isChromium}) => { | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  |   // Firefox just does not report this error.
 | 
					
						
							|  |  |  |   const [error] = await Promise.all([ | 
					
						
							|  |  |  |     page.waitForEvent('pageerror'), | 
					
						
							|  |  |  |     page.evaluate(() => setTimeout(() => { throw {}; }, 0)), | 
					
						
							|  |  |  |   ]); | 
					
						
							| 
									
										
										
										
											2020-09-11 10:02:07 -07:00
										 |  |  |   expect(error.message).toBe(isChromium ? 'Object' : '[object Object]'); | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-26 16:05:58 -07:00
										 |  |  | it('should handle window', (test, { browserName }) => { | 
					
						
							|  |  |  |   test.fixme(browserName === 'firefox'); | 
					
						
							| 
									
										
										
										
											2020-09-11 10:02:07 -07:00
										 |  |  | }, async ({page, isChromium}) => { | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  |   // Firefox just does not report this error.
 | 
					
						
							|  |  |  |   const [error] = await Promise.all([ | 
					
						
							|  |  |  |     page.waitForEvent('pageerror'), | 
					
						
							|  |  |  |     page.evaluate(() => setTimeout(() => { throw window; }, 0)), | 
					
						
							|  |  |  |   ]); | 
					
						
							| 
									
										
										
										
											2020-09-11 10:02:07 -07:00
										 |  |  |   expect(error.message).toBe(isChromium ? 'Window' : '[object Window]'); | 
					
						
							| 
									
										
										
										
											2020-08-04 15:09:24 -07:00
										 |  |  | }); |