mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -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.
99 lines
3.7 KiB
JavaScript
99 lines
3.7 KiB
JavaScript
'use strict';
|
|
(async () => {
|
|
|
|
// Plain-Node unit test (no Meteor) for the linked-card member target helpers.
|
|
// Run: node tests/linkedCardMembers.test.cjs
|
|
//
|
|
// Regression guard for #5676 ("Bug: Can not add members to Linked Card"): a
|
|
// linked card's members are stored on the REAL card it points at (on another
|
|
// board), which is what getMembers()/assignMember() act on — but the member
|
|
// picker used to list the *viewing* board's members. memberTargetBoardId() must
|
|
// resolve a linked card to its real card's board (so the picker matches where
|
|
// membership is stored), and memberTargetCardId() must resolve to the real card
|
|
// id that member changes are written to. Normal cards and linked-board cards must
|
|
// keep their own board.
|
|
|
|
const assert = require('assert');
|
|
const {
|
|
memberTargetCardId,
|
|
memberTargetBoardId,
|
|
} = await import('../models/lib/linkedCardMembers.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
// Real card on board A; a linked card on board B points at it.
|
|
const realCard = { _id: 'realA', boardId: 'boardA', type: 'card' };
|
|
const linkedCard = {
|
|
_id: 'linkB',
|
|
boardId: 'boardB',
|
|
type: 'cardType-linkedCard',
|
|
linkedId: 'realA',
|
|
};
|
|
const resolve = id => (id === 'realA' ? realCard : undefined);
|
|
|
|
// --- memberTargetCardId ------------------------------------------------------
|
|
test('linked card resolves to the real card id for member writes', () => {
|
|
assert.strictEqual(memberTargetCardId(linkedCard), 'realA');
|
|
});
|
|
|
|
test('normal card targets its own id', () => {
|
|
assert.strictEqual(memberTargetCardId(realCard), 'realA');
|
|
});
|
|
|
|
test('memberTargetCardId is null-safe', () => {
|
|
assert.strictEqual(memberTargetCardId(null), null);
|
|
assert.strictEqual(memberTargetCardId({ type: 'card' }), null);
|
|
});
|
|
|
|
// --- memberTargetBoardId: POSITIVE ------------------------------------------
|
|
test('#5676: linked card resolves to the REAL card\'s board (not the viewing board)', () => {
|
|
const boardId = memberTargetBoardId(linkedCard, resolve);
|
|
assert.strictEqual(boardId, 'boardA');
|
|
// and crucially NOT the board the linked card is viewed on
|
|
assert.notStrictEqual(boardId, 'boardB');
|
|
});
|
|
|
|
test('normal card uses its own board', () => {
|
|
assert.strictEqual(memberTargetBoardId(realCard, resolve), 'boardA');
|
|
});
|
|
|
|
test('linked-board card uses the linked board id itself', () => {
|
|
const linkedBoardCard = {
|
|
_id: 'lbc',
|
|
boardId: 'boardB',
|
|
type: 'cardType-linkedBoard',
|
|
linkedId: 'boardX',
|
|
};
|
|
assert.strictEqual(memberTargetBoardId(linkedBoardCard, resolve), 'boardX');
|
|
});
|
|
|
|
// --- memberTargetBoardId: NEGATIVE ------------------------------------------
|
|
test('linked card whose real card is not loaded yet resolves to null (caller falls back)', () => {
|
|
const orphan = { type: 'cardType-linkedCard', linkedId: 'missing' };
|
|
assert.strictEqual(memberTargetBoardId(orphan, resolve), null);
|
|
});
|
|
|
|
test('linked card with no resolver does not throw and returns null', () => {
|
|
assert.strictEqual(memberTargetBoardId(linkedCard, undefined), null);
|
|
});
|
|
|
|
test('a linked card must NOT fall back to the viewing board when unresolved', () => {
|
|
// Guards the bug: returning boardB here would re-introduce the wrong-board
|
|
// picker. Unresolved must be null so the caller decides the fallback.
|
|
const orphan = { boardId: 'boardB', type: 'cardType-linkedCard', linkedId: 'missing' };
|
|
assert.strictEqual(memberTargetBoardId(orphan, resolve), null);
|
|
});
|
|
|
|
test('memberTargetBoardId is null-safe', () => {
|
|
assert.strictEqual(memberTargetBoardId(null, resolve), null);
|
|
assert.strictEqual(memberTargetBoardId({ type: 'card' }, resolve), null);
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|
|
|
|
})().catch(e => { console.error(e); process.exit(1); }); |