|
| 1 | +import vue, { VuePluginOptions } from '../../src' |
| 2 | +import { pluginInline } from '../setup/plugins' |
| 3 | +import { rollup } from 'rollup' |
| 4 | + |
| 5 | +describe('customBlocks', () => { |
| 6 | + async function setup(options?: Partial<VuePluginOptions>) { |
| 7 | + return rollup({ |
| 8 | + input: '/entry.vue', |
| 9 | + plugins: [ |
| 10 | + pluginInline( |
| 11 | + '/entry.vue', |
| 12 | + ` |
| 13 | + <template> |
| 14 | + <div>Hello, world</div> |
| 15 | + </template> |
| 16 | + <custom> |
| 17 | + // My Custom Block |
| 18 | + </custom> |
| 19 | + <docs> |
| 20 | + // My Docs Block |
| 21 | + </docs> |
| 22 | + ` |
| 23 | + ), |
| 24 | + vue({ |
| 25 | + ...options, |
| 26 | + normalizer: 'vue-runtime-helpers/dist/normalize-component.mjs' |
| 27 | + }) |
| 28 | + ] |
| 29 | + }) |
| 30 | + .then(bundle => bundle.generate({ format: 'es' })) |
| 31 | + .then(generated => generated.output[0]) |
| 32 | + } |
| 33 | + |
| 34 | + it('default', async () => { |
| 35 | + const { code } = await setup() |
| 36 | + |
| 37 | + expect(code).not.toEqual(expect.stringContaining('My Custom Block')) |
| 38 | + expect(code).not.toEqual(expect.stringContaining('My Docs Block')) |
| 39 | + }) |
| 40 | + |
| 41 | + it('array of tags', async () => { |
| 42 | + const { code } = await setup({ |
| 43 | + customBlocks: ['custom'] |
| 44 | + }) |
| 45 | + |
| 46 | + expect(code).toEqual(expect.stringContaining('My Custom Block')) |
| 47 | + expect(code).not.toEqual(expect.stringContaining('My Docs Block')) |
| 48 | + }) |
| 49 | + it('negative array of tags', async () => { |
| 50 | + const { code } = await setup({ |
| 51 | + customBlocks: ['*', '!custom'] |
| 52 | + }) |
| 53 | + |
| 54 | + expect(code).not.toEqual(expect.stringContaining('My Custom Block')) |
| 55 | + expect(code).toEqual(expect.stringContaining('My Docs Block')) |
| 56 | + }) |
| 57 | + it('function', async () => { |
| 58 | + const { code } = await setup({ |
| 59 | + customBlocks(tag) { |
| 60 | + return tag === 'custom' |
| 61 | + } |
| 62 | + }) |
| 63 | + |
| 64 | + expect(code).toEqual(expect.stringContaining('My Custom Block')) |
| 65 | + expect(code).not.toEqual(expect.stringContaining('My Docs Block')) |
| 66 | + }) |
| 67 | +}) |
0 commit comments