Skip to content

Commit

Permalink
🧪 Update tests and types for new toc
Browse files Browse the repository at this point in the history
  • Loading branch information
fwkoch committed May 22, 2024
1 parent 46d00cc commit 6a1d956
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/myst-cli/src/project/fromTOC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export function projectFromTOC(
): Omit<LocalProject, 'bibliography'> {
const pageSlugs: PageSlugs = {};
const [root, ...entries] = toc;
if (!root) {
throw new Error('Project TOC must have at least one item');
}
if (!isFile(root)) {
throw new Error(`First TOC item should be a file`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-cli/src/store/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const config = createSlice({
currentProjectPath: string | undefined;
currentSitePath: string | undefined;
rawConfigs: Record<string, { raw: Record<string, any>; validated: ValidatedRawConfig }>;
projects: Record<string, ProjectConfig>;
projects: Record<string, Record<string, any>>;
sites: Record<string, Record<string, any>>;
filenames: Record<string, string>;
configExtensions?: string[];
Expand Down
11 changes: 11 additions & 0 deletions packages/myst-frontmatter/src/exports/exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,17 @@ cases:
sub_articles:
- a.md
errors: 1
- title: export with invalid toc errors
raw:
exports:
- format: pdf
toc:
- foo.md
normalized:
exports:
- format: pdf
toc: []
errors: 1
- title: zip passes
raw:
exports:
Expand Down
4 changes: 3 additions & 1 deletion packages/myst-frontmatter/src/exports/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { TOC } from 'myst-toc';

export enum ExportFormats {
pdf = 'pdf',
tex = 'tex',
Expand All @@ -22,7 +24,7 @@ export type Export = {
template?: string | null;
output?: string;
zip?: boolean;
toc?: any[];
toc?: TOC;
articles?: ExportArticle[];
top_level?: 'parts' | 'chapters' | 'sections';
/** sub_articles are only for jats xml export */
Expand Down
2 changes: 1 addition & 1 deletion packages/myst-toc/src/toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,5 @@ export function validateEntry(entry: any, opts: ValidationOptions): Entry | unde
export function validateTOC(toc: any, opts: ValidationOptions): TOC | undefined {
return validateList(toc, opts, (item, ind) =>
validateEntry(item, incrementOptions(`${ind}`, opts)),
) as unknown as TOC | undefined;
);
}
12 changes: 12 additions & 0 deletions packages/myst-toc/tests/examples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,15 @@ test('Single parent entry without title', () => {
]);
expect(opts.messages.warnings).toBeUndefined();
});

test('invalid toc entry', () => {
const input = ['invalid'];
validateTOC(input, opts);
expect(opts.messages.errors).toStrictEqual([
{
message: "'0' must be object (at test)",
property: '0',
},
]);
expect(opts.messages.warnings).toBeUndefined();
});
2 changes: 1 addition & 1 deletion packages/mystmd/tests/multi-page-toc-tex/myst.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ project:
template: ../template/tex
output: _build/out-single.tex
toc:
- one.md
- file: one.md

0 comments on commit 6a1d956

Please sign in to comment.