test: add metadata test

This commit is contained in:
endiliey 2018-09-08 00:41:17 +08:00
parent 68518002d7
commit 59fa427dbd
4 changed files with 138 additions and 183 deletions

View file

@ -1,66 +0,0 @@
---
id: bar
title: Bar
---
# Remarkable
> Experience real-time editing with Remarkable!
Click the `clear` link to start with a clean slate, or get the `permalink` to share or save your results.
***
# h1 Heading
## h2 Heading
### h3 Heading
#### h4 Heading
##### h5 Heading
###### h6 Heading
## Horizontal Rules
___
***
***
## Typographic replacements
Enable typographer option to see result.
(c) (C) (r) (R) (tm) (TM) (p) (P) +-
test.. test... test..... test?..... test!....
!!!!!! ???? ,,
Remarkable -- awesome
"Smartypants, double quotes"
'Smartypants, single quotes'
## Emphasis
**This is bold text**
__This is bold text__
*This is italic text*
_This is italic text_
~~Deleted text~~
Superscript: 19^th^
Subscript: H~2~O
++Inserted text++
==Marked text==

View file

@ -1,77 +0,0 @@
---
id: baz
title: baz
---
## Images
![Minion](/img/minion.png)
![Stormtroopocat](/img/stormtroopocat.jpg)
Like links, Images also have a footnote style syntax
![Alt text][id]
With a reference later in the document defining the URL location:
[id]: https://octodex.github.com/images/dojocat.jpg "The Dojocat"
## Links
[link text](http://dev.nodeca.com)
[link with title](http://nodeca.github.io/pica/demo/ "title text!")
Autoconverted link https://github.com/nodeca/pica (enable linkify to see)
## Footnotes
Footnote 1 link[^first].
Footnote 2 link[^second].
Inline footnote^[Text of inline footnote] definition.
Duplicated footnote reference[^second].
[^first]: Footnote **can have markup**
and multiple paragraphs.
[^second]: Footnote text.
## Definition lists
Term 1
: Definition 1
with lazy continuation.
Term 2 with *inline markup*
: Definition 2
{ some code, part of Definition 2 }
Third paragraph of definition 2.
_Compact style:_
Term 1
~ Definition 1
Term 2
~ Definition 2a
~ Definition 2b
## Abbreviations
This is HTML abbreviation example.
It converts "HTML", but keep intact partial entries like "xxxHTMLyyy" and so on.
*[HTML]: Hyper Text Markup Language

View file

@ -1,40 +0,0 @@
---
id: hello
title: Hello, World !
---
Hi, Endilie here :)
## Blockquotes
> Blockquotes can also be nested...
>> ...by using additional greater-than signs right next to each other...
> > > ...or with spaces between arrows.
## Lists
Unordered
+ Create a list by starting a line with `+`, `-`, or `*`
+ Sub-lists are made by indenting 2 spaces:
- Marker character change forces new list start:
* Ac tristique libero volutpat at
+ Facilisis in pretium nisl aliquet
- Nulla volutpat aliquam velit
+ Very easy!
Ordered
1. Lorem ipsum dolor sit amet
2. Consectetur adipiscing elit
3. Integer molestie lorem at massa
1. You can use sequential numbers...
1. ...or keep all the numbers as `1.`
Start numbering with offset:
57. foo
1. bar

View file

@ -0,0 +1,138 @@
import path from 'path';
import processMetadata from '@lib/load/docs/metadata';
import loadSetup from '../../loadSetup';
describe('processMetadata', () => {
test('normal docs', async () => {
const props = await loadSetup('simple');
const {docsDir, env} = props;
const sourceA = path.join('foo', 'bar.md');
const sourceB = path.join('hello.md');
const dataA = await processMetadata(sourceA, docsDir, env, {});
const dataB = await processMetadata(sourceB, docsDir, env, {});
expect(dataA).toEqual({
id: 'foo/bar',
language: undefined,
localized_id: 'foo/bar',
permalink: 'docs/foo/bar',
source: 'foo/bar.md',
title: 'Bar',
version: undefined
});
expect(dataB).toEqual({
id: 'hello',
language: undefined,
localized_id: 'hello',
permalink: 'docs/hello',
source: 'hello.md',
title: 'Hello, World !',
version: undefined
});
});
test('versioned docs (without translation)', async () => {
const props = await loadSetup('versioned');
const {siteDir, docsDir, env} = props;
const refDir = path.join(siteDir, 'versioned_docs');
const sourceA = path.join('version-1.0.0', 'foo', 'bar.md');
const sourceB = path.join('version-1.0.0', 'hello.md');
const dataA = await processMetadata(sourceA, refDir, env, {});
const dataB = await processMetadata(sourceB, refDir, env, {});
expect(dataA).toEqual({
id: 'version-1.0.0-foo/bar',
language: undefined,
localized_id: 'version-1.0.0-foo/bar',
permalink: 'docs/1.0.0/foo/bar',
source: 'version-1.0.0/foo/bar.md',
title: 'Bar',
version: '1.0.0'
});
expect(dataB).toEqual({
id: 'version-1.0.0-hello',
language: undefined,
localized_id: 'version-1.0.0-hello',
permalink: 'docs/1.0.0/hello',
source: 'version-1.0.0/hello.md',
title: 'Hello, World !',
version: '1.0.0'
});
});
test('translated versioned docs', async () => {
const props = await loadSetup('transversioned');
const {siteDir, docsDir, env} = props;
const refDir = path.join(siteDir, 'translated_docs');
const sourceA = path.join('ko', 'version-1.0.0', 'foo', 'bar.md');
const sourceB = path.join('ko', 'version-1.0.0', 'hello.md');
const sourceC = path.join('ko', 'version-1.0.1', 'foo', 'bar.md');
const sourceD = path.join('ko', 'version-1.0.1', 'hello.md');
const dataA = await processMetadata(sourceA, refDir, env, {});
const dataB = await processMetadata(sourceB, refDir, env, {});
const dataC = await processMetadata(sourceC, refDir, env, {});
const dataD = await processMetadata(sourceD, refDir, env, {});
expect(dataA).toEqual({
id: 'ko-version-1.0.0-foo/bar',
language: 'ko',
localized_id: 'ko-version-1.0.0-foo/bar',
permalink: 'docs/ko/1.0.0/foo/bar',
source: 'ko/version-1.0.0/foo/bar.md',
title: 'Bar',
version: '1.0.0'
});
expect(dataB).toEqual({
id: 'ko-version-1.0.0-hello',
language: 'ko',
localized_id: 'ko-version-1.0.0-hello',
permalink: 'docs/ko/1.0.0/hello',
source: 'ko/version-1.0.0/hello.md',
title: 'Hello, World !',
version: '1.0.0'
});
expect(dataC).toEqual({
id: 'ko-version-1.0.1-foo/bar',
language: 'ko',
localized_id: 'ko-version-1.0.1-foo/bar',
permalink: 'docs/ko/foo/bar',
source: 'ko/version-1.0.1/foo/bar.md',
title: 'Bar',
version: '1.0.1'
});
expect(dataD).toEqual({
id: 'ko-version-1.0.1-hello',
language: 'ko',
localized_id: 'ko-version-1.0.1-hello',
permalink: 'docs/ko/hello',
source: 'ko/version-1.0.1/hello.md',
title: 'Hello, World !',
version: '1.0.1'
});
});
test('translated docs only', async () => {
const props = await loadSetup('translated');
const {siteDir, docsDir, env} = props;
const refDir = path.join(siteDir, 'translated_docs');
const sourceA = path.join('ko', 'foo', 'bar.md');
const sourceB = path.join('ko', 'hello.md');
const dataA = await processMetadata(sourceA, refDir, env, {});
const dataB = await processMetadata(sourceB, refDir, env, {});
expect(dataA).toEqual({
id: 'ko-foo/bar',
language: 'ko',
localized_id: 'ko-foo/bar',
permalink: 'docs/ko/foo/bar',
source: 'ko/foo/bar.md',
title: 'Bar',
version: undefined
});
expect(dataB).toEqual({
id: 'ko-hello',
language: 'ko',
localized_id: 'ko-hello',
permalink: 'docs/ko/hello',
source: 'ko/hello.md',
title: 'Hello, World !',
version: undefined
});
});
});