test: add initial testing and linting (#18)

This commit is contained in:
Morten Olsen
2025-05-19 21:04:32 +02:00
committed by GitHub
parent 9d04cf0414
commit c01dce4998
33 changed files with 4159 additions and 299 deletions

View File

@@ -1,25 +1,18 @@
import { dirname, resolve } from 'path';
import { toString } from 'mdast-util-to-string'
import { execute, type ExecutionHandler } from '../execution.js';
import { FileNotFoundError } from '../../utils/errors.js';
import { existsSync } from 'fs';
const fileHandler: ExecutionHandler = ({
addStep,
node,
parent,
index,
file,
}) => {
import { toString } from 'mdast-util-to-string';
import { execute, type ExecutionHandler } from '../execution.js';
import { FileNotFoundError } from '../../utils/errors.js';
const fileHandler: ExecutionHandler = ({ addStep, node, parent, index, file }) => {
if (node.type === 'leafDirective' && node.name === 'md') {
addStep({
type: 'file',
node,
action: async ({ context }) => {
const filePath = resolve(
dirname(file),
toString(node)
);
const filePath = resolve(dirname(file), toString(node));
if (!existsSync(filePath)) {
throw new FileNotFoundError(filePath);
}
@@ -37,10 +30,10 @@ const fileHandler: ExecutionHandler = ({
parent.children?.splice(index, 1);
return;
}
parent.children?.splice(index, 1, ...newRoot.children as any);
parent.children?.splice(index, 1, ...(newRoot.children as ExpectedAny[]));
},
})
});
}
}
};
export { fileHandler };