8
0
Просмотр исходного кода

Fixed `crashes` property, added test for it.

Maciej Bukowski 6 лет назад
Родитель
Сommit
24c8d63bd7

+ 5 - 5
packages/ckeditor5-watchdog/src/watchdog.js

@@ -32,9 +32,9 @@ export default class Watchdog {
 		 * * `message`: `String`,
 		 * * `stack`: `String`,
 		 * * `date`: `Number`,
-		 * * `source`: `String | undefined`,
-		 * * `lineno`: `String | undefined`,
-		 * * `colno`: `String` | undefined,
+		 * * `filename`: `String | undefined`,
+		 * * `lineno`: `Number | undefined`,
+		 * * `colno`: `Number` | undefined,
 		 *
 		 * @public
 		 * @readonly
@@ -327,8 +327,8 @@ export default class Watchdog {
 				message: error.message,
 				stack: error.stack,
 
-				// `evt.source`, `evt.lineno` and `evt.colno` are available only in ErrorEvent events
-				source: evt.source,
+				// `evt.filename`, `evt.lineno` and `evt.colno` are available only in ErrorEvent events
+				filename: evt.filename,
 				lineno: evt.lineno,
 				colno: evt.colno,
 				date: Date.now()

+ 39 - 0
packages/ckeditor5-watchdog/tests/watchdog.js

@@ -821,6 +821,12 @@ describe( 'Watchdog', () => {
 						window.onerror = originalErrorHandler;
 
 						expect( watchdog.crashes[ 0 ].message ).to.equal( 'foo' );
+						expect( watchdog.crashes[ 0 ].stack ).to.be.a( 'string' );
+						expect( watchdog.crashes[ 0 ].date ).to.be.a( 'number' );
+						expect( watchdog.crashes[ 0 ].filename ).to.be.a( 'string' );
+						expect( watchdog.crashes[ 0 ].lineno ).to.be.a( 'number' );
+						expect( watchdog.crashes[ 0 ].colno ).to.be.a( 'number' );
+
 						expect( watchdog.crashes[ 1 ].message ).to.equal( 'bar' );
 
 						watchdog.destroy().then( res );
@@ -828,6 +834,39 @@ describe( 'Watchdog', () => {
 				} );
 			} );
 		} );
+
+		it( 'should include async errors', () => {
+			return isUnhandledRejectionEventSupported().then( isSupported => {
+				if ( !isSupported ) {
+					return;
+				}
+
+				const watchdog = Watchdog.for( ClassicTestEditor );
+
+				// sinon.stub( window, 'onerror' ).value( undefined ); and similar do not work.
+				const originalErrorHandler = window.onerror;
+				window.onerror = undefined;
+
+				return watchdog.create( element ).then( () => {
+					Promise.resolve().then( () => throwCKEditorError( 'foo', watchdog.editor ) );
+
+					return new Promise( res => {
+						setTimeout( () => {
+							window.onerror = originalErrorHandler;
+
+							expect( watchdog.crashes[ 0 ].message ).to.equal( 'foo' );
+							expect( watchdog.crashes[ 0 ].stack ).to.be.a( 'string' );
+							expect( watchdog.crashes[ 0 ].date ).to.be.a( 'number' );
+							expect( watchdog.crashes[ 0 ].filename ).to.be.an( 'undefined' );
+							expect( watchdog.crashes[ 0 ].lineno ).to.be.an( 'undefined' );
+							expect( watchdog.crashes[ 0 ].colno ).to.be.an( 'undefined' );
+
+							watchdog.destroy().then( res );
+						} );
+					} );
+				} );
+			} );
+		} );
 	} );
 
 	describe( 'state', () => {