Fix bibliographyTest breakage after d5cf33a798

d5cf33a798 adds a `yield` to bibliography.js, which runs in modal
windows (e.g., Create Bib), but there's a weird interaction between
Bluebird and modal dialogs that can result in hangs -- presumably
something to do with things being queued on the event loop but the modal
dialog preventing other code from running? This was breaking
bibliographyTest, but it seemed to work fine for me in normal usage,
waiting properly for a running styles initialization to finish. It's
possible this problem is limited to tests, but in the past, at least, I
apparently decided that this was a general problem with `yield` in modal
dialogs [1]. (See also: [2].) In any case, calling `yield
Zotero.Styles.init()` from the Create Bib window was hanging the test,
so for now do a synchronous check for style initialization to avoid it,
and we should make sure that `yield` actually works in other contexts.

[1] https://github.com/zotero/zotero/commit/99dd1c069776
[2] https://github.com/zotero/zotero/commit/c2dd531cec4
This commit is contained in:
Dan Stillman 2017-04-13 04:19:55 -04:00
parent ed3b18ba8c
commit 9b53570968
2 changed files with 13 additions and 2 deletions

View file

@ -67,8 +67,11 @@ var Zotero_File_Interface_Bibliography = new function() {
_io.style = Zotero.Prefs.get("export.lastStyle");
}
// Initialize styles
yield Zotero.Styles.init();
// See note in style.js
if (!Zotero.Styles.initialized) {
// Initialize styles
yield Zotero.Styles.init();
}
// add styles to list

View file

@ -117,6 +117,14 @@ Zotero.Styles = new function() {
});
this.init = Zotero.lazy(this.reinit);
// This is used by bibliography.js to work around a weird interaction between Bluebird and modal
// dialogs in tests. Calling `yield Zotero.Styles.init()` from `Zotero_File_Interface_Bibliography.init()`
// in the modal Create Bibliography dialog results in a hang, so instead use a synchronous check for
// initialization. The hang doesn't seem to happen (at least in the same way) outside of tests.
this.initialized = function () {
return _initialized;
};
/**
* Reads all styles from a given directory and caches their metadata
* @private