mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
The rspack client build treats a `module.exports` file imported into the
client bundle as an ES module and throws
"ES Modules may not assign module.exports" at evaluation time, aborting
the whole client module chain (No such template: swimlane / notifications
/ boardButtons, blank board, missing top bar). This is not an rspack
version regression (the lockfile has pinned ~1.7.x since v8.40); it is
that WeKan added CommonJS helpers to the client bundle.
Convert the 42 client-reachable pure-logic models/lib helpers from
`module.exports = { ... }` to `export { ... }`, and calendarFilter's
internal require('./swimlaneFilter') to an import with a .js extension
(node ESM needs it; rspack/reify tolerate it). Server-only helpers that
use node built-ins (fs/path/child_process) stay CommonJS. The plain-Node
.cjs unit tests for these helpers now use `await import(...js)` (wrapped
in an async IIFE); a source-guard in importVirtualMembers was updated
from module.exports to export. Verified: the full tests/*.test.cjs suite
has the SAME 7 pre-existing failures as before this change and no new
ones.
77 lines
3.1 KiB
JavaScript
77 lines
3.1 KiB
JavaScript
'use strict';
|
|
(async () => {
|
|
|
|
// Plain-Node unit test (no Meteor) for the linked-card cover resolver.
|
|
// Run: node tests/linkedCardCover.test.cjs
|
|
//
|
|
// Regression guard for #5666 ("Minicard connection without images"): a linked
|
|
// card's cover image lives on the real card it points at, but the cover helpers
|
|
// read `this.coverId` directly — and a linked card has no coverId of its own, so
|
|
// the cover never showed on the linking board. resolveCoverId() must hop a linked
|
|
// card to its real card's coverId, while leaving normal cards unchanged.
|
|
|
|
const assert = require('assert');
|
|
const {
|
|
coverSourceCard,
|
|
resolveCoverId,
|
|
} = await import('../models/lib/linkedCardCover.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
// Real card on board A with a cover; a linked card on board B points at it.
|
|
const realCard = { _id: 'realA', type: 'card', coverId: 'att-A' };
|
|
const linkedCard = { _id: 'linkB', type: 'cardType-linkedCard', linkedId: 'realA' };
|
|
const getCard = id => (id === 'realA' ? realCard : undefined);
|
|
|
|
// --- POSITIVE ---------------------------------------------------------------
|
|
test('#5666: a linked card resolves to the REAL card\'s cover id', () => {
|
|
assert.strictEqual(resolveCoverId(linkedCard, getCard), 'att-A');
|
|
assert.strictEqual(coverSourceCard(linkedCard, getCard), realCard);
|
|
});
|
|
|
|
test('a plain card resolves to its own cover id', () => {
|
|
assert.strictEqual(resolveCoverId(realCard, getCard), 'att-A');
|
|
});
|
|
|
|
test('a linked card ignores any stray coverId on the placeholder, using the real card', () => {
|
|
// Even if the linked-card placeholder somehow carried a coverId, the real
|
|
// card's cover is authoritative (guards the #5666 root cause directly).
|
|
const stray = { _id: 'linkB', type: 'cardType-linkedCard', linkedId: 'realA', coverId: 'stray' };
|
|
assert.strictEqual(resolveCoverId(stray, getCard), 'att-A');
|
|
});
|
|
|
|
// --- NEGATIVE ---------------------------------------------------------------
|
|
test('a plain card with no cover returns null', () => {
|
|
assert.strictEqual(resolveCoverId({ _id: 'x', type: 'card' }, getCard), null);
|
|
});
|
|
|
|
test('a linked card whose real card has no cover returns null', () => {
|
|
const realNoCover = { _id: 'realA', type: 'card' };
|
|
const linked = { _id: 'l', type: 'cardType-linkedCard', linkedId: 'realA' };
|
|
assert.strictEqual(resolveCoverId(linked, () => realNoCover), null);
|
|
});
|
|
|
|
test('a linked card whose real card is not loaded yet returns null (no throw)', () => {
|
|
const orphan = { _id: 'l', type: 'cardType-linkedCard', linkedId: 'missing' };
|
|
assert.strictEqual(resolveCoverId(orphan, getCard), null);
|
|
});
|
|
|
|
test('a linked card with no resolver returns null (no throw)', () => {
|
|
assert.strictEqual(resolveCoverId(linkedCard, undefined), null);
|
|
assert.strictEqual(coverSourceCard(linkedCard, undefined), null);
|
|
});
|
|
|
|
test('null / typeless cards are handled without throwing', () => {
|
|
assert.strictEqual(resolveCoverId(null, getCard), null);
|
|
assert.strictEqual(resolveCoverId(undefined, getCard), null);
|
|
assert.strictEqual(coverSourceCard(null, getCard), null);
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|
|
|
|
})().catch(e => { console.error(e); process.exit(1); }); |