import { createApp } from 'vue' import { renderToString } from '../src/renderToString' describe('ssr: compiler options', () => { test('config.isCustomElement (deprecated)', async () => { const app = createApp({ template: `
`, }) app.config.isCustomElement = tag => tag.startsWith('x-') expect(await renderToString(app)).toBe(`
`) }) test('config.compilerOptions.isCustomElement', async () => { const app = createApp({ template: `
`, }) app.config.compilerOptions.isCustomElement = tag => tag.startsWith('x-') expect(await renderToString(app)).toBe(`
`) }) test('component.compilerOptions.isCustomElement', async () => { const app = createApp({ template: `
`, compilerOptions: { isCustomElement: (tag: string) => tag.startsWith('x-'), }, components: { YChild: { template: `
`, }, }, }) app.config.compilerOptions.isCustomElement = tag => tag.startsWith('y-') expect(await renderToString(app)).toBe( `
`, ) }) test('component.delimiters (deprecated)', async () => { const app = createApp({ template: `
[[ 1 + 1 ]]
`, delimiters: ['[[', ']]'], }) expect(await renderToString(app)).toBe(`
2
`) }) test('config.compilerOptions.delimiters', async () => { const app = createApp({ template: `
[( 1 + 1 )]
`, }) app.config.compilerOptions.delimiters = ['[(', ')]'] expect(await renderToString(app)).toBe(`
2
`) }) test('component.compilerOptions.delimiters', async () => { const app = createApp({ template: `
[[ 1 + 1 ]]
`, compilerOptions: { delimiters: ['[[', ']]'], }, components: { ChildComponent: { template: `
(( 2 + 2 ))
`, }, }, }) app.config.compilerOptions.delimiters = ['((', '))'] expect(await renderToString(app)).toBe(`
2
4
`) }) test('compilerOptions.whitespace', async () => { const app = createApp({ template: `
Hello world
`, compilerOptions: { whitespace: 'condense', }, components: { ChildComponent: { template: `Hello world`, }, }, }) app.config.compilerOptions.whitespace = 'preserve' expect(await renderToString(app)).toBe( `
Hello worldHello world
`, ) }) test('caching with compilerOptions', async () => { const template = `
{{1 + 1}} [[1 + 1]]
` const app = createApp({ template: `
`, components: { ChildOne: { template, }, ChildTwo: { template, compilerOptions: { whitespace: 'preserve', }, }, ChildThree: { template, compilerOptions: { delimiters: ['[[', ']]'], }, }, }, }) expect(await renderToString(app)).toBe( `
2 [[1 + 1]]
2 [[1 + 1]]
{{1 + 1}} 2
`, ) }) test('caching with isCustomElement', async () => { const template = `
` const app = createApp({ template, // No compilerOptions on the root components: { MyChild: { template, compilerOptions: { isCustomElement: tag => tag.startsWith('x-'), }, components: { MyChild: { template, compilerOptions: { isCustomElement: tag => tag.startsWith('My'), }, }, }, }, }, }) expect(await renderToString(app)).toBe( `
`, ) }) })