Explorar el Código

Fixed coverage.

Maciej Bukowski hace 8 años
padre
commit
207f86a369

+ 13 - 11
packages/ckeditor5-engine/src/dev-utils/deltareplayer.js

@@ -49,22 +49,24 @@ export default class DeltaReplayer {
 	 * Applies all deltas with delay between actions.
 	 *
 	 * @param {Number} timeInterval Time between applying deltas.
-	 * @param {Function} [cb] Callback.
+	 * @returns {Promise}
 	 */
-	play( timeInterval = 1000, cb = () => {} ) {
+	play( timeInterval = 1000 ) {
 		const deltaReplayer = this;
 
-		play();
+		return new Promise( ( res ) => {
+			play();
 
-		function play() {
-			if ( deltaReplayer._deltasToReplay.length === 0 ) {
-				return cb();
-			}
+			function play() {
+				if ( deltaReplayer._deltasToReplay.length === 0 ) {
+					return res();
+				}
 
-			deltaReplayer.applyNextDelta().then( () => {
-				setTimeout( play, timeInterval );
-			}, cb );
-		}
+				deltaReplayer.applyNextDelta().then( () => {
+					setTimeout( play, timeInterval );
+				}, res );
+			}
+		} );
 	}
 
 	/**

+ 1 - 1
packages/ckeditor5-engine/src/dev-utils/enableenginedebug.js

@@ -485,7 +485,7 @@ function enableDocumentTools() {
 	};
 
 	ModelDocument.prototype.getAppliedDeltas = function() {
-		return ( this._appliedDeltas || [] ).map( JSON.stringify ).join( LOG_SEPARATOR );
+		return this._appliedDeltas.map( JSON.stringify ).join( LOG_SEPARATOR );
 	};
 
 	ModelDocument.prototype.createReplayer = function( stringifiedDeltas ) {

+ 10 - 4
packages/ckeditor5-engine/tests/dev-utils/deltareplayer.js

@@ -128,7 +128,7 @@ describe( 'DeltaReplayer', () => {
 	} );
 
 	describe( 'play', () => {
-		it( 'should play deltas with time interval', ( done ) => {
+		it( 'should play deltas with time interval', () => {
 			const doc = getDocument();
 
 			const stringifiedDeltas = [ getFirstDelta(), getSecondDelta() ]
@@ -137,12 +137,18 @@ describe( 'DeltaReplayer', () => {
 
 			const deltaReplayer = new DeltaReplayer( doc, '---', stringifiedDeltas );
 
-			deltaReplayer.play( 0, () => {
+			return deltaReplayer.play( 0 ).then( () => {
 				expect( deltaReplayer.getDeltasToReplay().length ).to.equal( 0 );
-
-				done();
 			} );
 		} );
+
+		it( 'should work with default time interval', () => {
+			const doc = getDocument();
+
+			const deltaReplayer = new DeltaReplayer( doc, '---', '' );
+
+			return deltaReplayer.play();
+		} );
 	} );
 } );