Skip to content

Commit de109e7

Browse files
committed
test: fixed
1 parent b0c8744 commit de109e7

31 files changed

+129
-180
lines changed

babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ module.exports = {
33
'test': {
44
'presets': [
55
['@babel/preset-env', { 'targets': { 'node': 'current' }}]
6+
],
7+
'plugins': [
8+
'@babel/plugin-syntax-dynamic-import'
69
]
710
}
811
}

packages/@vuepress/core/lib/client/dataMixin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* global VUEPRESS_TEMP_PATH */
22

3-
import Vue from 'vue'
3+
import GLobalVue from 'vue'
44

5-
export default function dataMixin (I18n, siteData) {
5+
export default function dataMixin (I18n, siteData, Vue = GLobalVue) {
66
prepare(siteData)
77
Vue.$vuepress.$set('siteData', siteData)
88

packages/@vuepress/core/lib/node/__tests__/plugin-api/PluginUtil.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ import { flattenPlugin } from '../../plugin-api/util'
22

33
describe('flattenPlugin', () => {
44
test('should hydrate plugin correctly', () => {
5-
const plugin = { name: 'a', shortcut: 'a', module: { enhanceAppFiles: 'file' }}
5+
const plugin = { name: 'a', shortcut: 'a', entry: { enhanceAppFiles: 'file' }}
66
const hydratedPlugin = flattenPlugin(plugin, {}, {})
77
expect(hydratedPlugin.name).toBe('a')
8-
expect(hydratedPlugin.shortcut).toBe('a')
8+
expect(hydratedPlugin.shortcut).toBe(null)
99
expect(hydratedPlugin.enabled).toBe(true)
1010
expect(hydratedPlugin.enhanceAppFiles).toBe('file')
1111
})
1212

1313
test('should set \'enabled\' to false when \'pluginOptions\' is set to false.', () => {
14-
const plugin = { name: 'a', shortcut: 'a', module: {}}
14+
const plugin = { name: 'a', shortcut: 'a', entry: {}}
1515
const hydratedPlugin = flattenPlugin(plugin, false, {})
1616
expect(hydratedPlugin.name).toBe('a')
17-
expect(hydratedPlugin.shortcut).toBe('a')
17+
expect(hydratedPlugin.shortcut).toBe(null)
1818
expect(hydratedPlugin.enabled).toBe(false)
1919
})
2020

2121
test('should flatten functional plugin correctly.', () => {
2222
const config = jest.fn(() => ({ enhanceAppFiles: 'file' }))
23-
const plugin = { name: 'a', shortcut: 'a', module: config }
23+
const plugin = { name: 'a', shortcut: 'a', entry: config }
2424
const pluginOptions = {}
2525
const pluginContext = {}
2626
const hydratedPlugin = flattenPlugin(plugin, pluginOptions, pluginContext)
2727
expect(hydratedPlugin.name).toBe('a')
28-
expect(hydratedPlugin.shortcut).toBe('a')
28+
expect(hydratedPlugin.shortcut).toBe(null)
2929
expect(hydratedPlugin.enabled).toBe(true)
3030
expect(hydratedPlugin.enhanceAppFiles).toBe('file')
3131
expect(config.mock.calls).toHaveLength(1)
@@ -35,7 +35,7 @@ describe('flattenPlugin', () => {
3535

3636
test('should flatten functional plugin correctly - options defaults to \'{}\'.', () => {
3737
const config = jest.fn(() => ({ enhanceAppFiles: 'file' }))
38-
const plugin = { name: 'a', shortcut: 'a', module: config }
38+
const plugin = { name: 'a', shortcut: 'a', entry: config }
3939
const pluginOptions = undefined
4040
const pluginContext = {}
4141
flattenPlugin(plugin, pluginOptions, pluginContext)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { fs, path } = require('@vuepress/shared-utils')
2-
const prepare = require('../../lib/prepare')
2+
const App = require('../../App')
33

44
const docsBaseDir = path.resolve(__dirname, 'fixtures')
55
const docsModeNames = fs.readdirSync(docsBaseDir)
@@ -9,12 +9,16 @@ const docsModes = docsModeNames.map(name => {
99
return { name, docsPath, docsTempPath }
1010
})
1111

12-
describe('prepare', () => {
12+
describe('App', () => {
1313
test('should not throw error', async () => {
1414
await Promise.all(docsModes.map(async ({ name, docsPath, docsTempPath }) => {
1515
await fs.ensureDir(docsTempPath)
16-
const context = await prepare(docsPath, { theme: '@vuepress/default', temp: docsTempPath })
17-
expect(context.sourceDir).toBe(docsPath)
16+
const app = new App({
17+
sourceDir: docsPath,
18+
theme: '@vuepress/default',
19+
emp: docsTempPath
20+
})
21+
expect(app.sourceDir).toBe(docsPath)
1822
}))
1923
})
2024
})

packages/@vuepress/core/lib/node/__tests__/prepare/Page.spec.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
const Page = require('../../lib/prepare/Page')
1+
const Page = require('../../Page')
2+
const App = require('../../App')
3+
24
const {
3-
getComputed,
45
getMarkdown,
56
getDocument,
67
readFile
78
} = require('./util')
89

910
describe('Page', () => {
11+
let app
12+
let computed
13+
14+
beforeAll(async () => {
15+
app = new App()
16+
await app.process()
17+
computed = new app.ClientComputedMixinConstructor()
18+
})
19+
1020
test('pure route', async () => {
11-
const page = new Page({ path: '/' })
21+
const page = new Page({ path: '/' }, app)
1222

1323
expect(page.path).toBe('/')
1424
expect(page.regularPath).toBe('/')
1525

16-
const computed = getComputed()
1726
await page.process({ computed })
1827

1928
expect(page.path).toBe('/')
@@ -22,7 +31,7 @@ describe('Page', () => {
2231

2332
test('pure route - encodeURI', async () => {
2433
const path = '/尤/'
25-
const page = new Page({ path })
34+
const page = new Page({ path }, app)
2635

2736
expect(page.path).toBe(encodeURI(path))
2837
expect(page.regularPath).toBe(encodeURI(path))
@@ -33,7 +42,7 @@ describe('Page', () => {
3342
const page = new Page({
3443
path: '/',
3544
frontmatter
36-
})
45+
}, app)
3746
expect(page.frontmatter).toBe(frontmatter)
3847
})
3948

@@ -42,15 +51,16 @@ describe('Page', () => {
4251
const page = new Page({
4352
path: '/',
4453
frontmatter
45-
})
54+
}, app)
4655

4756
expect(page.frontmatter.title).toBe('alpha')
4857

49-
const computed = getComputed()
5058
const enhancers = [
5159
{
5260
name: 'plugin-a',
53-
value: page => { page.frontmatter.title = 'beta' }
61+
value: page => {
62+
page.frontmatter.title = 'beta'
63+
}
5464
}
5565
]
5666
await page.process({ computed, enhancers })
@@ -60,14 +70,13 @@ describe('Page', () => {
6070

6171
test('markdown page - pointing to a markdown file', async () => {
6272
const { relative, filePath } = getDocument('README.md')
63-
const page = new Page({ filePath, relative })
73+
const page = new Page({ filePath, relative }, app)
6474

6575
expect(page._filePath).toBe(filePath)
6676
expect(page.regularPath).toBe('/')
6777
expect(page.path).toBe('/')
6878
expect(page.frontmatter).toEqual({})
6979

70-
const computed = getComputed()
7180
const markdown = getMarkdown()
7281
await page.process({ computed, markdown })
7382

@@ -79,14 +88,13 @@ describe('Page', () => {
7988

8089
test('markdown page - pointing to a markdown file with frontmatter', async () => {
8190
const { relative, filePath } = getDocument('alpha.md')
82-
const page = new Page({ filePath, relative })
91+
const page = new Page({ filePath, relative }, app)
8392

8493
expect(page._filePath).toBe(filePath)
8594
expect(page.regularPath).toBe('/alpha.html')
8695
expect(page.path).toBe('/alpha.html')
8796
expect(page.frontmatter).toEqual({})
8897

89-
const computed = getComputed()
9098
const markdown = getMarkdown()
9199
await page.process({ computed, markdown })
92100

packages/@vuepress/core/lib/node/__tests__/prepare/util.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
const { fs, path } = require('@vuepress/shared-utils')
2-
const AppContext = require('../../lib/prepare/AppContext')
32
const createMarkdown = require('../../../../../markdown/index')
43

5-
function getAppContext () {
6-
return new AppContext('.')
7-
}
8-
9-
function getComputed () {
10-
const context = getAppContext()
11-
return new context.ClientComputedMixinConstructor()
12-
}
13-
144
const docsBaseDir = path.resolve(__dirname, 'fixtures/docs')
155

166
function getDocument (relative) {
@@ -25,8 +15,6 @@ const getMarkdown = createMarkdown
2515
const readFile = async filePath => await fs.readFile(filePath, 'utf-8')
2616

2717
module.exports = {
28-
getAppContext,
29-
getComputed,
3018
getMarkdown,
3119
getDocument,
3220
readFile

packages/@vuepress/core/lib/node/__tests__/theme-api/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
jest.mock('vuepress-theme-parent')
22
jest.mock('vuepress-theme-child')
33

4-
import ThemeAPI from '../../lib/theme-api'
4+
import ThemeAPI from '../../theme-api'
55
import { resolve } from 'path'
66

77
const theme = {

packages/@vuepress/markdown/__tests__/__snapshots__/containers.spec.js.snap

Lines changed: 0 additions & 35 deletions
This file was deleted.

packages/@vuepress/markdown/__tests__/__snapshots__/highlightLines.spec.js.snap

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
exports[`highlightLines highlight multiple lines 1`] = `
44
<div class="highlight-lines">
55
<div class="highlighted">&nbsp;</div>
6+
<div class="highlighted">&nbsp;</div><br>
67
<div class="highlighted">&nbsp;</div>
7-
<br>
8-
<div class="highlighted">&nbsp;</div>
9-
<div class="highlighted">&nbsp;</div>
10-
<br>
11-
<br>
12-
</div>const app = new Vue({ render, router }) app.$mount('#app')
8+
<div class="highlighted">&nbsp;</div><br><br>
9+
</div>const app = new Vue({
10+
render,
11+
router
12+
})
13+
14+
app.$mount('#app')
1315
`;
1416
1517
exports[`highlightLines highlight single line 1`] = `
1618
<div class="highlight-lines">
17-
<div class="highlighted">&nbsp;</div>
18-
<br>
19+
<div class="highlighted">&nbsp;</div><br>
1920
</div>new Vue()
2021
`;

packages/@vuepress/markdown/__tests__/__snapshots__/hoist.spec.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ exports[`hoist Should miss script and style when using hoist 1`] = `
1818

1919
exports[`hoist Should miss script and style when using hoist 2`] = `
2020
Object {
21+
"__data_block": Object {},
2122
"hoistedTags": Array [
2223
<script src="vue.js"></script>,
2324
<style>

packages/@vuepress/markdown/__tests__/__snapshots__/lineNumers.spec.js.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ exports[`lineNumbers should lineNumbers work with highlightLines 1`] = `
55
<div class="language-js line-numbers-mode">
66
<!--afterbegin-->
77
<div class="highlight-lines">
8-
<div class="highlighted">&nbsp;</div>
9-
<br>
8+
<div class="highlighted">&nbsp;</div><br>
109
</div>new Vue()
1110
<div class="line-numbers-wrapper"></div>
1211
<!--beforeend-->
Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`link should render external links correctly 1`] = `
4-
<p>
5-
<a href="https://vuejs.org/" target="_blank" rel="noopener noreferrer">vue
6-
<OutboundLink/>
7-
</a>
8-
</p>
4+
<p><a href="https://vuejs.org/" target="_blank" rel="noopener noreferrer">vue
5+
<OutboundLink /></a></p>
96
`;
107

118
exports[`link should render external links correctly 2`] = `
12-
<p>
13-
<a href="http://vuejs.org/" target="_blank" rel="noopener noreferrer">vue
14-
<OutboundLink/>
15-
</a>
16-
</p>
9+
<p><a href="http://vuejs.org/" target="_blank" rel="noopener noreferrer">vue
10+
<OutboundLink /></a></p>
1711
`;
1812

1913
exports[`link should render external links correctly 3`] = `
20-
<p>
21-
<a href="https://google.com" target="_blank" rel="noopener noreferrer">some <strong>link</strong> with <code>code</code>
22-
<OutboundLink/>
23-
</a>
24-
</p>
14+
<p><a href="https://google.com" target="_blank" rel="noopener noreferrer">some <strong>link</strong> with <code>code</code>
15+
<OutboundLink /></a></p>
2516
`;

packages/@vuepress/markdown/__tests__/__snapshots__/snippet.spec.js.snap

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@ exports[`snippet import snippet 1`] = `
1010
exports[`snippet import snippet with highlight multiple lines 1`] = `
1111
<div class="highlight-lines">
1212
<div class="highlighted">&nbsp;</div>
13-
<div class="highlighted">&nbsp;</div>
14-
<div class="highlighted">&nbsp;</div>
15-
<br>
16-
</div>export default function () { // .. }
13+
</div>
1714
`;
1815

1916
exports[`snippet import snippet with highlight single line 1`] = `
2017
<div class="highlight-lines">
2118
<div class="highlighted">&nbsp;</div>
22-
<br>
23-
<div class="highlighted">&nbsp;</div>
24-
<br>
25-
</div>export default function () { // .. }
19+
</div>
2620
`;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<<< @/packages/@vuepress/core/__test__/markdown/fragments/snippet.js{1-3}
1+
<<< @/packages/@vuepress/markdown/__tests__/fragments/snippet.js{1-3}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<<< @/packages/@vuepress/core/__test__/markdown/fragments/snippet.js{1,3}
1+
<<< @/packages/@vuepress/markdown/__tests__/fragments/snippet.js{1,3}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<<< @/packages/@vuepress/core/__test__/markdown/fragments/snippet.js
1+
<<< @/packages/@vuepress/markdown/__tests__/fragments/snippet.js

packages/@vuepress/markdown/__tests__/highlight.spec.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { Md, getFragment } from './util'
1+
import { getFragment } from '@vuepress/test-utils'
2+
import { Md } from './util'
23
import highlight from '../lib/highlight.js'
34

45
const md = Md()
56
const mdH = Md().set({ highlight })
67

78
describe('highlight', () => {
8-
test('should highlight code', async () => {
9-
const input = await getFragment('code')
9+
test('should highlight code', () => {
10+
const input = getFragment(__dirname, 'code.md')
1011
const output1 = md.render(input)
1112
const output2 = mdH.render(input)
1213
expect(output1 === output2).toBe(false)

0 commit comments

Comments
 (0)