Skip to content

Commit 630c526

Browse files
committed
Merge branch 'master' of github.com:vuejs/vue-jest
2 parents 980ae73 + 3a0f4fe commit 630c526

File tree

22 files changed

+171
-1274
lines changed

22 files changed

+171
-1274
lines changed

e2e/2.x/babel-in-package/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
"@babel/preset-env": "^7.9.0",
1717
"@vue/test-utils": "^1.1.0",
1818
"coffeescript": "^2.3.2",
19-
"jest": "26.x",
20-
"ts-jest": "^26.3.0",
19+
"jest": "27.x",
20+
"ts-jest": "^27.0.4",
2121
"typescript": "^3.2.2",
22-
"vue2-jest": "~26.0.0"
22+
"vue2-jest": "~27.0.0-alpha.1"
2323
},
2424
"jest": {
25+
"testEnvironment": "jsdom",
2526
"moduleFileExtensions": [
2627
"js",
2728
"json",

e2e/2.x/basic/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
"babel-plugin-transform-vue-jsx": "^3.7.0",
2020
"coffeescript": "^2.3.2",
2121
"jade": "^1.11.0",
22-
"jest": "26.x",
22+
"jest": "27.x",
2323
"pug": "^3.0.1",
2424
"sass": "^1.23.7",
25-
"ts-jest": "^26.3.0",
25+
"ts-jest": "^27.0.4",
2626
"typescript": "^3.2.2",
27-
"vue2-jest": "~26.0.0"
27+
"vue2-jest": "~27.0.0-alpha.1"
2828
},
2929
"jest": {
30+
"testEnvironment": "jsdom",
3031
"moduleFileExtensions": [
3132
"js",
3233
"json",

e2e/2.x/basic/test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ test('handles named exports', () => {
3838
test('generates source maps for .vue files', () => {
3939
const filePath = resolve(__dirname, './components/Basic.vue')
4040
const fileString = readFileSync(filePath, { encoding: 'utf8' })
41+
const config = {
42+
moduleFileExtensions: ['js', 'vue']
43+
}
4144

4245
const { map } = jestVue.process(fileString, filePath, {
43-
moduleFileExtensions: ['js', 'vue']
46+
config
4447
})
4548

4649
expect(map).toMatchSnapshot()
@@ -50,8 +53,12 @@ test('generates source maps using src attributes', () => {
5053
const filePath = resolve(__dirname, './components/SourceMapsSrc.vue')
5154
const fileString = readFileSync(filePath, { encoding: 'utf8' })
5255

53-
const { map } = jestVue.process(fileString, filePath, {
56+
const config = {
5457
moduleFileExtensions: ['js', 'vue']
58+
}
59+
60+
const { map } = jestVue.process(fileString, filePath, {
61+
config
5562
})
5663

5764
expect(map).toMatchSnapshot()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { createTransformer } = require('babel-jest')
1+
const { createTransformer } = require('babel-jest').default
22
module.exports = createTransformer({
33
presets: ['@babel/preset-env']
44
})

e2e/2.x/custom-transformers/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
"@babel/core": "^7.9.0",
1515
"@babel/preset-env": "^7.9.0",
1616
"@vue/test-utils": "^1.1.0",
17-
"babel-jest": "^26.6.3",
18-
"jest": "26.x",
17+
"babel-jest": "^27.0.6",
18+
"jest": "27.x",
1919
"postcss": "^7.0.13",
2020
"postcss-color-function": "^4.0.1",
2121
"sass": "^1.23.7",
22-
"vue2-jest": "~26.0.0"
22+
"vue2-jest": "~27.0.0-alpha.1"
2323
},
2424
"jest": {
25+
"testEnvironment": "jsdom",
2526
"moduleFileExtensions": [
2627
"js",
2728
"json",

e2e/2.x/style/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
"@babel/core": "^7.9.0",
1515
"@babel/preset-env": "^7.9.0",
1616
"@vue/test-utils": "^1.1.0",
17-
"jest": "26.x",
17+
"jest": "27.x",
1818
"less": "^3.9.0",
1919
"postcss": "^7.0.13",
2020
"sass": "^1.23.7",
2121
"stylus": "^0.54.5",
22-
"vue2-jest": "~26.0.0"
22+
"vue2-jest": "~27.0.0-alpha.1"
2323
},
2424
"jest": {
25+
"testEnvironment": "jsdom",
2526
"moduleFileExtensions": [
2627
"js",
2728
"json",

e2e/3.x/custom-transformers/components/Scss.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div>
3-
<span :class="this.$style.g"></span>
4-
<span :class="this.$style.dark.f"></span>
3+
<span :class="$style.g"></span>
4+
<span :class="$style.dark.f"></span>
55
</div>
66
</template>
77

e2e/3.x/custom-transformers/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"devDependencies": {
1414
"@babel/core": "^7.9.0",
1515
"@babel/preset-env": "^7.9.0",
16+
"@vue/test-utils": "^2.0.0-rc.10",
1617
"babel-jest": "^27.0.0",
1718
"extract-from-css": "^0.4.4",
1819
"jest": "^27.0.0",
@@ -22,6 +23,7 @@
2223
"vue3-jest": "^27.0.0-alpha.1"
2324
},
2425
"jest": {
26+
"testEnvironment": "jsdom",
2527
"moduleFileExtensions": [
2628
"js",
2729
"json",

e2e/3.x/custom-transformers/test.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
// import { createApp, h } from 'vue'
2-
3-
// import Scss from './components/Scss.vue'
4-
5-
// function mount(Component, props, slots) {
6-
// document.getElementsByTagName('html')[0].innerHTML = ''
7-
// const el = document.createElement('div')
8-
// el.id = 'app'
9-
// document.body.appendChild(el)
10-
// const Parent = {
11-
// render() {
12-
// return h(Component, props, slots)
13-
// }
14-
// }
15-
// createApp(Parent).mount(el)
16-
// }
17-
18-
// TODO: Figure this out with Vue 3. `$style` no longer exists.
19-
test.todo('processes SCSS using user specified post transforms')
20-
21-
test.todo('processes SCSS using user specified pre transforms')
1+
import { mount } from '@vue/test-utils'
2+
import Scss from './components/Scss.vue'
3+
4+
test('processes SCSS using user specified post transforms', () => {
5+
const wrapper = mount(Scss)
6+
expect(wrapper.vm.$style.light.a).toBeUndefined()
7+
expect(wrapper.vm.$style.light.f).toEqual('f')
8+
expect(wrapper.vm.$style.dark.f).toEqual('f')
9+
expect(wrapper.vm.$style.dark.g).toEqual('g')
10+
})
11+
12+
test('processes SCSS using user specified pre transforms', () => {
13+
const wrapper = mount(Scss)
14+
expect(wrapper.vm.$style.g).toEqual('g')
15+
})

e2e/3.x/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/3.x/style/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"devDependencies": {
1414
"@babel/core": "^7.9.0",
1515
"@babel/preset-env": "^7.9.0",
16-
"@vue/test-utils": "^1.1.0",
16+
"@vue/test-utils": "^2.0.0-rc.10",
1717
"jest": "^27.0.0",
1818
"less": "^3.9.0",
1919
"postcss": "^7.0.13",

e2e/3.x/style/test.js

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// TODO: Support styles
2-
//
3-
import { createApp, h } from 'vue'
1+
import { mount } from '@vue/test-utils'
42

53
import Less from './components/Less.vue'
64
import Stylus from './components/Stylus.vue'
@@ -9,73 +7,42 @@ import Sass from './components/Sass.vue'
97
import PostCss from './components/PostCss.vue'
108
import External from './components/External.vue'
119

12-
function mount(Component, props, slots) {
13-
document.getElementsByTagName('html')[0].innerHTML = ''
14-
const el = document.createElement('div')
15-
el.id = 'app'
16-
document.body.appendChild(el)
17-
const Parent = {
18-
render() {
19-
return h(Component, props, slots)
20-
}
21-
}
22-
createApp(Parent).mount(el)
23-
}
24-
2510
test('processes Less', () => {
26-
mount(Less)
27-
expect(document.getElementById('app').innerHTML).toEqual(
28-
'<div><div class="a">a</div><div class="b">b</div><div class="c">c</div><div class="d">d</div></div>'
29-
)
11+
const wrapper = mount(Less)
12+
expect(wrapper.vm.$style.a).toEqual('a')
3013
})
3114

3215
test('processes PostCSS', () => {
33-
mount(PostCss)
34-
expect(document.getElementById('app').innerHTML).toEqual(
35-
'<section><div class="c"></div><div class="d"></div></section>'
36-
)
37-
// expect(wrapper.is('section')).toBeTruthy()
38-
// expect(wrapper.vm.$style.a).toEqual('a')
39-
// expect(wrapper.vm.$style.b).toEqual('b')
16+
const wrapper = mount(PostCss)
17+
expect(wrapper.vm.$style.c).toEqual('c')
18+
expect(wrapper.vm.$style.d).toEqual('d')
4019
})
4120

4221
test('processes Sass', () => {
43-
mount(Sass)
44-
expect(document.getElementById('app').innerHTML).toEqual(
45-
'<div><div class="a"></div><div class="b"></div><div class="c"></div><div class=""></div><div class="e"></div></div>'
46-
)
47-
// expect(wrapper.vm.$style.a).toEqual('a')
48-
// expect(wrapper.vm.$style.b).toEqual('b')
49-
// expect(wrapper.vm.$style.c).toEqual('c')
50-
// expect(wrapper.vm.$style.light).toBeUndefined()
22+
const wrapper = mount(Sass)
23+
expect(wrapper.vm.$style.a).toEqual('a')
24+
expect(wrapper.vm.$style.b).toEqual('b')
25+
expect(wrapper.vm.$style.c).toEqual('c')
26+
expect(wrapper.vm.$style.light).toBeUndefined()
5127
})
5228

5329
test('processes SCSS with resources', () => {
54-
mount(Scss)
55-
expect(document.getElementById('app').innerHTML).toEqual(
56-
'<div><div class="a"></div><div class="b"></div><div class="c"></div><div class=""></div><div class=""></div><div class="f"></div></div>'
57-
)
58-
// expect(wrapper.vm.$style.a).toEqual('a')
59-
// expect(wrapper.vm.$style.b).toEqual('b')
60-
// expect(wrapper.vm.$style.c).toEqual('c')
30+
const wrapper = mount(Scss)
31+
expect(wrapper.vm.$style.a).toEqual('a')
32+
expect(wrapper.vm.$style.b).toEqual('b')
33+
expect(wrapper.vm.$style.c).toEqual('c')
6134
})
6235

6336
test('process Stylus', () => {
64-
mount(Stylus)
65-
expect(document.getElementById('app').innerHTML).toEqual(
66-
'<div><div class="a"></div><div class="b"></div></div>'
67-
)
68-
// expect(wrapper.vm).toBeTruthy()
69-
// expect(wrapper.vm.css.a).toEqual('a')
70-
// expect(wrapper.vm.$style.b).toEqual('b')
37+
const wrapper = mount(Stylus)
38+
expect(wrapper.vm).toBeTruthy()
39+
expect(wrapper.vm.css.a).toEqual('a')
40+
expect(wrapper.vm.$style.b).toEqual('b')
7141
})
7242

7343
test('process External', () => {
74-
mount(External)
75-
expect(document.getElementById('app').innerHTML).toEqual(
76-
'<div class="testClass"><div class="a"></div></div>'
77-
)
78-
// expect(wrapper.vm).toBeTruthy()
79-
// expect(wrapper.vm.$style.xtestClass).toEqual('xtestClass')
80-
// expect(wrapper.vm.css.a).toEqual('a')
44+
const wrapper = mount(External)
45+
expect(wrapper.vm).toBeTruthy()
46+
expect(wrapper.vm.$style.testClass).toEqual('testClass')
47+
expect(wrapper.vm.css.a).toEqual('a')
8148
})

packages/vue2-jest/lib/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
const crypto = require('crypto')
2-
const babelJest = require('babel-jest')
3-
2+
const babelJest = require('babel-jest').default
43
module.exports = {
54
process: require('./process'),
65
getCacheKey: function getCacheKey(
76
fileData,
87
filename,
9-
configString,
10-
{ config, instrument, rootDir }
8+
{ config, configString, instrument, rootDir }
119
) {
1210
return crypto
1311
.createHash('md5')
1412
.update(
15-
babelJest.getCacheKey(fileData, filename, configString, {
13+
babelJest.getCacheKey(fileData, filename, {
1614
config,
15+
configString,
1716
instrument,
1817
rootDir
1918
}),

packages/vue2-jest/lib/process-style.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = function processStyle(stylePart, filePath, config = {}) {
5656
const cssFilePath = applyModuleNameMapper(
5757
stylePart.src,
5858
filePath,
59-
config,
59+
config.config,
6060
stylePart.lang
6161
)
6262
stylePart.content = loadSrc(cssFilePath, filePath)
@@ -86,7 +86,7 @@ module.exports = function processStyle(stylePart, filePath, config = {}) {
8686
const preprocessOptions = getPreprocessOptions(
8787
stylePart.lang,
8888
filePath,
89-
config
89+
config.config
9090
)
9191
const result = compileStyle({
9292
source: content,

packages/vue2-jest/lib/process.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const logResultErrors = require('./utils').logResultErrors
1010
const stripInlineSourceMap = require('./utils').stripInlineSourceMap
1111
const getCustomTransformer = require('./utils').getCustomTransformer
1212
const loadSrc = require('./utils').loadSrc
13-
const babelTransformer = require('babel-jest')
13+
const babelTransformer = require('babel-jest').default
1414
const compilerUtils = require('@vue/component-compiler-utils')
1515
const generateCode = require('./generate-code')
1616

packages/vue2-jest/lib/transformers/coffee.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const throwError = require('../utils').throwError
33
const getBabelOptions = require('../utils').getBabelOptions
44

55
module.exports = {
6-
process(src, filename, config) {
6+
process(src, filename) {
77
ensureRequire('coffee', ['coffeescript'])
88
const coffee = require('coffeescript')
99
const babelOptions = getBabelOptions(filename)

0 commit comments

Comments
 (0)