mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-20 17:43:24 +00:00
Fix and test Book.getDefaultExt() (#1674)
This commit is contained in:
committed by
Samy Pessé
parent
af80cbcd7c
commit
0342a11da0
@@ -0,0 +1,65 @@
|
||||
const Book = require('../book');
|
||||
const File = require('../file');
|
||||
const Readme = require('../readme');
|
||||
const Summary = require('../summary');
|
||||
const Glossary = require('../glossary');
|
||||
|
||||
function createMockBook(def) {
|
||||
return new Book({
|
||||
readme: new Readme({
|
||||
file: new File({ path: def.readme })
|
||||
}),
|
||||
|
||||
summary: new Summary({
|
||||
file: new File({ path: def.summary })
|
||||
}),
|
||||
|
||||
glossary: new Glossary({
|
||||
file: new File({ path: def.glossary })
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
describe('Book', () => {
|
||||
describe('getDefaultExt', () => {
|
||||
it('must infer from README', () => {
|
||||
const book = createMockBook({
|
||||
readme: 'README.adoc',
|
||||
summary: 'SUMMARY.md',
|
||||
glossary: 'GLOSSARY.md'
|
||||
});
|
||||
|
||||
expect(book.getDefaultExt()).toBe('.adoc');
|
||||
});
|
||||
|
||||
it('must infer from SUMMARY', () => {
|
||||
const book = createMockBook({
|
||||
readme: '',
|
||||
summary: 'SUMMARY.adoc',
|
||||
glossary: 'GLOSSARY.md'
|
||||
});
|
||||
|
||||
expect(book.getDefaultExt()).toBe('.adoc');
|
||||
});
|
||||
|
||||
it('must infer from GLOSSARY', () => {
|
||||
const book = createMockBook({
|
||||
readme: '',
|
||||
summary: '',
|
||||
glossary: 'GLOSSARY.adoc'
|
||||
});
|
||||
|
||||
expect(book.getDefaultExt()).toBe('.adoc');
|
||||
});
|
||||
|
||||
it('must default to .md', () => {
|
||||
const book = createMockBook({
|
||||
readme: '',
|
||||
summary: '',
|
||||
glossary: ''
|
||||
});
|
||||
|
||||
expect(book.getDefaultExt()).toBe('.md');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -259,7 +259,7 @@ class Book extends Record(DEFAULTS) {
|
||||
const exts = clues.map((clue) => {
|
||||
const file = clue.getFile();
|
||||
if (file.exists()) {
|
||||
return file.getParser().getExtensions().first();
|
||||
return file.getParser().FILE_EXTENSIONS[0];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user