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.
85 lines
2.7 KiB
JavaScript
85 lines
2.7 KiB
JavaScript
'use strict';
|
|
(async () => {
|
|
|
|
// Plain-Node unit test (no Meteor) for copying a card's subtasks.
|
|
// Run: node tests/subtaskCopy.test.cjs
|
|
//
|
|
// Regression guard for #3185 ("Template with subtasks and checklists"). Copying
|
|
// a card inserted each subtask as a bare card document, dropping the subtask's
|
|
// checklists so the copied subtasks came out empty. The subtask copy must be
|
|
// re-homed correctly AND must reproduce its checklists.
|
|
|
|
const assert = require('assert');
|
|
const {
|
|
buildCopiedSubtaskFields,
|
|
subtaskCopyChildKinds,
|
|
} = await import('../models/lib/subtaskCopy.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
const SUBTASK = {
|
|
_id: 'sub1',
|
|
title: 'a subtask',
|
|
parentId: 'oldParent',
|
|
boardId: 'srcBoard',
|
|
swimlaneId: 'srcSwim',
|
|
listId: 'srcList',
|
|
sort: 2,
|
|
};
|
|
const TARGET = { newParentId: 'newParent', boardId: 'dstB', swimlaneId: 'dstS', listId: 'dstL' };
|
|
|
|
// --- POSITIVE: the subtask copy is re-homed under the new parent/board -------
|
|
test('re-parents to the new parent card', () => {
|
|
assert.strictEqual(buildCopiedSubtaskFields(SUBTASK, TARGET).parentId, 'newParent');
|
|
});
|
|
|
|
test('re-homes onto the destination board / swimlane / list', () => {
|
|
const f = buildCopiedSubtaskFields(SUBTASK, TARGET);
|
|
assert.strictEqual(f.boardId, 'dstB');
|
|
assert.strictEqual(f.swimlaneId, 'dstS');
|
|
assert.strictEqual(f.listId, 'dstL');
|
|
});
|
|
|
|
test('drops _id so a NEW subtask document is inserted', () => {
|
|
assert.ok(!('_id' in buildCopiedSubtaskFields(SUBTASK, TARGET)));
|
|
});
|
|
|
|
test('preserves other fields (title, sort)', () => {
|
|
const f = buildCopiedSubtaskFields(SUBTASK, TARGET);
|
|
assert.strictEqual(f.title, 'a subtask');
|
|
assert.strictEqual(f.sort, 2);
|
|
});
|
|
|
|
test('does not mutate the source subtask', () => {
|
|
buildCopiedSubtaskFields(SUBTASK, TARGET);
|
|
assert.strictEqual(SUBTASK._id, 'sub1');
|
|
assert.strictEqual(SUBTASK.parentId, 'oldParent');
|
|
assert.strictEqual(SUBTASK.boardId, 'srcBoard');
|
|
});
|
|
|
|
// --- NEGATIVE: the #3185 regression — checklists must be copied too ----------
|
|
test('NEGATIVE: a subtask copy MUST reproduce checklists (#3185)', () => {
|
|
assert.ok(
|
|
subtaskCopyChildKinds().includes('checklists'),
|
|
'copying a subtask must also copy its checklists',
|
|
);
|
|
});
|
|
|
|
test('NEGATIVE: the copy must never keep the OLD parent id (orphan) ...', () => {
|
|
const f = buildCopiedSubtaskFields(SUBTASK, TARGET);
|
|
assert.notStrictEqual(f.parentId, 'oldParent');
|
|
});
|
|
|
|
test('NEGATIVE: ... nor the SOURCE board id (would strand the subtask)', () => {
|
|
const f = buildCopiedSubtaskFields(SUBTASK, TARGET);
|
|
assert.notStrictEqual(f.boardId, 'srcBoard');
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|
|
|
|
})().catch(e => { console.error(e); process.exit(1); }); |