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.
76 lines
2.8 KiB
JavaScript
76 lines
2.8 KiB
JavaScript
'use strict';
|
|
(async () => {
|
|
|
|
// Plain-Node unit test (no Meteor) for comment-activity display text.
|
|
// Run: node tests/commentActivity.test.cjs
|
|
//
|
|
// Regression guard for #3606 ("activity feed shows 'edited/deleted comment
|
|
// undefined'"). The template fed the comment ID (undefined on older activities,
|
|
// and gone for a deleted comment) into the activity string. edit/delete
|
|
// activities now store commentText; commentActivityDisplayText() returns the
|
|
// stored text, else the live comment's text, else '' — never "undefined".
|
|
|
|
const assert = require('assert');
|
|
const { commentActivityDisplayText } = await import('../models/lib/commentActivity.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
// --- POSITIVE ---------------------------------------------------------------
|
|
test('stored commentText is used (delete case — comment doc already gone)', () => {
|
|
assert.strictEqual(
|
|
commentActivityDisplayText({ commentText: 'please review this' }),
|
|
'please review this',
|
|
);
|
|
});
|
|
|
|
test('falls back to the live comment text (edit case)', () => {
|
|
assert.strictEqual(
|
|
commentActivityDisplayText({ comment: { text: 'edited body' } }),
|
|
'edited body',
|
|
);
|
|
});
|
|
|
|
test('stored text wins over live comment text', () => {
|
|
assert.strictEqual(
|
|
commentActivityDisplayText({ commentText: 'snapshot', comment: { text: 'live' } }),
|
|
'snapshot',
|
|
);
|
|
});
|
|
|
|
test('empty string commentText is respected (not replaced by fallback)', () => {
|
|
assert.strictEqual(commentActivityDisplayText({ commentText: '' }), '');
|
|
});
|
|
|
|
// --- NEGATIVE: the literal string "undefined" must never appear (#3606) ------
|
|
test('NEGATIVE: no text available yields "" not the word "undefined"', () => {
|
|
const out = commentActivityDisplayText({ commentId: 'abc123' });
|
|
assert.strictEqual(out, '');
|
|
assert.notStrictEqual(out, 'undefined');
|
|
assert.strictEqual(String(out).includes('undefined'), false);
|
|
});
|
|
|
|
test('NEGATIVE: an activity that only has an id (old data) does not render the id', () => {
|
|
const out = commentActivityDisplayText({ commentId: 'someCommentId' });
|
|
assert.notStrictEqual(out, 'someCommentId');
|
|
});
|
|
|
|
test('NEGATIVE: null / undefined activity does not throw', () => {
|
|
assert.doesNotThrow(() => commentActivityDisplayText(null));
|
|
assert.strictEqual(commentActivityDisplayText(null), '');
|
|
assert.strictEqual(commentActivityDisplayText(undefined), '');
|
|
});
|
|
|
|
test('NEGATIVE: non-string commentText / malformed comment do not leak "undefined"', () => {
|
|
assert.strictEqual(commentActivityDisplayText({ commentText: 42 }), '');
|
|
assert.strictEqual(commentActivityDisplayText({ comment: {} }), '');
|
|
assert.strictEqual(commentActivityDisplayText({ comment: null }), '');
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|
|
|
|
})().catch(e => { console.error(e); process.exit(1); }); |