mirror of
https://github.com/ether/etherpad-lite.git
synced 2026-05-04 19:56:37 +02:00
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) <noreply@anthropic.com>
This commit is contained in:
parent
faad9a8150
commit
f7f2a5bd29
41
src/tests/backend/specs/settings_cjs_compat.ts
Normal file
41
src/tests/backend/specs/settings_cjs_compat.ts
Normal file
@ -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;
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user