Context
The translator tester (accessible in the debug build of the connector extension) is supposed to run the tests for the translators specified on the URL.
This is used by the Selenium-driven test for pull requests in zotero/translators, but this test (most of the time) does not actually run:
https://github.com/zotero/translators/blob/3a9544d7b0b6fdcb6cdcbc8c08392f91d20d99b4/.ci/pull-request-check/selenium-test.js#L128-L130
The problem
I think the problem is that, when runURLSpecifiedTranslators() is called at the end of init(), most likely the translators have not been loaded into the global object translatorTestViewsToRun which is used by the function to identify the translator(s) to run:
|
async function runURLSpecifiedTranslators() { |
|
const href = document.location.href; |
|
let hashParams = href.split('#')[1]; |
|
if (!hashParams) return; |
|
|
|
let translatorIDs = new Set(hashParams.split('translators=')[1].split(',').map(decodeURI)); |
|
let translatorTestViews = []; |
|
for (let type in translatorTestViewsToRun) { |
|
for (const translatorTestView of translatorTestViewsToRun[type]) { |
|
if (translatorIDs.has(translatorTestView._translatorTester.translator.translatorID)) { |
|
translatorTestViews.push(translatorTestView); |
But the sequence of calls is like the following:
init() calls haveTranslators() which returns a promise that is not awaited/then-handled. (The following snippet is the call site, and itself is inside one big initialization loop waited for by await Promise.all(...) on Line 428.
|
// get translators, with code for unsupported translators |
|
if(!viewerMode) { |
|
let translators = await Zotero.Translators.getAllForType(translatorType, true); |
|
haveTranslators(translators, translatorType); |
|
} |
Then the init() function runs its course, and makes the call to runURLSpecifiedTranslators() at the very end:
|
|
|
// Run translators specified in the hash params if any |
|
runURLSpecifiedTranslators(); |
|
} |
|
} |
And by this time when runURLSpecifiedTranslators() accesses translatorTestViewsToRun, the haveTranslators() function likely has not been called (enough times) yet, so translatorTestViewsToRun is empty or incomplete.
Impact
Because of this, the following lines in runURLSpecifiedTranslators() are executed without the tests being actually run.
|
var elem = document.createElement('p'); |
|
elem.setAttribute('id', 'translator-tests-complete'); |
|
document.body.appendChild(elem); |
That is to say, the page falsely reports that the tests passed by the URL are complete. This can even happen if the URL-passed translator ID is invalid.
Context
The translator tester (accessible in the debug build of the connector extension) is supposed to run the tests for the translators specified on the URL.
This is used by the Selenium-driven test for pull requests in zotero/translators, but this test (most of the time) does not actually run:
https://github.com/zotero/translators/blob/3a9544d7b0b6fdcb6cdcbc8c08392f91d20d99b4/.ci/pull-request-check/selenium-test.js#L128-L130
The problem
I think the problem is that, when
runURLSpecifiedTranslators()is called at the end ofinit(), most likely the translators have not been loaded into the global objecttranslatorTestViewsToRunwhich is used by the function to identify the translator(s) to run:translate/testTranslators/testTranslators.js
Lines 580 to 590 in fcb7b8a
But the sequence of calls is like the following:
init()callshaveTranslators()which returns a promise that is notawaited/then-handled. (The following snippet is the call site, and itself is inside one big initialization loop waited for byawait Promise.all(...)on Line 428.translate/testTranslators/testTranslators.js
Lines 474 to 478 in fcb7b8a
Then the
init()function runs its course, and makes the call torunURLSpecifiedTranslators()at the very end:translate/testTranslators/testTranslators.js
Lines 532 to 536 in fcb7b8a
And by this time when
runURLSpecifiedTranslators()accessestranslatorTestViewsToRun, thehaveTranslators()function likely has not been called (enough times) yet, sotranslatorTestViewsToRunis empty or incomplete.Impact
Because of this, the following lines in
runURLSpecifiedTranslators()are executed without the tests being actually run.translate/testTranslators/testTranslators.js
Lines 599 to 601 in fcb7b8a
That is to say, the page falsely reports that the tests passed by the URL are complete. This can even happen if the URL-passed translator ID is invalid.