forked from ryanlelek/Raneto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.test.js
More file actions
60 lines (55 loc) · 1.87 KB
/
functions.test.js
File metadata and controls
60 lines (55 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Modules
import fs from 'node:fs';
import path from 'node:path';
import moment from 'moment';
import build_nested_pages from '../app/functions/build_nested_pages.js';
import content_processors from '../app/functions/content_processors.js';
import contents_handler from '../app/core/contents.js';
import utils from '../app/core/utils.js';
const config = {
base_url: '',
image_url: '/images',
excerpt_length: 400,
page_sort_meta: 'sort',
category_sort: true,
show_on_home_default: true,
searchExtraLanguages: ['ru'],
debug: false,
// TODO: Fix extra trailing /
content_dir: path.join('test', 'content') + path.sep,
datetime_format: 'Do MMM YYYY',
};
describe('#get_last_modified()', () => {
it('returns last modified from page meta', async () => {
const file_path = path.join('test', 'content', 'page-with-bom-yaml.md');
const content = fs.readFileSync(file_path, 'utf8');
const modified = await utils.getLastModified(
config,
content_processors.processMeta(content),
file_path,
);
expect(modified).toEqual('14th Sep 2016');
});
it('returns last modified from fs', async () => {
const file_path = path.join('test', 'content', 'example-page.md');
const content = fs.readFileSync(file_path, 'utf8');
const modified = await utils.getLastModified(
config,
content_processors.processMeta(content),
file_path,
);
const fstime = moment(fs.lstatSync(file_path).mtime).format(
config.datetime_format,
);
expect(modified).toEqual(fstime);
});
});
describe('#build_nested_pages()', () => {
it('builds tree of pages', async () => {
const pages = await contents_handler(null, config);
const result = build_nested_pages(pages);
expect(result.length).toEqual(2);
expect(result[1].files.length).toEqual(3);
expect(result[1].files[0].files[0].title).toEqual('Sub2 Page');
});
});