Skip to content

Commit 10559e1

Browse files
committed
chore: rebase
2 parents 4e8d6c8 + 1fb3b2e commit 10559e1

File tree

11 files changed

+116
-23
lines changed

11 files changed

+116
-23
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ pids
2525
*.pid.lock
2626

2727
package-lock.json
28+
/e2e/**/yarn.lock
29+

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,28 @@ If a string is provided, it will be an assumed path to a TypeScript configuratio
271271
}
272272
```
273273

274+
#### templateCompiler
275+
276+
You can provide [TemplateCompileOptions](https://github.com/vuejs/component-compiler-utils#compiletemplatetemplatecompileoptions-templatecompileresults) in `templateCompiler` section like this:
277+
278+
```json
279+
{
280+
"jest": {
281+
"globals": {
282+
"vue-jest": {
283+
"templateCompiler": {
284+
"transpileOptions": {
285+
"transforms": {
286+
"dangerousTaggedTemplateString": true
287+
}
288+
}
289+
}
290+
}
291+
}
292+
}
293+
}
294+
```
295+
274296
### Supported template languages
275297

276298
- **pug** (`lang="pug"`)
Lines changed: 21 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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, {

e2e/__projects__/style/components/External.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
<style module src="./styles/external.css" />
88

9+
<style module="$style2" src="~__styles/external.css" />
10+
11+
<style module="$style3" src="./styles/external.css"></style>
12+
913
<style module="css">
1014
.a {
1115
background: color(red a(90%));

e2e/__projects__/style/test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,7 @@ test('process External', () => {
4545
const wrapper = mount(External)
4646
expect(wrapper.vm).toBeTruthy()
4747
expect(wrapper.vm.$style.testClass).toEqual('testClass')
48+
expect(wrapper.vm.$style2.testClass).toEqual('testClass')
49+
expect(wrapper.vm.$style3.testClass).toEqual('testClass')
4850
expect(wrapper.vm.css.a).toEqual('a')
4951
})

lib/process-style.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,15 @@ function getPreprocessOptions(lang, filePath, jestConfig) {
5252
module.exports = function processStyle(stylePart, filePath, config = {}) {
5353
const vueJestConfig = getVueJestConfig(config)
5454

55-
if (stylePart.src && !stylePart.content) {
56-
stylePart.content = loadSrc(stylePart.src, filePath)
55+
if (stylePart.src && !stylePart.content.trim()) {
56+
const cssFilePath = applyModuleNameMapper(
57+
stylePart.src,
58+
filePath,
59+
config,
60+
stylePart.lang
61+
)
62+
stylePart.content = loadSrc(cssFilePath, filePath)
63+
filePath = cssFilePath
5764
}
5865

5966
if (vueJestConfig.experimentalCSSCompile === false || !stylePart.content) {

lib/process.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,19 @@ function processTemplate(template, filename, config) {
5656
template.content = loadSrc(template.src, filename)
5757
}
5858

59+
const userTemplateCompilerOptions = vueJestConfig.templateCompiler || {}
5960
const result = compilerUtils.compileTemplate({
6061
source: template.content,
6162
compiler: VueTemplateCompiler,
6263
filename: filename,
63-
compilerOptions: {
64-
optimize: false
65-
},
6664
isFunctional: template.attrs.functional,
6765
preprocessLang: template.lang,
68-
preprocessOptions: vueJestConfig[template.lang]
66+
preprocessOptions: vueJestConfig[template.lang],
67+
...userTemplateCompilerOptions,
68+
compilerOptions: {
69+
optimize: false,
70+
...userTemplateCompilerOptions.compilerOptions
71+
}
6972
})
7073

7174
logResultErrors(result)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-jest",
3-
"version": "4.0.0-rc.0",
3+
"version": "4.0.0",
44
"description": "Jest Vue transform",
55
"main": "lib/index.js",
66
"files": [

0 commit comments

Comments
 (0)