Add Promise.prototype.finally polyfill and restore failing tests

Change-Id: Ia6cdb85d33d2b3e0e2e868838defaa39ae60572a
This commit is contained in:
Ed Sanders 2018-10-23 12:28:28 +01:00
parent e4724b3f26
commit c895c60907
4 changed files with 76 additions and 10 deletions

View file

@ -1019,6 +1019,8 @@ class VisualEditorHooks {
'lib/ve/lib/jsdifflib/diffview.css', 'lib/ve/lib/jsdifflib/diffview.css',
], ],
'scripts' => [ 'scripts' => [
// Promise.finally polyfill. Can be removed when CI uses Chrome >= 64
'lib/proposal-promise-finally/polyfill.js',
// MW config preload // MW config preload
'modules/ve-mw/tests/mw-preload.js', 'modules/ve-mw/tests/mw-preload.js',
// jsdifflib // jsdifflib
@ -1091,14 +1093,13 @@ class VisualEditorHooks {
'lib/ve/tests/ce/ve.ce.ContentBranchNode.test.js', 'lib/ve/tests/ce/ve.ce.ContentBranchNode.test.js',
'modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js', 'modules/ve-mw/tests/ce/ve.ce.ContentBranchNode.test.js',
'lib/ve/tests/ce/ve.ce.LeafNode.test.js', 'lib/ve/tests/ce/ve.ce.LeafNode.test.js',
// FIXME: These are breaking VE-MW CI tests 'lib/ve/tests/ce/keydownhandlers/ve.ce.LinearArrowKeyDownHandler.test.js',
// 'lib/ve/tests/ce/keydownhandlers/ve.ce.LinearArrowKeyDownHandler.test.js', 'lib/ve/tests/ce/keydownhandlers/ve.ce.LinearDeleteKeyDownHandler.test.js',
// 'lib/ve/tests/ce/keydownhandlers/ve.ce.LinearDeleteKeyDownHandler.test.js', 'lib/ve/tests/ce/keydownhandlers/ve.ce.LinearEnterKeyDownHandler.test.js',
// 'lib/ve/tests/ce/keydownhandlers/ve.ce.LinearEnterKeyDownHandler.test.js', 'lib/ve/tests/ce/keydownhandlers/ve.ce.LinearEscapeKeyDownHandler.test.js',
// 'lib/ve/tests/ce/keydownhandlers/ve.ce.LinearEscapeKeyDownHandler.test.js', 'lib/ve/tests/ce/keydownhandlers/ve.ce.TableArrowKeyDownHandler.test.js',
// 'lib/ve/tests/ce/keydownhandlers/ve.ce.TableArrowKeyDownHandler.test.js', 'lib/ve/tests/ce/keydownhandlers/ve.ce.TableDeleteKeyDownHandler.test.js',
// 'lib/ve/tests/ce/keydownhandlers/ve.ce.TableDeleteKeyDownHandler.test.js', 'lib/ve/tests/ce/keydownhandlers/ve.ce.TableEnterKeyDownHandler.test.js',
// 'lib/ve/tests/ce/keydownhandlers/ve.ce.TableEnterKeyDownHandler.test.js',
'lib/ve/tests/ce/nodes/ve.ce.TextNode.test.js', 'lib/ve/tests/ce/nodes/ve.ce.TextNode.test.js',
'lib/ve/tests/ce/nodes/ve.ce.TableNode.test.js', 'lib/ve/tests/ce/nodes/ve.ce.TableNode.test.js',
// VisualEditor UI Tests // VisualEditor UI Tests

View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Jordan Harband
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,45 @@
if (typeof Promise !== 'function') {
throw new TypeError('A global Promise is required');
}
if (typeof Promise.prototype.finally !== 'function') {
var speciesConstructor = function (O, defaultConstructor) {
if (!O || (typeof O !== 'object' && typeof O !== 'function')) {
throw new TypeError('Assertion failed: Type(O) is not Object');
}
var C = O.constructor;
if (typeof C === 'undefined') {
return defaultConstructor;
}
if (!C || (typeof C !== 'object' && typeof C !== 'function')) {
throw new TypeError('O.constructor is not an Object');
}
var S = typeof Symbol === 'function' && typeof Symbol.species === 'symbol' ? C[Symbol.species] : undefined;
if (S == null) {
return defaultConstructor;
}
if (typeof S === 'function' && S.prototype) {
return S;
}
throw new TypeError('no constructor found');
};
var shim = {
finally(onFinally) {
var promise = this;
if (typeof promise !== 'object' || promise === null) {
throw new TypeError('"this" value is not an Object');
}
var C = speciesConstructor(promise, Promise); // throws if SpeciesConstructor throws
if (typeof onFinally !== 'function') {
return Promise.prototype.then.call(promise, onFinally, onFinally);
}
return Promise.prototype.then.call(
promise,
x => new C(resolve => resolve(onFinally())).then(() => x),
e => new C(resolve => resolve(onFinally())).then(() => { throw e; })
);
}
};
Object.defineProperty(Promise.prototype, 'finally', { configurable: true, writable: true, value: shim.finally });
}

View file

@ -60,8 +60,7 @@ QUnit.test( 'handleLinearDelete', function ( assert ) {
} ); } );
} ); } );
// VE-MW CI doesn't support finally yet promise.finally( function () { done(); } );
promise.then( function () { done(); }, function () { done(); } );
} ); } );
QUnit.test( 'beforePaste/afterPaste', function ( assert ) { QUnit.test( 'beforePaste/afterPaste', function ( assert ) {