Skip to content

Commit 0f450a5

Browse files
authored
Merge pull request #288 from FRSource/feat-add-compile-template-options
feat: add compile template options
2 parents 4afea00 + 37efa58 commit 0f450a5

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div
3+
:data-sth="
4+
gql`
5+
query {
6+
id
7+
}
8+
`
9+
"
10+
/>
11+
</template>
12+
13+
<script lang="ts">
14+
export default {
15+
methods: {
16+
gql([str]) {
17+
return str
18+
}
19+
}
20+
}
21+
</script>

e2e/__projects__/basic/package.json

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
"vue-jest": {
3939
"pug": {
4040
"basedir": "./"
41+
},
42+
"templateCompiler": {
43+
"transpileOptions": {
44+
"transforms": {
45+
"dangerousTaggedTemplateString": true
46+
}
47+
}
4148
}
4249
}
4350
}

e2e/__projects__/basic/test.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mount } from '@vue/test-utils'
22
import TypeScript from './components/TypeScript.vue'
3+
import TemplateString from './components/TemplateString.vue'
34
import { resolve } from 'path'
45
import { readFileSync } from 'fs'
56
import jestVue from 'vue-jest'
@@ -81,6 +82,15 @@ test('processes .vue files with lang set to typescript', () => {
8182
expect(wrapper.element.tagName).toBe('DIV')
8283
})
8384

85+
test('processes .vue files with template strings in the template', () => {
86+
const wrapper = mount(TemplateString)
87+
expect(wrapper.attributes('data-sth')).toBe(`
88+
query {
89+
id
90+
}
91+
`)
92+
})
93+
8494
test('processes functional components', () => {
8595
const clickSpy = jest.fn()
8696
const wrapper = mount(FunctionalSFC, {

lib/process.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,21 @@ function processTemplate(template, filename, config) {
5757
template.content = loadSrc(template.src, filename)
5858
}
5959

60+
const userTemplateCompilerOptions = vueJestConfig.templateCompiler || {}
6061
const result = compilerUtils.compileTemplate({
6162
source: template.content,
6263
compiler: VueTemplateCompiler,
6364
filename: filename,
64-
compilerOptions: {
65-
optimize: false
66-
},
6765
isFunctional: template.attrs.functional,
6866
preprocessLang: template.lang,
69-
preprocessOptions: vueJestConfig[template.lang]
67+
preprocessOptions: vueJestConfig[template.lang],
68+
...userTemplateCompilerOptions,
69+
compilerOptions: {
70+
optimize: false,
71+
...userTemplateCompilerOptions.compilerOptions
72+
},
73+
transformAssetUrls: { ...userTemplateCompilerOptions.transformAssetUrls },
74+
transpileOptions: { ...userTemplateCompilerOptions.transpileOptions }
7075
})
7176

7277
logResultErrors(result)

0 commit comments

Comments
 (0)