Skip to content

Commit

Permalink
test(sidebar): add sidebar test and add async foreach test
Browse files Browse the repository at this point in the history
fix coverage
  • Loading branch information
ph1p committed Feb 18, 2019
1 parent 56473a8 commit 5d10de1
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
# for Jetbrains IDEA ides
.idea
coverage
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
"bail": true,
"verbose": true,
"collectCoverageFrom": [
"src/**/*.{js,jsx}",
"**/*.{js,jsx}",
"!**/node_modules/**",
"!**/coverage/**",
"!**/example/**",
"!**/vendor/**"
],
"coverageDirectory": "./coverage"
Expand Down
8 changes: 8 additions & 0 deletions tests/index.test.js → tests/comment-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ describe('commentParser', () => {
expect(attributes.page).toBe(25);
});
});

describe('commentParser fail', () => {
const { fontmatter } = commentParser();

test('fontmatter should be null', () => {
expect(fontmatter).toBe(null);
});
});
49 changes: 49 additions & 0 deletions tests/sidebar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';

const vueSidebar = require('../helpers/vue-sidebar');

describe('test sidebar', () => {
test('vueSidebar should return valid vue config', () => {
const codeFolder = 'test_folder';
const title = 'test_folder';
const fileTree = [
{ name: 'class', path: '/class', fullPath: './documentation/test_folder/class' },
{
name: 'lib',
children: [
{ name: 'test1', path: '/test1', fullPath: './documentation/test_folder/test1' },
{
name: 'test2',
path: '/test2',
fullPath: './documentation/test_folder/test2',
children: [
{ name: 'test3', path: '/test3', fullPath: './documentation/test_folder/test2/test3' },
{ name: 'test4', path: '/test4', fullPath: './documentation/test_folder/test2/test4' }
]
}
]
},
{ name: 'test', path: '/test', fullPath: './documentation/test_folder/test' },
{ name: 'tests', children: [] }
];

const sidebar = vueSidebar({ fileTree, codeFolder, title });

const result = {
[`/${codeFolder}/`]: [
{ title, collapsable: false, children: [['', '::vuepress-jsdoc-title::'], 'class', 'test'] },
{
title: 'lib',
collapsable: false,
children: [
'./documentation/test_folder/test1',
'./documentation/test_folder/test2/test3',
'./documentation/test_folder/test2/test4'
]
}
]
};

expect(sidebar).toEqual(result);
});
});
14 changes: 13 additions & 1 deletion tests/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

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

describe('test utils', () => {
test('checkExtension should return true', () => {
Expand All @@ -16,4 +16,16 @@ describe('test utils', () => {
expect(getFilename(undefined)).toBe('');
expect(getFilename()).toBe('');
});
test('asyncForEach should run array async', async () => {
const promise1 = Promise.resolve(1);
const promise2 = Promise.resolve(2);

let results = [];

await asyncForEach([promise1, promise2], async result => {
results.push(await result);
});

expect(results).toEqual([1, 2]);
});
});

0 comments on commit 5d10de1

Please sign in to comment.