Skip to content

Commit

Permalink
Merge pull request #288 from FRSource/feat-add-compile-template-options
Browse files Browse the repository at this point in the history
feat: add compile template options
  • Loading branch information
lmiller1990 committed Sep 28, 2020
2 parents 4afea00 + 37efa58 commit 0f450a5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
21 changes: 21 additions & 0 deletions e2e/__projects__/basic/components/TemplateString.vue
@@ -0,0 +1,21 @@
<template>
<div
:data-sth="
gql`
query {
id
}
`
"
/>
</template>

<script lang="ts">
export default {
methods: {
gql([str]) {
return str
}
}
}
</script>
7 changes: 7 additions & 0 deletions e2e/__projects__/basic/package.json
Expand Up @@ -38,6 +38,13 @@
"vue-jest": {
"pug": {
"basedir": "./"
},
"templateCompiler": {
"transpileOptions": {
"transforms": {
"dangerousTaggedTemplateString": true
}
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions e2e/__projects__/basic/test.js
@@ -1,5 +1,6 @@
import { mount } from '@vue/test-utils'
import TypeScript from './components/TypeScript.vue'
import TemplateString from './components/TemplateString.vue'
import { resolve } from 'path'
import { readFileSync } from 'fs'
import jestVue from 'vue-jest'
Expand Down Expand Up @@ -81,6 +82,15 @@ test('processes .vue files with lang set to typescript', () => {
expect(wrapper.element.tagName).toBe('DIV')
})

test('processes .vue files with template strings in the template', () => {
const wrapper = mount(TemplateString)
expect(wrapper.attributes('data-sth')).toBe(`
query {
id
}
`)
})

test('processes functional components', () => {
const clickSpy = jest.fn()
const wrapper = mount(FunctionalSFC, {
Expand Down
13 changes: 9 additions & 4 deletions lib/process.js
Expand Up @@ -57,16 +57,21 @@ function processTemplate(template, filename, config) {
template.content = loadSrc(template.src, filename)
}

const userTemplateCompilerOptions = vueJestConfig.templateCompiler || {}
const result = compilerUtils.compileTemplate({
source: template.content,
compiler: VueTemplateCompiler,
filename: filename,
compilerOptions: {
optimize: false
},
isFunctional: template.attrs.functional,
preprocessLang: template.lang,
preprocessOptions: vueJestConfig[template.lang]
preprocessOptions: vueJestConfig[template.lang],
...userTemplateCompilerOptions,
compilerOptions: {
optimize: false,
...userTemplateCompilerOptions.compilerOptions
},
transformAssetUrls: { ...userTemplateCompilerOptions.transformAssetUrls },
transpileOptions: { ...userTemplateCompilerOptions.transpileOptions }
})

logResultErrors(result)
Expand Down

0 comments on commit 0f450a5

Please sign in to comment.