Skip to content

Commit

Permalink
chore: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
lmiller1990 committed Mar 5, 2021
2 parents 4e8d6c8 + 1fb3b2e commit 10559e1
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -25,3 +25,5 @@ pids
*.pid.lock

package-lock.json
/e2e/**/yarn.lock

22 changes: 22 additions & 0 deletions README.md
Expand Up @@ -271,6 +271,28 @@ If a string is provided, it will be an assumed path to a TypeScript configuratio
}
```

#### templateCompiler

You can provide [TemplateCompileOptions](https://github.com/vuejs/component-compiler-utils#compiletemplatetemplatecompileoptions-templatecompileresults) in `templateCompiler` section like this:

```json
{
"jest": {
"globals": {
"vue-jest": {
"templateCompiler": {
"transpileOptions": {
"transforms": {
"dangerousTaggedTemplateString": true
}
}
}
}
}
}
}
```

### Supported template languages

- **pug** (`lang="pug"`)
Expand Down
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
4 changes: 4 additions & 0 deletions e2e/__projects__/style/components/External.vue
Expand Up @@ -6,6 +6,10 @@

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

<style module="$style2" src="~__styles/external.css" />

<style module="$style3" src="./styles/external.css"></style>

<style module="css">
.a {
background: color(red a(90%));
Expand Down
2 changes: 2 additions & 0 deletions e2e/__projects__/style/test.js
Expand Up @@ -45,5 +45,7 @@ test('process External', () => {
const wrapper = mount(External)
expect(wrapper.vm).toBeTruthy()
expect(wrapper.vm.$style.testClass).toEqual('testClass')
expect(wrapper.vm.$style2.testClass).toEqual('testClass')
expect(wrapper.vm.$style3.testClass).toEqual('testClass')
expect(wrapper.vm.css.a).toEqual('a')
})
11 changes: 9 additions & 2 deletions lib/process-style.js
Expand Up @@ -52,8 +52,15 @@ function getPreprocessOptions(lang, filePath, jestConfig) {
module.exports = function processStyle(stylePart, filePath, config = {}) {
const vueJestConfig = getVueJestConfig(config)

if (stylePart.src && !stylePart.content) {
stylePart.content = loadSrc(stylePart.src, filePath)
if (stylePart.src && !stylePart.content.trim()) {
const cssFilePath = applyModuleNameMapper(
stylePart.src,
filePath,
config,
stylePart.lang
)
stylePart.content = loadSrc(cssFilePath, filePath)
filePath = cssFilePath
}

if (vueJestConfig.experimentalCSSCompile === false || !stylePart.content) {
Expand Down
11 changes: 7 additions & 4 deletions lib/process.js
Expand Up @@ -56,16 +56,19 @@ 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
}
})

logResultErrors(result)
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "vue-jest",
"version": "4.0.0-rc.0",
"version": "4.0.0",
"description": "Jest Vue transform",
"main": "lib/index.js",
"files": [
Expand Down
47 changes: 31 additions & 16 deletions yarn.lock
Expand Up @@ -4101,6 +4101,7 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6
growly@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=

hamljs@^0.6.2:
version "0.6.2"
Expand Down Expand Up @@ -4407,9 +4408,9 @@ inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@^2.0.4, inherits@~2.0.1,
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==

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

init-package-json@^1.10.3:
version "1.10.3"
Expand Down Expand Up @@ -5907,7 +5908,6 @@ lodash.isstring@^4.0.1:
lodash.memoize@4.x:
version "4.1.2"
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=

lodash.set@^4.3.2:
version "4.3.2"
Expand Down Expand Up @@ -6018,6 +6018,13 @@ lru-cache@^5.1.1:
dependencies:
yallist "^3.0.2"

lru-cache@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-6.0.0.tgz#6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94"
integrity sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==
dependencies:
yallist "^4.0.0"

macos-release@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/macos-release/-/macos-release-2.3.0.tgz#eb1930b036c0800adebccd5f17bc4c12de8bb71f"
Expand Down Expand Up @@ -6451,9 +6458,9 @@ node-modules-regexp@^1.0.0:
resolved "https://registry.yarnpkg.com/node-modules-regexp/-/node-modules-regexp-1.0.0.tgz#8d9dbe28964a4ac5712e9131642107c71e90ec40"

node-notifier@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-8.0.0.tgz#a7eee2d51da6d0f7ff5094bc7108c911240c1620"
integrity sha512-46z7DUmcjoYdaWyXouuFNNfUo6eFa94t23c53c+lG/9Cvauk4a98rAUp9672X5dxGdQmLpPzTxzu8f/OeEPaFA==
version "8.0.1"
resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-8.0.1.tgz#f86e89bbc925f2b068784b31f382afdc6ca56be1"
integrity sha512-BvEXF+UmsnAfYfoapKM9nGxnP+Wn7P91YfXmrKnfcYCx6VBeoN5Ez5Ogck6I8Bi5k4RlpqRYaw75pAwzX9OphA==
dependencies:
growly "^1.3.0"
is-wsl "^2.2.0"
Expand Down Expand Up @@ -6620,9 +6627,9 @@ npm-run-path@^4.0.0:
path-key "^3.0.0"

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

npm-which@^3.0.1:
version "3.0.1"
Expand Down Expand Up @@ -8200,9 +8207,11 @@ semver@7.0.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e"

semver@7.x, semver@^7.3.2:
version "7.3.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==
version "7.3.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.4.tgz#27aaa7d2e4ca76452f98d3add093a72c943edc97"
integrity sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==
dependencies:
lru-cache "^6.0.0"

semver@^6.0.0, semver@^6.3.0:
version "6.3.0"
Expand Down Expand Up @@ -8256,6 +8265,7 @@ shebang-regex@^3.0.0:
shellwords@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==

sigmund@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -9279,9 +9289,9 @@ uuid@^3.3.2, uuid@^3.3.3:
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==

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

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

yallist@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-4.0.0.tgz#9bb92790d9c0effec63be73519e11a35019a3a72"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==

yaml@^1.7.2:
version "1.8.2"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.8.2.tgz#a29c03f578faafd57dcb27055f9a5d569cb0c3d9"
Expand Down

0 comments on commit 10559e1

Please sign in to comment.