-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathgenerate.test.mjs
More file actions
53 lines (45 loc) · 1.49 KB
/
generate.test.mjs
File metadata and controls
53 lines (45 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import assert from 'node:assert/strict';
import { describe, it, mock } from 'node:test';
// Mock dependencies
const mockParseApiDoc = mock.fn();
mock.module('../utils/parse.mjs', {
namedExports: { parseApiDoc: mockParseApiDoc },
});
// Mock configuration and URL utils
// From src/generators/metadata/__tests__/ to src/utils/ is ../../../utils/
mock.module('../../../utils/configuration/index.mjs', {
defaultExport: () => ({ metadata: { typeMap: 'typeMap.json' } }),
});
mock.module('../../../utils/url.mjs', {
namedExports: { importFromURL: async () => ({}) },
});
const { processChunk } = await import('../generate.mjs');
describe('metadata/generate.mjs error handling', () => {
it('should bubble parsing errors to the caller', async () => {
const error = new Error('PARSE_ERROR');
mockParseApiDoc.mock.mockImplementation(() => {
throw error;
});
const fullInput = [{ file: { path: 'docs/api/fs.md', basename: 'fs.md' } }];
const itemIndices = [0];
await assert.rejects(
async () => await processChunk(fullInput, itemIndices, {}),
err => {
assert.strictEqual(err, error);
return true;
}
);
});
it('should preserve non-Error throws from parseApiDoc', async () => {
mockParseApiDoc.mock.mockImplementation(() => {
throw 'PARSE_ERROR';
});
await assert.rejects(
async () => await processChunk([{}], [0], {}),
err => {
assert.strictEqual(err, 'PARSE_ERROR');
return true;
}
);
});
});