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.
84 lines
3.1 KiB
JavaScript
84 lines
3.1 KiB
JavaScript
'use strict';
|
|
(async () => {
|
|
|
|
// Plain-Node unit test (no Meteor) for linked-card title update targets.
|
|
// Run: node tests/linkedCardTitle.test.cjs
|
|
//
|
|
// Regression guard for #4249 ("sometimes filter by card title doesn't work").
|
|
// Renaming a linked card updated only the linked target's title, leaving the
|
|
// linking card's OWN `title` stale; filter-by-title queries the own field, so
|
|
// the linked card dropped out of title filters after a rename.
|
|
// computeTitleUpdateTargets() must ALWAYS include the linking card's own
|
|
// document, plus the linked target.
|
|
|
|
const assert = require('assert');
|
|
const { computeTitleUpdateTargets } = await import('../models/lib/linkedCardTitle.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
// --- POSITIVE ---------------------------------------------------------------
|
|
test('normal card writes only its own document', () => {
|
|
const t = computeTitleUpdateTargets({ _id: 'c1', type: 'card' });
|
|
assert.deepStrictEqual(t, [{ collection: 'cards', id: 'c1' }]);
|
|
});
|
|
|
|
test('linked card writes own doc AND the original card', () => {
|
|
const t = computeTitleUpdateTargets({
|
|
_id: 'link1', linkedId: 'orig1', type: 'cardType-linkedCard',
|
|
});
|
|
assert.deepStrictEqual(t, [
|
|
{ collection: 'cards', id: 'link1' },
|
|
{ collection: 'cards', id: 'orig1' },
|
|
]);
|
|
});
|
|
|
|
test('linked board writes own card doc AND the linked board', () => {
|
|
const t = computeTitleUpdateTargets({
|
|
_id: 'link2', linkedId: 'board9', type: 'cardType-linkedBoard',
|
|
});
|
|
assert.deepStrictEqual(t, [
|
|
{ collection: 'cards', id: 'link2' },
|
|
{ collection: 'boards', id: 'board9' },
|
|
]);
|
|
});
|
|
|
|
// --- NEGATIVE: the #4249 regression — own doc must never be skipped ----------
|
|
test('NEGATIVE: a linked card ALWAYS updates its own document (filter fix)', () => {
|
|
const t = computeTitleUpdateTargets({
|
|
_id: 'link1', linkedId: 'orig1', type: 'cardType-linkedCard',
|
|
});
|
|
assert.ok(
|
|
t.some(x => x.collection === 'cards' && x.id === 'link1'),
|
|
'the linking card\'s own doc must be written so filter-by-title matches',
|
|
);
|
|
});
|
|
|
|
test('NEGATIVE: a linked card whose target write was the ONLY write (old bug) is gone', () => {
|
|
const t = computeTitleUpdateTargets({
|
|
_id: 'link1', linkedId: 'orig1', type: 'cardType-linkedCard',
|
|
});
|
|
// Old behavior wrote only { id: 'orig1' }. Now there must be >= 2 targets and
|
|
// the own doc must be present.
|
|
assert.ok(t.length >= 2);
|
|
assert.notDeepStrictEqual(t, [{ collection: 'cards', id: 'orig1' }]);
|
|
});
|
|
|
|
test('NEGATIVE: linked card with missing linkedId still writes its own doc', () => {
|
|
const t = computeTitleUpdateTargets({ _id: 'link1', type: 'cardType-linkedCard' });
|
|
assert.deepStrictEqual(t, [{ collection: 'cards', id: 'link1' }]);
|
|
});
|
|
|
|
test('NEGATIVE: null / id-less card yields no targets, no throw', () => {
|
|
assert.doesNotThrow(() => computeTitleUpdateTargets(null));
|
|
assert.deepStrictEqual(computeTitleUpdateTargets(null), []);
|
|
assert.deepStrictEqual(computeTitleUpdateTargets({ type: 'card' }), []);
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|
|
|
|
})().catch(e => { console.error(e); process.exit(1); }); |