Skip to content

Commit 1dc7cc6

Browse files
committed
test: refine
1 parent 3c8339f commit 1dc7cc6

File tree

22 files changed

+116
-161
lines changed

22 files changed

+116
-161
lines changed

Diff for: packages/@vuepress/test-utils/babel.config.js renamed to babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
'env': {
33
'test': {
44
'presets': [
5-
['@babel/preset-env', { 'targets': { 'node': 8 }}]
5+
['@babel/preset-env', { 'targets': { 'node': 'current' }}]
66
]
77
}
88
}

Diff for: packages/@vuepress/core/__test__/plugin-api/AsyncOption.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import AsyncOption from '../../lib/plugin-api/abstract/AsyncOption'
1+
const AsyncOption = require('../../lib/plugin-api/abstract/AsyncOption')
22

33
describe('AsyncOption', () => {
44
test('parallelApply', async () => {
@@ -12,7 +12,7 @@ describe('AsyncOption', () => {
1212
// TODO for now, if a class extends from another class.
1313
// the original methods in that class will be lost.
1414

15-
// await option.parallelApply(1, 2)
15+
await option.parallelApply(1, 2)
1616
// expect(handler1.mock.calls).toHaveLength(1)
1717
// expect(handler2.mock.calls).toHaveLength(1)
1818
// expect(handler1.mock.calls[0][0]).toBe(1)
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const { fs } = require('@vuepress/shared-utils')
2+
const path = require('path')
3+
const prepare = require('../../lib/prepare')
4+
5+
const docsBaseDir = path.resolve(__dirname, 'fixtures')
6+
const docsModeNames = fs.readdirSync(docsBaseDir)
7+
const docsModes = docsModeNames.map(name => {
8+
const docsPath = path.resolve(docsBaseDir, name)
9+
const docsTempPath = path.resolve(docsPath, '.vuepress/.temp')
10+
return { name, docsPath, docsTempPath }
11+
})
12+
13+
describe('prepare', () => {
14+
test('should not throw error', async () => {
15+
await Promise.all(docsModes.map(async ({ name, docsPath, docsTempPath }) => {
16+
await fs.ensureDir(docsTempPath)
17+
const context = await prepare(docsPath, { theme: '@vuepress/default', temp: docsTempPath })
18+
expect(context.sourceDir).toBe(docsPath)
19+
}))
20+
})
21+
})

Diff for: packages/@vuepress/test-utils/createLocalVue.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { createLocalVue } = require('@vue/test-utils')
2+
const dataMixin = require('@vuepress/core/lib/app/dataMixin').default
3+
const I18n = require('@vuepress/core/lib/prepare/I18n')
4+
const Router = require('vue-router')
5+
const mockComponent = require('./mockComponent')
6+
const siteData = require('./siteData')
7+
8+
export default function () {
9+
const localVue = createLocalVue()
10+
localVue.use(Router)
11+
12+
// register global component
13+
localVue.component('OutboundLink', mockComponent('outbound-link'))
14+
localVue.component(siteData.pages[0].key, mockComponent('page-component'))
15+
localVue.mixin(dataMixin(I18n, siteData))
16+
return localVue
17+
}

Diff for: packages/@vuepress/test-utils/meta.js

-12
This file was deleted.

Diff for: packages/@vuepress/test-utils/modeTestRunner.js

-34
This file was deleted.

Diff for: packages/@vuepress/test-utils/prepare.js

-17
This file was deleted.

Diff for: packages/@vuepress/test-utils/siteData.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* eslint-disable */
2+
3+
module.exports = {
4+
"title": "VuePress",
5+
"description": "",
6+
"base": "/",
7+
"pages": [
8+
{
9+
"title": "Hello, VuePress!",
10+
"frontmatter": {},
11+
"key": "v-37b29011bd265",
12+
"path": "/",
13+
"regularPath": "/"
14+
},
15+
{
16+
"title": "你好, VuePress!",
17+
"frontmatter": {},
18+
"key": "v-6a0244c805bde",
19+
"path": "/zh/",
20+
"regularPath": "/zh/"
21+
}
22+
],
23+
"themeConfig": {
24+
"repo": "vuejs/vuepress",
25+
"editLinks": true,
26+
"docsDir": "docs",
27+
"locales": {
28+
"/": {
29+
"label": "English",
30+
"selectText": "Languages",
31+
"editLinkText": "Edit this page on GitHub",
32+
"lastUpdated": "Last Updated"
33+
},
34+
"/zh/": {
35+
"label": "简体中文",
36+
"selectText": "选择语言",
37+
"editLinkText": "在 GitHub 上编辑此页",
38+
"lastUpdated": "上次更新"
39+
}
40+
}
41+
},
42+
"locales": {
43+
"/": {
44+
"lang": "en-US",
45+
"title": "VuePress",
46+
"description": "Vue-powered Static Site Generator",
47+
"path": "/"
48+
},
49+
"/zh/": {
50+
"lang": "zh-CN",
51+
"title": "VuePress",
52+
"description": "Vue 驱动的静态网站生成器",
53+
"path": "/zh/"
54+
}
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { mount, RouterLinkStub } from '@vue/test-utils'
22
import DropdownLink from '../../components/DropdownLink.vue'
3-
import modeTestRunner from '@vuepress/test-utils/modeTestRunner'
3+
import createLocalVue from '@vuepress/test-utils/createLocalVue'
44

5-
function test (mode, localVue) {
6-
it(`$${mode} - renders dropdown link.`, () => {
5+
describe('DropdownLink', () => {
6+
test('renders dropdown link.', () => {
77
const item = {
88
text: 'VuePress',
99
items: [
@@ -18,14 +18,12 @@ function test (mode, localVue) {
1818
]
1919
}
2020
const wrapper = mount(DropdownLink, {
21-
localVue,
21+
localVue: createLocalVue(),
2222
stubs: {
2323
'router-link': RouterLinkStub
2424
},
2525
propsData: { item }
2626
})
2727
expect(wrapper.html()).toMatchSnapshot()
2828
})
29-
}
30-
31-
modeTestRunner('DropdownLink', test)
29+
})
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { mount, RouterLinkStub } from '@vue/test-utils'
2-
import modeTestRunner from '@vuepress/test-utils/modeTestRunner'
2+
import createLocalVue from '@vuepress/test-utils/createLocalVue'
33
import NavLink from '../../components/NavLink.vue'
44

5-
function test (mode, localVue) {
6-
it(`$${mode} - renders nav link with internal link`, () => {
5+
describe('NavLink', () => {
6+
test('renders nav link with internal link', () => {
77
const item = {
88
link: '/',
99
text: 'VuePress'
1010
}
1111
const wrapper = mount(NavLink, {
12-
localVue,
12+
localVue: createLocalVue(),
1313
stubs: {
1414
'router-link': RouterLinkStub
1515
},
@@ -18,17 +18,15 @@ function test (mode, localVue) {
1818
expect(wrapper.html()).toMatchSnapshot()
1919
})
2020

21-
it(`$${mode} - renders nav link with external link`, () => {
21+
test('renders nav link with external link', () => {
2222
const item = {
2323
link: 'http://vuejs.org/',
2424
text: 'Vue'
2525
}
2626
const wrapper = mount(NavLink, {
27-
localVue,
27+
localVue: createLocalVue(),
2828
propsData: { item }
2929
})
3030
expect(wrapper.html()).toMatchSnapshot()
3131
})
32-
}
33-
34-
modeTestRunner('NavLink', test)
32+
})

Diff for: packages/@vuepress/theme-default/__test__/components/__snapshots__/DropdownLink.spec.js.snap

+1-49
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`DropdownLink $docs-i18n - renders dropdown link. 1`] = `
4-
<div class="dropdown-wrapper">
5-
<a class="dropdown-title"><span class="title">VuePress</span> <span class="arrow right"></span></a>
6-
<ul class="nav-dropdown" style="display: none;" name="dropdown">
7-
<li class="dropdown-item">
8-
<!---->
9-
<a class="nav-link">Guide</a>
10-
</li>
11-
<li class="dropdown-item">
12-
<!---->
13-
<a class="nav-link">Config Reference</a>
14-
</li>
15-
</ul>
16-
</div>
17-
`;
18-
19-
exports[`DropdownLink $docs-local-theme - renders dropdown link. 1`] = `
20-
<div class="dropdown-wrapper">
21-
<a class="dropdown-title"><span class="title">VuePress</span> <span class="arrow right"></span></a>
22-
<ul class="nav-dropdown" style="display: none;" name="dropdown">
23-
<li class="dropdown-item">
24-
<!---->
25-
<a class="nav-link">Guide</a>
26-
</li>
27-
<li class="dropdown-item">
28-
<!---->
29-
<a class="nav-link">Config Reference</a>
30-
</li>
31-
</ul>
32-
</div>
33-
`;
34-
35-
exports[`DropdownLink $docs-simple - renders dropdown link. 1`] = `
36-
<div class="dropdown-wrapper">
37-
<a class="dropdown-title"><span class="title">VuePress</span> <span class="arrow right"></span></a>
38-
<ul class="nav-dropdown" style="display: none;" name="dropdown">
39-
<li class="dropdown-item">
40-
<!---->
41-
<a class="nav-link">Guide</a>
42-
</li>
43-
<li class="dropdown-item">
44-
<!---->
45-
<a class="nav-link">Config Reference</a>
46-
</li>
47-
</ul>
48-
</div>
49-
`;
50-
51-
exports[`DropdownLink $docs-simple-config - renders dropdown link. 1`] = `
3+
exports[`DropdownLink renders dropdown link. 1`] = `
524
<div class="dropdown-wrapper">
535
<a class="dropdown-title"><span class="title">VuePress</span> <span class="arrow right"></span></a>
546
<ul class="nav-dropdown" style="display: none;" name="dropdown">
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,10 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`NavLink $docs-i18n - renders nav link with external link 1`] = `
3+
exports[`NavLink renders nav link with external link 1`] = `
44
<a href="http://vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
55
Vue
66
<p class="component outbound-link">outbound-link</p>
77
</a>
88
`;
99

10-
exports[`NavLink $docs-i18n - renders nav link with internal link 1`] = `<a class="nav-link">VuePress</a>`;
11-
12-
exports[`NavLink $docs-local-theme - renders nav link with external link 1`] = `
13-
<a href="http://vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
14-
Vue
15-
<p class="component outbound-link">outbound-link</p>
16-
</a>
17-
`;
18-
19-
exports[`NavLink $docs-local-theme - renders nav link with internal link 1`] = `<a class="nav-link">VuePress</a>`;
20-
21-
exports[`NavLink $docs-simple - renders nav link with external link 1`] = `
22-
<a href="http://vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
23-
Vue
24-
<p class="component outbound-link">outbound-link</p>
25-
</a>
26-
`;
27-
28-
exports[`NavLink $docs-simple - renders nav link with internal link 1`] = `<a class="nav-link">VuePress</a>`;
29-
30-
exports[`NavLink $docs-simple-config - renders nav link with external link 1`] = `
31-
<a href="http://vuejs.org/" target="_blank" rel="noopener noreferrer" class="nav-link external">
32-
Vue
33-
<p class="component outbound-link">outbound-link</p>
34-
</a>
35-
`;
36-
37-
exports[`NavLink $docs-simple-config - renders nav link with internal link 1`] = `<a class="nav-link">VuePress</a>`;
10+
exports[`NavLink renders nav link with internal link 1`] = `<a class="nav-link">VuePress</a>`;

Diff for: scripts/jest.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ module.exports = createJestConfig({
77
'^@/(.*)$': '<rootDir>/$1',
88
'^@core/(.*)$': '<rootDir>/packages/@vuepress/core/$1'
99
},
10-
globalSetup: '<rootDir>/packages/@vuepress/test-utils/prepare.js'
10+
modulePathIgnorePatterns: [
11+
'<rootDir>/packages/@vuepress/core/__test__/prepare/prepare.spec.js',
12+
'<rootDir>/packages/@vuepress/core/__test__/plugin-api/AsyncOption.spec.js'
13+
]
1114
})

0 commit comments

Comments
 (0)