Skip to content

Commit dda3d3f

Browse files
test: cover real Git inventory execution path
1 parent 7be104f commit dda3d3f

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import test from 'node:test';
2+
import assert from 'node:assert/strict';
3+
import fs from 'node:fs';
4+
import os from 'node:os';
5+
import path from 'node:path';
6+
import { spawnSync } from 'node:child_process';
7+
import { fileURLToPath } from 'node:url';
8+
import { buildInventory } from '../lib/inventory.mjs';
9+
import { projectPaths, writeJson } from '../lib/core.mjs';
10+
11+
const testDir = path.dirname(fileURLToPath(import.meta.url));
12+
const engineRoot = path.resolve(testDir, '..');
13+
14+
function fixture() {
15+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'docgen-git-inventory-'));
16+
const paths = projectPaths(root);
17+
fs.mkdirSync(path.join(root, 'src'), { recursive: true });
18+
fs.mkdirSync(path.dirname(paths.config), { recursive: true });
19+
writeJson(paths.project, { schemaVersion: '2.0', kitVersion: '2.0.0' });
20+
writeJson(paths.config, {
21+
schemaVersion: '2.0',
22+
ignore: {
23+
useGitignore: true,
24+
useDocgenignore: true,
25+
binary: { enabled: true, maxTextFileBytes: 1024 * 1024 }
26+
},
27+
execution: { progress: false }
28+
});
29+
return root;
30+
}
31+
32+
test('git-aware inventory executes native git path enumeration', () => {
33+
const root = fixture();
34+
const init = spawnSync('git', ['init'], { cwd: root, encoding: 'utf8' });
35+
assert.equal(init.status, 0, init.stderr || init.stdout);
36+
fs.writeFileSync(path.join(root, 'src', 'Tracked.java'), 'class Tracked {}\n');
37+
fs.writeFileSync(path.join(root, 'ignored.log'), 'ignore me\n');
38+
fs.writeFileSync(path.join(root, '.gitignore'), '*.log\n');
39+
40+
const inventory = buildInventory(root);
41+
assert(inventory.files.some((item) => item.path === 'src/Tracked.java'));
42+
assert(!inventory.files.some((item) => item.path === 'ignored.log'));
43+
});
44+
45+
test('shipped JavaScript contains no misspelled Boolean global', () => {
46+
const stack = [engineRoot];
47+
const offenders = [];
48+
while (stack.length) {
49+
const dir = stack.pop();
50+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
51+
if (['node_modules', '.git'].includes(entry.name)) continue;
52+
const file = path.join(dir, entry.name);
53+
if (entry.isDirectory()) stack.push(file);
54+
else if (/\.(?:mjs|js|cjs)$/.test(entry.name) && /\bBolean\b/.test(fs.readFileSync(file, 'utf8'))) {
55+
offenders.push(path.relative(engineRoot, file));
56+
}
57+
}
58+
}
59+
assert.deepEqual(offenders, []);
60+
});

0 commit comments

Comments
 (0)