Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/generators/ast/__tests__/generate.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import assert from 'node:assert/strict';
import { describe, it, mock } from 'node:test';

// Mock dependencies
const mockReadFile = mock.fn();
mock.module('node:fs/promises', {
namedExports: { readFile: mockReadFile },
});

// Mock other internal modules as needed
// From src/generators/ast/__tests__/ to src/utils/configuration/index.mjs is ../../../utils/configuration/index.mjs
mock.module('../../../utils/configuration/index.mjs', {
defaultExport: () => ({ ast: { input: 'docs/*.md' } }),
});

const { processChunk } = await import('../generate.mjs');

describe('ast/generate.mjs error handling', () => {
it('should bubble readFile errors to the caller', async () => {
const error = new Error('FS_ERROR');
mockReadFile.mock.mockImplementation(async () => {
throw error;
});

const inputSlice = ['test.md'];
const itemIndices = [0];

await assert.rejects(
async () => await processChunk(inputSlice, itemIndices),
err => {
assert.strictEqual(err, error);
return true;
}
);
});
});
2 changes: 1 addition & 1 deletion src/generators/ast/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function processChunk(inputSlice, itemIndices) {

results.push({
tree: remarkProcessor.parse(vfile),
file: { stem: vfile.stem, basename: vfile.basename },
file: { stem: vfile.stem, basename: vfile.basename, path },
});
}

Expand Down
53 changes: 53 additions & 0 deletions src/generators/metadata/__tests__/generate.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
);
});
});
Loading