Skip to content

Commit d58c494

Browse files
committed
Add test for Pug Loader
1 parent af4f59f commit d58c494

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

src/lib/Loader.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type Options = Pick<Vuedoc.Parser.ResolvedOptions, 'source'> & {
55
definitions: Vuedoc.Loader.Definition[];
66
};
77

8-
export class Loader implements Vuedoc.Loader.Interface {
8+
export abstract class Loader implements Vuedoc.Loader.Interface {
99
options: Options;
1010

1111
static extend(name: string, loader: any) {
@@ -32,12 +32,7 @@ export class Loader implements Vuedoc.Loader.Interface {
3232
this.options = options;
3333
}
3434

35-
/* istanbul ignore next */
36-
/* eslint-disable-next-line class-methods-use-this */
37-
// eslint-disable-next-line no-unused-vars
38-
async load(data: Vuedoc.Loader.TemplateData | Vuedoc.Loader.ScriptData) {
39-
throw new Error('Cannot call abstract Loader.load() method');
40-
}
35+
abstract load(data: Vuedoc.Loader.TemplateData | Vuedoc.Loader.ScriptData): Promise<void>;
4136

4237
emitTemplate(data: Vuedoc.Loader.TemplateData) {
4338
this.options.source.template = data;

src/lib/parser/AbstractParser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class AbstractParser<Source extends Vuedoc.Parser.Source, Root> {
5656

5757
emit(entry: Vuedoc.Entry.Type) {
5858
if (this.root) {
59-
this.root.emit(entry);
59+
(this.root as any).emit(entry);
6060
}
6161
}
6262

test/spec/MarkupTemplateParser.spec.js

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,51 @@
1-
import { ComponentTestCase } from '../lib/TestUtils.js';
21
import { describe } from 'vitest';
2+
import { ComponentTestCase } from '../lib/TestUtils.js';
3+
import { PugLoader } from '../../src/loaders/pug.ts';
4+
import { Loader } from '../../src/lib/Loader.ts';
35

46
describe('MarkupTemplateParser', () => {
7+
ComponentTestCase({
8+
name: 'Pug',
9+
options: {
10+
filecontent: `
11+
<template lang="pug">
12+
div
13+
label(:for='id')
14+
// Use this slot to set the label
15+
slot(name='label')
16+
.editor(contenteditable='true')
17+
// Use this slot to set the textarea value
18+
slot
19+
</template>
20+
`,
21+
loaders: [
22+
Loader.extend('pug', PugLoader),
23+
],
24+
},
25+
expected: {
26+
slots: [
27+
{
28+
kind: 'slot',
29+
name: 'label',
30+
visibility: 'public',
31+
category: undefined,
32+
description: 'Use this slot to set the label',
33+
keywords: [],
34+
props: [],
35+
},
36+
{
37+
kind: 'slot',
38+
name: 'default',
39+
visibility: 'public',
40+
category: undefined,
41+
description: 'Use this slot to set the textarea value',
42+
keywords: [],
43+
props: [],
44+
},
45+
],
46+
},
47+
});
48+
549
ComponentTestCase({
650
name: 'slots',
751
options: {

0 commit comments

Comments
 (0)