mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-21 15:17:40 +00:00
Changes the test_utils scripts to provide a more robust initiailization callback timer for automated CI testing.
This commit is contained in:
parent
1db5bbd7ef
commit
c6d3a2fc13
3 changed files with 58 additions and 39 deletions
|
|
@ -86,10 +86,7 @@ Modernizr.on('touchevents', function(result) {
|
|||
this.timeout(10000);
|
||||
|
||||
fixture.setBase('unit_tests/fixtures');
|
||||
setupKMW({ attachType:'auto' });
|
||||
|
||||
// Pass the initTimer method our 'done' callback so it can handle our initialization delays for us.
|
||||
initTimer(done);
|
||||
setupKMW({ attachType:'auto' }, done, 10000);
|
||||
});
|
||||
|
||||
beforeEach(function() {
|
||||
|
|
@ -155,10 +152,7 @@ Modernizr.on('touchevents', function(result) {
|
|||
this.timeout(10000);
|
||||
|
||||
fixture.setBase('unit_tests/fixtures');
|
||||
setupKMW({ attachType:'auto' });
|
||||
|
||||
// Pass the initTimer method our 'done' callback so it can handle our initialization delays for us.
|
||||
initTimer(done);
|
||||
setupKMW({ attachType:'auto' }, done, 10000);
|
||||
});
|
||||
|
||||
beforeEach(function() {
|
||||
|
|
|
|||
|
|
@ -7,10 +7,7 @@ describe('Basic KeymanWeb', function() {
|
|||
|
||||
fixture.setBase('unit_tests/fixtures');
|
||||
fixture.load("singleInput.html");
|
||||
setupKMW();
|
||||
|
||||
// Pass the initTimer method our 'done' callback so it can handle our initialization delays for us.
|
||||
initTimer(done);
|
||||
setupKMW(null, done, 10000);
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
|
|
@ -38,9 +35,7 @@ Modernizr.on('touchevents', function(result) {
|
|||
fixture.setBase('unit_tests/fixtures');
|
||||
fixture.load('singleInput.html');
|
||||
|
||||
setupKMW('toggle');
|
||||
|
||||
initTimer(done);
|
||||
setupKMW('toggle', done, 10000, function() { return keyman.ui.initialized; });
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
|
|
@ -73,9 +68,7 @@ Modernizr.on('touchevents', function(result) {
|
|||
fixture.setBase('unit_tests/fixtures');
|
||||
fixture.load('singleInput.html');
|
||||
|
||||
setupKMW('button');
|
||||
|
||||
initTimer(done);
|
||||
setupKMW('button', done, 10000, function() { return keyman.ui.init; });
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
|
|
@ -95,9 +88,7 @@ Modernizr.on('touchevents', function(result) {
|
|||
fixture.setBase('unit_tests/fixtures');
|
||||
fixture.load('singleInput.html');
|
||||
|
||||
setupKMW('float');
|
||||
|
||||
initTimer(done);
|
||||
setupKMW('float', done, 10000, function() { return keyman.ui.initialized; });
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
|
|
@ -130,10 +121,7 @@ Modernizr.on('touchevents', function(result) {
|
|||
fixture.setBase('unit_tests/fixtures');
|
||||
fixture.load('singleInput.html');
|
||||
|
||||
setupKMW('toolbar');
|
||||
|
||||
// The Toolbar UI has extra-special init to do... may as well feed it more time.
|
||||
initTimer(done, 2500);
|
||||
setupKMW('toolbar', done, 10000, function() { return keyman.ui.init; });
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
var setupKMW = function(kmwOptions) {
|
||||
var setupKMW = function(kmwOptions, done, timeout, uiInitCheck) {
|
||||
var ui;
|
||||
|
||||
if(typeof(kmwOptions) == 'string' || typeof(kmwOptions) == 'undefined') {
|
||||
if(typeof(kmwOptions) == 'string' || typeof(kmwOptions) == 'undefined' || kmwOptions == null) {
|
||||
ui = kmwOptions;
|
||||
|
||||
var kmwOptions = {
|
||||
|
|
@ -15,7 +15,7 @@ var setupKMW = function(kmwOptions) {
|
|||
}
|
||||
}
|
||||
|
||||
var kmw = setupScript('source/keymanweb.js');
|
||||
var kmw = setupScript('source/keymanweb.js', done, timeout, uiInitCheck);
|
||||
fixture.el.appendChild(kmw);
|
||||
|
||||
ui = kmwOptions.ui;
|
||||
|
|
@ -46,14 +46,17 @@ var setupKMW = function(kmwOptions) {
|
|||
*/
|
||||
window.setTimeout(function() {
|
||||
initFunc();
|
||||
}, 5);
|
||||
}, 8);
|
||||
}
|
||||
|
||||
var setupScript = function(src) {
|
||||
var setupScript = function(src, done, timeout, uiInitCheck) {
|
||||
var Lscript = document.createElement('script');
|
||||
Lscript.charset="UTF-8"; // KMEW-89
|
||||
Lscript.type = 'text/javascript';
|
||||
Lscript.async = false;
|
||||
if(done) {
|
||||
Lscript.onload = initTimer(done, timeout, uiInitCheck);
|
||||
}
|
||||
|
||||
Lscript.src = src;
|
||||
|
||||
|
|
@ -67,15 +70,49 @@ var teardownKMW = function() {
|
|||
}
|
||||
|
||||
// Make sure the main script loads...
|
||||
var initTimer = function(done, timeout) {
|
||||
window.setTimeout(function() {
|
||||
if(window['keyman']) {
|
||||
// ... and then give KMW and the UI a bit more time to init and attach.
|
||||
var initTimer = function(done, timeout, uiInitCheck) {
|
||||
var uiLoadDelay;
|
||||
if(typeof(uiInitCheck) != 'function') {
|
||||
uiInitCheck = function() { return true; };
|
||||
uiLoadDelay = false;
|
||||
} else {
|
||||
uiLoadDelay = true;
|
||||
}
|
||||
|
||||
// We need managed state for this.
|
||||
var InitializationManager = function() {
|
||||
this.killSwitch = false;
|
||||
|
||||
this.initCheckCallback = function() {
|
||||
if(window['keyman'] && window['keyman'].initialized == 2 && uiInitCheck()) {
|
||||
if(done) {
|
||||
this.timer = window.setTimeout(function() {
|
||||
// There can be some odd cross-interference with the UI modules and their initialization.
|
||||
// We use a significant delay here to avoid said problems.
|
||||
done();
|
||||
}, uiLoadDelay ? 2000 : 0);
|
||||
}
|
||||
} else if(!this.killSwitch) {
|
||||
this.timer = window.setTimeout(this.initCheckCallback, 50);
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
if(timeout) {
|
||||
window.setTimeout(function() {
|
||||
done();
|
||||
}, timeout ? timeout : 1000);
|
||||
} else {
|
||||
initTimer(done);
|
||||
this.killSwitch = true;
|
||||
|
||||
if(this.observer) {
|
||||
this.observer.end();
|
||||
}
|
||||
|
||||
if(this.timer) {
|
||||
window.clearTimeout(this.timer);
|
||||
this.timer = 0;
|
||||
}
|
||||
}.bind(this), timeout);
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
|
||||
var im = new InitializationManager();
|
||||
return im.initCheckCallback;
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue