This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
/
custom-blocks.spec.ts
91 lines (82 loc) · 2.34 KB
/
custom-blocks.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import vue, { VuePluginOptions } from '../../src'
import { pluginInline } from '../setup/plugins'
import { rollup } from 'rollup'
function pluginText() {
return {
name: 'text',
transform(source: string, id: string) {
if (/\.(md|txt)$/.test(id)) {
return `export default ${JSON.stringify(source.trim())}`
}
},
}
}
describe('customBlocks', () => {
async function setup(options?: Partial<VuePluginOptions>) {
return rollup({
input: '/entry.vue',
plugins: [
pluginInline(
'/entry.vue',
`
<template>
<div>Hello, world</div>
</template>
<custom>
// My Custom Block
</custom>
<docs>
// My Docs Block
</docs>
`
),
pluginText(),
vue({
...options,
defaultLang: {
docs: 'md',
custom: 'txt',
},
normalizer: 'vue-runtime-helpers/dist/normalize-component.mjs',
}),
],
})
.then(bundle => bundle.generate({ format: 'es' }))
.then(generated => generated.output[0])
}
it('default', async () => {
const { code } = await setup()
expect(code).not.toEqual(expect.stringContaining('My Custom Block'))
expect(code).not.toEqual(expect.stringContaining('My Docs Block'))
})
it('array of tags', async () => {
const { code } = await setup({
customBlocks: ['custom'],
})
expect(code).toEqual(expect.stringContaining('My Custom Block'))
expect(code).not.toEqual(expect.stringContaining('My Docs Block'))
})
it('negative array of tags', async () => {
const { code } = await setup({
customBlocks: ['*', '!custom'],
})
expect(code).not.toEqual(expect.stringContaining('My Custom Block'))
expect(code).toEqual(expect.stringContaining('My Docs Block'))
})
it('function', async () => {
const { code } = await setup({
customBlocks(tag) {
return tag === 'custom'
},
})
expect(code).toEqual(expect.stringContaining('My Custom Block'))
expect(code).not.toEqual(expect.stringContaining('My Docs Block'))
})
it('transform', async () => {
const { code } = await setup({
customBlocks: ['docs'],
})
expect(code).toEqual(expect.stringContaining('__custom_block_1__(__vue_component__)'))
expect(code).toMatchSnapshot()
})
})