Zotero Connectors have two complementary testing modes. The first is a Mocha + Puppeteer integration suite that launches a real Chromium browser with the extension loaded and exercises the full extension stack — background service worker, injected scripts, and in-browser APIs. The second is the Translator Tester — an interactive UI bundled only in debug builds that lets you run translators against live or local pages and inspect the results in real time.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/zotero/zotero-connectors/llms.txt
Use this file to discover all available pages before exploring further.
Running the Test Suite
Quick start
npm test invokes mocha, which reads .mocharc.js for configuration.
Using scripts/runtests.sh
The helper script scripts/runtests.sh wraps npm test with convenient flags:
| Flag | Environment variable set | Effect |
|---|---|---|
-i | HEADLESS=true | Launch Puppeteer in headless mode |
-c | NO_QUIT=true | Do not quit browser on completion |
-d | DEBUG=true | Enable debug logging |
-f | (mocha --bail) | Stop after first failure |
-g PATTERN | (mocha --grep) | Filter tests by pattern |
Environment variables passed to build.sh
When build.sh is called with TEST_CHROME=1 or TEST_FX=1 set in the environment it automatically selects the browserExt target so there is no need to pass -p b separately:
Mocha Configuration (.mocharc.js)
spec— all files matchingtest/tests/**/*Test.mjsare picked up automaticallytimeout— individual async test steps get 5 seconds; increase with--timeoutif your machine is slowui: 'bdd'— tests usedescribe/it/before/afterreporter: 'spec'— nested output with pass/fail indicators
Test File Locations
In-extension test data lives under
src/common/test/data/. These HTML pages are copied into the build and used as fixture pages for translator tests:DOI-multiple.htmlframePDF.htmlgoogleDocs-integration.htmljournalArticle-single.htmltop-DOI-frame-COInS.html
journalArticle-single.html is also listed in the manifest’s web_accessible_resources so injected scripts can load it directly.Puppeteer Integration
Puppeteer (puppeteer ^24.8.0) is a devDependency that allows Mocha tests to drive a real Chromium instance. The setup module test/support/puppeteerSetup.mjs handles the lifecycle:
browser instance via globalThis.browser to open pages, interact with the extension popup, inspect the background service worker, and assert on network calls.
The Translator Tester UI
The translator tester is a full-page debugging tool bundled only in debug builds (when./build.sh -d is used). It is excluded from production builds by the gulp pipeline.
Enabling the translator tester
The-d flag to build.sh includes several extra files in each browser directory:
tools/testTranslators/testTranslators.html+testTranslators.js+testTranslators.css— the tester UItools/testTranslators/translatorTester_background.js— background page integrationtools/testTranslators/translatorTester_inject.js— injected page integrationtools/testTranslators/translatorTester_messages.js— message types for the testertools/testTranslators/translatorTester_environment.mjs— test environment helpers (sourced from thetranslatesubmodule)
lib/sinon.js) in debug builds for spy/stub support.
Opening the translator tester
From the Preferences → Advanced pane, click Open Translator Tester. The button calls:The ALWAYS_FETCH_FROM_REPOSITORY flag
In src/common/zotero_config.js the flag ALWAYS_FETCH_FROM_REPOSITORY defaults to false. When developing translators you can set the ZOTERO_ALWAYS_FETCH_FROM_REPOSITORY environment variable before building to force the connector to fetch translator code from the repository on every request instead of using the local cache:
Debugging Tips
Zotero.debug() logging
Call
Zotero.debug("message") anywhere in the extension. In debug builds (isDebug = true) output goes to the browser’s background service-worker console. In production it is silently suppressed unless debug logging is enabled from Preferences.Debug output console
Open Preferences → Advanced → View Output to read the stored debug log. Use Submit Output to send a report to the Zotero server and receive a report ID for bug reports.
Enable logging at startup
Check Enable logging at startup in Preferences → Advanced to store debug output across extension restarts (sets
Zotero.Prefs.set('debug.store', true)).Report translation failures
The Report translation failures checkbox (controlled by the
reportTranslationFailure preference) sends automatic error reports when a translator crashes, helping maintainers identify broken translators.CI Pipeline
The CI workflow in.github/workflows/ci.yml builds the extension in debug mode and then runs the full test suite in headless mode with bail on first failure:
-i flag sets HEADLESS=true; -f passes --bail to Mocha so the first failure immediately stops the run.