Skip to content

Commit 5d10de1

Browse files
committed
test(sidebar): add sidebar test and add async foreach test
fix coverage
1 parent 56473a8 commit 5d10de1

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
# for Jetbrains IDEA ides
33
.idea
4+
coverage

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@
5050
"bail": true,
5151
"verbose": true,
5252
"collectCoverageFrom": [
53-
"src/**/*.{js,jsx}",
53+
"**/*.{js,jsx}",
5454
"!**/node_modules/**",
5555
"!**/coverage/**",
56+
"!**/example/**",
5657
"!**/vendor/**"
5758
],
5859
"coverageDirectory": "./coverage"

tests/index.test.js renamed to tests/comment-parser.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,11 @@ describe('commentParser', () => {
2424
expect(attributes.page).toBe(25);
2525
});
2626
});
27+
28+
describe('commentParser fail', () => {
29+
const { fontmatter } = commentParser();
30+
31+
test('fontmatter should be null', () => {
32+
expect(fontmatter).toBe(null);
33+
});
34+
});

tests/sidebar.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
const vueSidebar = require('../helpers/vue-sidebar');
4+
5+
describe('test sidebar', () => {
6+
test('vueSidebar should return valid vue config', () => {
7+
const codeFolder = 'test_folder';
8+
const title = 'test_folder';
9+
const fileTree = [
10+
{ name: 'class', path: '/class', fullPath: './documentation/test_folder/class' },
11+
{
12+
name: 'lib',
13+
children: [
14+
{ name: 'test1', path: '/test1', fullPath: './documentation/test_folder/test1' },
15+
{
16+
name: 'test2',
17+
path: '/test2',
18+
fullPath: './documentation/test_folder/test2',
19+
children: [
20+
{ name: 'test3', path: '/test3', fullPath: './documentation/test_folder/test2/test3' },
21+
{ name: 'test4', path: '/test4', fullPath: './documentation/test_folder/test2/test4' }
22+
]
23+
}
24+
]
25+
},
26+
{ name: 'test', path: '/test', fullPath: './documentation/test_folder/test' },
27+
{ name: 'tests', children: [] }
28+
];
29+
30+
const sidebar = vueSidebar({ fileTree, codeFolder, title });
31+
32+
const result = {
33+
[`/${codeFolder}/`]: [
34+
{ title, collapsable: false, children: [['', '::vuepress-jsdoc-title::'], 'class', 'test'] },
35+
{
36+
title: 'lib',
37+
collapsable: false,
38+
children: [
39+
'./documentation/test_folder/test1',
40+
'./documentation/test_folder/test2/test3',
41+
'./documentation/test_folder/test2/test4'
42+
]
43+
}
44+
]
45+
};
46+
47+
expect(sidebar).toEqual(result);
48+
});
49+
});

tests/utils.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { checkExtension, getFilename } = require('../helpers/utils');
3+
const { checkExtension, getFilename, asyncForEach } = require('../helpers/utils');
44

55
describe('test utils', () => {
66
test('checkExtension should return true', () => {
@@ -16,4 +16,16 @@ describe('test utils', () => {
1616
expect(getFilename(undefined)).toBe('');
1717
expect(getFilename()).toBe('');
1818
});
19+
test('asyncForEach should run array async', async () => {
20+
const promise1 = Promise.resolve(1);
21+
const promise2 = Promise.resolve(2);
22+
23+
let results = [];
24+
25+
await asyncForEach([promise1, promise2], async result => {
26+
results.push(await result);
27+
});
28+
29+
expect(results).toEqual([1, 2]);
30+
});
1931
});

0 commit comments

Comments
 (0)