Files
wekan/tests/isomorphicGitRuntime.test.cjs
T
Lauri Ojansivu 189adaee52 Update imapflow, mailparser, pdfjs-dist, isomorphic-git and pretty-ms, with runtime tests.
imapflow 2.1.2 -> 2.8.0 and mailparser 3.9.31 -> 3.12.2 (email to card):
bug fixes, and mailparser no longer turns a decoded display name into an
address. pdfjs-dist 6.2.108 -> 6.4.299 (attachment text search),
isomorphic-git 1.42.4 -> 1.44.3 (GitHub wiki import), pretty-ms 9 -> 10
(upload time estimate; its breaking changes are in colonNotation, which
WeKan does not use, and the output it shows is unchanged).

Each now has a test that RUNS it the way WeKan calls it, so the next
update that moves an API fails in seconds:
- imapflowMailparserRuntime: the poller's connect, mailbox lock, unseen
  search, fetchOne, simpleParser and \Seen flag against
  server/lib/tests/fakeImapServer.js; a wrong password is refused, and an
  encoded address in a display name stays a name.
- pdfjsTextRuntime: documentGif.js's legacy build, worker, fonts, CMaps
  and getTextContent on a PDF with known text; a non-PDF is refused.
- isomorphicGitRuntime: githubWiki.js's log, recursive readTree and
  readBlob on a two-commit repository; a missing object is an error.

npm audit reports nothing. The e2e run against a build with these:
rules-blocks (147 languages), attachments, both email specs, and the
security specs pass, except two rules-blocks cases that fail the same way
on a build of the commit before this one.

Thanks to developers of dependencies and xet7 !
2026-10-22 06:34:36 +03:00

73 lines
3.5 KiB
JavaScript

'use strict';
// The installed isomorphic-git, read the way server/lib/githubWiki.js reads a
// cloned wiki: git.log with a depth, git.readTree recursing into subtrees, and
// git.readBlob - on a repository made here with isomorphic-git itself, with
// two commits that change one page and add another. The clone needs GitHub;
// everything after it is what this pins. isomorphic-git went 1.42.4 -> 1.44.3.
// Run: node tests/isomorphicGitRuntime.test.cjs
const assert = require('assert');
const fs = require('fs');
const os = require('os');
const path = require('path');
const git = require('isomorphic-git');
const ROOT = path.join(__dirname, '..');
(async () => {
const src = fs.readFileSync(path.join(ROOT, 'server/lib/githubWiki.js'), 'utf8');
for (const call of ['git.clone(', 'git.log(', 'git.readTree(', 'git.readBlob(']) {
assert.ok(src.includes(call), `githubWiki.js no longer calls ${call}; update this test`);
}
assert.ok(/noCheckout: true/.test(src), 'the clone writes no working tree');
const dir = fs.mkdtempSync(path.join(process.env.TMPDIR || os.tmpdir(), 'wekan-isogit-'));
const author = { name: 'Ann Example', email: 'ann@example.test' };
try {
await git.init({ fs, dir, defaultBranch: 'master' });
fs.writeFileSync(path.join(dir, 'Home.md'), 'First home\n');
await git.add({ fs, dir, filepath: 'Home.md' });
await git.commit({ fs, dir, author: { ...author, timestamp: 1700000000, timezoneOffset: 0 }, message: 'Create Home\n' });
fs.mkdirSync(path.join(dir, 'guides'));
fs.writeFileSync(path.join(dir, 'Home.md'), 'Second home\n');
fs.writeFileSync(path.join(dir, 'guides', 'Setup.md'), 'Setup page\n');
await git.add({ fs, dir, filepath: 'Home.md' });
await git.add({ fs, dir, filepath: 'guides/Setup.md' });
await git.commit({ fs, dir, author: { ...author, timestamp: 1700000100, timezoneOffset: 0 }, message: 'Add Setup\n' });
const commits = (await git.log({ fs, dir, depth: 200 })).reverse();
assert.deepStrictEqual(commits.map(c => c.commit.message.trim()), ['Create Home', 'Add Setup']);
assert.strictEqual(commits[0].commit.author.name, 'Ann Example');
assert.strictEqual(commits[1].commit.author.timestamp, 1700000100);
const files = async (oid, prefix = '') => {
const { tree } = await git.readTree({ fs, dir, oid });
const out = [];
for (const node of tree) {
const name = prefix ? `${prefix}/${node.path}` : node.path;
if (node.type === 'tree') out.push(...await files(node.oid, name));
else if (node.type === 'blob') out.push({ path: name, oid: node.oid });
}
return out;
};
const last = await files(commits[1].commit.tree);
assert.deepStrictEqual(last.map(f => f.path).sort(), ['Home.md', 'guides/Setup.md']);
const text = async f => Buffer.from((await git.readBlob({ fs, dir, oid: f.oid })).blob).toString('utf8');
assert.strictEqual(await text(last.find(f => f.path === 'Home.md')), 'Second home\n');
const first = await files(commits[0].commit.tree);
assert.strictEqual(await text(first.find(f => f.path === 'Home.md')), 'First home\n');
console.log(' ok - a wiki history reads back page by page, revision by revision');
// Negative: an object that is not there is an error, not empty text.
await assert.rejects(git.readBlob({ fs, dir, oid: '0'.repeat(40) }));
console.log(' ok - a missing object is an error (negative)');
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
console.log('\n2 passed');
})().catch((error) => {
console.error(error);
process.exit(1);
});