From 5d10de1e9ccd9c9eafcc9e2c8e72565b8f0718bb Mon Sep 17 00:00:00 2001 From: ph1p Date: Mon, 18 Feb 2019 18:55:34 +0100 Subject: [PATCH] test(sidebar): add sidebar test and add async foreach test fix coverage --- .gitignore | 1 + package.json | 3 +- .../{index.test.js => comment-parser.test.js} | 8 +++ tests/sidebar.test.js | 49 +++++++++++++++++++ tests/utils.test.js | 14 +++++- 5 files changed, 73 insertions(+), 2 deletions(-) rename tests/{index.test.js => comment-parser.test.js} (76%) create mode 100644 tests/sidebar.test.js diff --git a/.gitignore b/.gitignore index adc03b9..e53695d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules # for Jetbrains IDEA ides .idea +coverage \ No newline at end of file diff --git a/package.json b/package.json index 8955369..1f0e8e1 100644 --- a/package.json +++ b/package.json @@ -50,9 +50,10 @@ "bail": true, "verbose": true, "collectCoverageFrom": [ - "src/**/*.{js,jsx}", + "**/*.{js,jsx}", "!**/node_modules/**", "!**/coverage/**", + "!**/example/**", "!**/vendor/**" ], "coverageDirectory": "./coverage" diff --git a/tests/index.test.js b/tests/comment-parser.test.js similarity index 76% rename from tests/index.test.js rename to tests/comment-parser.test.js index 9ff4885..f84eacb 100644 --- a/tests/index.test.js +++ b/tests/comment-parser.test.js @@ -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); + }); +}); diff --git a/tests/sidebar.test.js b/tests/sidebar.test.js new file mode 100644 index 0000000..19c9d04 --- /dev/null +++ b/tests/sidebar.test.js @@ -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); + }); +}); diff --git a/tests/utils.test.js b/tests/utils.test.js index ed187c3..44c06aa 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -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', () => { @@ -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]); + }); });