From f7f2a5bd29b3ef8e58c284023db0be49e429219a Mon Sep 17 00:00:00 2001 From: John McLear Date: Mon, 6 Apr 2026 16:41:03 +0100 Subject: [PATCH] test: add regression tests for Settings CJS compatibility layer Verify that CJS consumers (plugins) can both read and write settings properties directly on the module.exports object, and that writes propagate to the underlying ESM default export. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../backend/specs/settings_cjs_compat.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/tests/backend/specs/settings_cjs_compat.ts diff --git a/src/tests/backend/specs/settings_cjs_compat.ts b/src/tests/backend/specs/settings_cjs_compat.ts new file mode 100644 index 000000000..c31fcebd3 --- /dev/null +++ b/src/tests/backend/specs/settings_cjs_compat.ts @@ -0,0 +1,41 @@ +'use strict'; + +import {describe, it} from 'mocha'; +import assert from 'assert'; + +describe('Settings CJS compatibility', function () { + it('CJS require can read settings properties directly', async function () { + // Simulate CJS require - the module.exports compatibility layer should + // expose settings properties directly (not under .default) + const settings = require('ep_etherpad-lite/node/utils/Settings'); + assert(settings.root != null, 'settings.root should be accessible'); + assert(typeof settings.port === 'number', 'settings.port should be a number'); + }); + + it('CJS require can write settings properties', async function () { + // Regression test: the CJS compatibility layer must have setters, + // not just getters, so plugins can mutate settings (e.g. in tests). + const settings = require('ep_etherpad-lite/node/utils/Settings'); + const original = settings.requireAuthentication; + try { + settings.requireAuthentication = !original; + assert.strictEqual(settings.requireAuthentication, !original, + 'setting should be writable via CJS require'); + } finally { + settings.requireAuthentication = original; + } + }); + + it('CJS writes are visible through ESM default import', async function () { + const settingsCjs = require('ep_etherpad-lite/node/utils/Settings'); + const {default: settingsEsm} = await import('ep_etherpad-lite/node/utils/Settings'); + const original = settingsCjs.title; + try { + settingsCjs.title = 'CJS_TEST_VALUE'; + assert.strictEqual(settingsEsm.title, 'CJS_TEST_VALUE', + 'CJS setter should update the same underlying object as ESM import'); + } finally { + settingsCjs.title = original; + } + }); +});