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

+2
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

+22
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"`)
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, {

e2e/__projects__/style/components/External.vue

+4
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

+2
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

+9-2
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

+7-4
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

+1-1
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": [

yarn.lock

+31-16
Original file line numberDiff line numberDiff line change
@@ -4101,6 +4101,7 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6
41014101
growly@^1.3.0:
41024102
version "1.3.0"
41034103
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
4104+
integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=
41044105

41054106
hamljs@^0.6.2:
41064107
version "0.6.2"
@@ -4407,9 +4408,9 @@ inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.1,
44074408
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==
44084409

44094410
ini@^1.3.2, ini@^1.3.4, ini@^1.3.5, ini@~1.3.0:
4410-
version "1.3.5"
4411-
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
4412-
integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==
4411+
version "1.3.7"
4412+
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.7.tgz#a09363e1911972ea16d7a8851005d84cf09a9a84"
4413+
integrity sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ==
44134414

44144415
init-package-json@^1.10.3:
44154416
version "1.10.3"
@@ -5907,7 +5908,6 @@ lodash.isstring@^4.0.1:
59075908
59085909
version "4.1.2"
59095910
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
5910-
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=
59115911

59125912
lodash.set@^4.3.2:
59135913
version "4.3.2"
@@ -6018,6 +6018,13 @@ lru-cache@^5.1.1:
60186018
dependencies:
60196019
yallist "^3.0.2"
60206020

6021+
lru-cache@^6.0.0:
6022+
version "6.0.0"
6023+
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
6024+
integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==
6025+
dependencies:
6026+
yallist "^4.0.0"
6027+
60216028
macos-release@^2.2.0:
60226029
version "2.3.0"
60236030
resolved "https://registry.yarnpkg.com/macos-release/-/macos-release-2.3.0.tgz#eb1930b036c0800adebccd5f17bc4c12de8bb71f"
@@ -6451,9 +6458,9 @@ node-modules-regexp@^1.0.0:
64516458
resolved "https://registry.yarnpkg.com/node-modules-regexp/-/node-modules-regexp-1.0.0.tgz#8d9dbe28964a4ac5712e9131642107c71e90ec40"
64526459

64536460
node-notifier@^8.0.0:
6454-
version "8.0.0"
6455-
resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-8.0.0.tgz#a7eee2d51da6d0f7ff5094bc7108c911240c1620"
6456-
integrity sha512-46z7DUmcjoYdaWyXouuFNNfUo6eFa94t23c53c+lG/9Cvauk4a98rAUp9672X5dxGdQmLpPzTxzu8f/OeEPaFA==
6461+
version "8.0.1"
6462+
resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-8.0.1.tgz#f86e89bbc925f2b068784b31f382afdc6ca56be1"
6463+
integrity sha512-BvEXF+UmsnAfYfoapKM9nGxnP+Wn7P91YfXmrKnfcYCx6VBeoN5Ez5Ogck6I8Bi5k4RlpqRYaw75pAwzX9OphA==
64576464
dependencies:
64586465
growly "^1.3.0"
64596466
is-wsl "^2.2.0"
@@ -6620,9 +6627,9 @@ npm-run-path@^4.0.0:
66206627
path-key "^3.0.0"
66216628

66226629
npm-user-validate@~1.0.0:
6623-
version "1.0.0"
6624-
resolved "https://registry.yarnpkg.com/npm-user-validate/-/npm-user-validate-1.0.0.tgz#8ceca0f5cea04d4e93519ef72d0557a75122e951"
6625-
integrity sha1-jOyg9c6gTU6TUZ73LQVXp1Ei6VE=
6630+
version "1.0.1"
6631+
resolved "https://registry.yarnpkg.com/npm-user-validate/-/npm-user-validate-1.0.1.tgz#31428fc5475fe8416023f178c0ab47935ad8c561"
6632+
integrity sha512-uQwcd/tY+h1jnEaze6cdX/LrhWhoBxfSknxentoqmIuStxUExxjWd3ULMLFPiFUrZKbOVMowH6Jq2FRWfmhcEw==
66266633

66276634
npm-which@^3.0.1:
66286635
version "3.0.1"
@@ -8200,9 +8207,11 @@ [email protected]:
82008207
resolved "https://registry.yarnpkg.com/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e"
82018208

82028209
[email protected], semver@^7.3.2:
8203-
version "7.3.2"
8204-
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
8205-
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==
8210+
version "7.3.4"
8211+
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.4.tgz#27aaa7d2e4ca76452f98d3add093a72c943edc97"
8212+
integrity sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==
8213+
dependencies:
8214+
lru-cache "^6.0.0"
82068215

82078216
semver@^6.0.0, semver@^6.3.0:
82088217
version "6.3.0"
@@ -8256,6 +8265,7 @@ shebang-regex@^3.0.0:
82568265
shellwords@^0.1.1:
82578266
version "0.1.1"
82588267
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
8268+
integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==
82598269

82608270
sigmund@^1.0.1:
82618271
version "1.0.1"
@@ -9279,9 +9289,9 @@ uuid@^3.3.2, uuid@^3.3.3:
92799289
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
92809290

92819291
uuid@^8.3.0:
9282-
version "8.3.0"
9283-
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.0.tgz#ab738085ca22dc9a8c92725e459b1d507df5d6ea"
9284-
integrity sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ==
9292+
version "8.3.2"
9293+
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
9294+
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
92859295

92869296
v8-to-istanbul@^5.0.1:
92879297
version "5.0.1"
@@ -9575,6 +9585,11 @@ yallist@^3.0.0, yallist@^3.0.2, yallist@^3.0.3:
95759585
resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd"
95769586
integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==
95779587

9588+
yallist@^4.0.0:
9589+
version "4.0.0"
9590+
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
9591+
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==
9592+
95789593
yaml@^1.7.2:
95799594
version "1.8.2"
95809595
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.8.2.tgz#a29c03f578faafd57dcb27055f9a5d569cb0c3d9"

0 commit comments

Comments
 (0)