2020-02-04 06:47:06 +08:00
|
|
|
import { compile } from '../src'
|
2020-02-04 00:46:14 +08:00
|
|
|
import { getCompiledString } from './utils'
|
|
|
|
|
2020-02-04 04:51:41 +08:00
|
|
|
describe('ssr: text', () => {
|
2020-02-04 00:46:14 +08:00
|
|
|
test('static text', () => {
|
|
|
|
expect(getCompiledString(`foo`)).toMatchInlineSnapshot(`"\`foo\`"`)
|
|
|
|
})
|
|
|
|
|
2020-05-02 05:04:36 +08:00
|
|
|
test('comments', () => {
|
|
|
|
expect(getCompiledString(`<!--bar-->`)).toMatchInlineSnapshot(
|
|
|
|
`"\`<!--bar-->\`"`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-02-04 00:46:14 +08:00
|
|
|
test('static text escape', () => {
|
|
|
|
expect(getCompiledString(`<foo>`)).toMatchInlineSnapshot(
|
|
|
|
`"\`<foo>\`"`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('nested elements with static text', () => {
|
|
|
|
expect(
|
|
|
|
getCompiledString(`<div><span>hello</span><span>bye</span></div>`)
|
|
|
|
).toMatchInlineSnapshot(
|
|
|
|
`"\`<div><span>hello</span><span>bye</span></div>\`"`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('interpolation', () => {
|
2020-02-04 06:47:06 +08:00
|
|
|
expect(compile(`foo {{ bar }} baz`).code).toMatchInlineSnapshot(`
|
2020-02-08 08:04:55 +08:00
|
|
|
"const { ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\")
|
2020-02-04 06:47:06 +08:00
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent) {
|
2020-02-07 01:09:09 +08:00
|
|
|
_push(\`foo \${_ssrInterpolate(_ctx.bar)} baz\`)
|
2020-02-04 06:47:06 +08:00
|
|
|
}"
|
|
|
|
`)
|
2020-02-04 00:46:14 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('nested elements with interpolation', () => {
|
|
|
|
expect(
|
2020-02-04 06:47:06 +08:00
|
|
|
compile(`<div><span>{{ foo }} bar</span><span>baz {{ qux }}</span></div>`)
|
|
|
|
.code
|
|
|
|
).toMatchInlineSnapshot(`
|
2020-02-08 08:04:55 +08:00
|
|
|
"const { ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\")
|
2020-02-04 06:47:06 +08:00
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent) {
|
2020-02-05 05:47:12 +08:00
|
|
|
_push(\`<div><span>\${
|
2020-02-07 01:09:09 +08:00
|
|
|
_ssrInterpolate(_ctx.foo)
|
2020-02-05 05:47:12 +08:00
|
|
|
} bar</span><span>baz \${
|
2020-02-07 01:09:09 +08:00
|
|
|
_ssrInterpolate(_ctx.qux)
|
2020-02-05 05:47:12 +08:00
|
|
|
}</span></div>\`)
|
2020-02-04 06:47:06 +08:00
|
|
|
}"
|
|
|
|
`)
|
2020-02-04 00:46:14 +08:00
|
|
|
})
|
|
|
|
})
|