import { compile } from '../src' import { getCompiledString } from './utils' describe('ssr: text', () => { test('static text', () => { expect(getCompiledString(`foo`)).toMatchInlineSnapshot(`"\`foo\`"`) }) test('static text with template string special chars', () => { expect(getCompiledString(`\`\${foo}\``)).toMatchInlineSnapshot( `"\`\\\`\\\${foo}\\\`\`"`, ) }) test('static text with char escape', () => { // the desired generated code should be `\\\$foo` // snapshot -> inline snapshot goes through two escapes // so that makes a total of 3 * 2 * 2 = 12 back slashes expect(getCompiledString(`\\$foo`)).toMatchInlineSnapshot( `"\`\\\\\\$foo\`"`, ) }) test('comments', () => { expect(getCompiledString(``)).toMatchInlineSnapshot( `"\`\`"`, ) }) test('static text escape', () => { expect(getCompiledString(`<foo>`)).toMatchInlineSnapshot( `"\`<foo>\`"`, ) }) test('nested elements with static text', () => { expect( getCompiledString(`
hellobye
`), ).toMatchInlineSnapshot( `"\`
hellobye
\`"`, ) }) test('interpolation', () => { expect(compile(`foo {{ bar }} baz`).code).toMatchInlineSnapshot(` "const { ssrInterpolate: _ssrInterpolate } = require("vue/server-renderer") return function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`foo \${_ssrInterpolate(_ctx.bar)} baz\`) }" `) }) test('nested elements with interpolation', () => { expect( compile(`
{{ foo }} barbaz {{ qux }}
`) .code, ).toMatchInlineSnapshot(` "const { ssrRenderAttrs: _ssrRenderAttrs, ssrInterpolate: _ssrInterpolate } = require("vue/server-renderer") return function ssrRender(_ctx, _push, _parent, _attrs) { _push(\`\${ _ssrInterpolate(_ctx.foo) } barbaz \${ _ssrInterpolate(_ctx.qux) }\`) }" `) }) })