Skip to content

Commit ef459ed

Browse files
author
vasia
committed
fix test
1 parent a075a9d commit ef459ed

File tree

7 files changed

+44
-9
lines changed

7 files changed

+44
-9
lines changed

lib/compilers/postcss-compiler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ module.exports = (content) => {
99
let css = null
1010

1111
postcss(plugins)
12-
.process(content)
12+
.process(content, {
13+
from: undefined
14+
})
1315
.then(result => {
1416
css = result.css || ''
1517
})

lib/process.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ module.exports = function (src, filePath, jestConfig) {
8181

8282
if (Array.isArray(parts.styles) && parts.styles.length > 0) {
8383
if ((parts.styles.some(ast => /^less/.test(ast.lang))) && logger.shouldLogStyleWarn) {
84-
!vueJestConfig.hideStyleWarn && logger.warn('Less and PostCSS are not currently compiled by vue-jest')
84+
!vueJestConfig.hideStyleWarn && logger.warn('Less are not currently compiled by vue-jest')
8585
logger.shouldLogStyleWarn = false
8686
}
8787

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"jade": "^1.11.0",
4747
"jest": "^20.0.4",
4848
"node-sass": "^4.10.0",
49+
"postcss-custom-properties": "^9.0.2",
4950
"pug": "^2.0.0-rc.3",
5051
"stylus": "^0.54.5",
5152
"typescript": "^2.5.2",
@@ -68,6 +69,7 @@
6869
"object-assign": "^4.1.1",
6970
"postcss": "^7.0.17",
7071
"postcss-load-config": "^2.1.0",
72+
"postcss-nested": "^4.1.2",
7173
"source-map": "^0.5.6",
7274
"tsconfig": "^7.0.0",
7375
"vue-template-es2015-compiler": "^1.6.0"

postcss.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: {
3+
'postcss-custom-properties': {},
4+
'postcss-nested': {}
5+
}
6+
}

test/postcss.spec.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,25 @@ import PostCss from './resources/PostCss.vue'
33
import PostCssModule from './resources/PostCssModule.vue'
44

55
describe('processes .vue file with PostCSS style', () => {
6-
it('does not error on pcss/postcss', () => {
7-
const wrapper = shallowMount(PostCss)
6+
const wrapper = shallowMount(PostCss)
7+
8+
it('does stick classes to component', () => {
89
expect(wrapper.classes()).toContain('testPcss')
910
})
1011

11-
it('does not error on pcss/postcss module', () => {
12-
expect(() => shallowMount(PostCssModule)).not.toThrow()
12+
it('does stick next classes to component', () => {
13+
expect(wrapper.find('span').classes()).toContain('nestedCom')
14+
})
15+
16+
const wrapperModules = shallowMount(PostCssModule)
17+
18+
const classListModules = Object.keys(wrapperModules.vm.$style)
19+
20+
it('does inject classes to $style', () => {
21+
expect(classListModules).toContain('testPcss')
22+
})
23+
24+
it('does inject nested classes to $style', () => {
25+
expect(classListModules).toContain('nestedClass')
1326
})
1427
})

test/resources/PostCss.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
<template>
2-
<div class="testPcss"></div>
2+
<div class="testPcss">
3+
<span class="nestedCom"></span>
4+
</div>
35
</template>
46

57
<style lang="postcss">
68
.testPcss {
79
background-color: purple;
10+
11+
& .nestedCom {
12+
background-color: purple;
13+
}
814
}
915
</style>
1016

test/resources/PostCssModule.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,23 @@
55
<style module lang="postcss">
66
.testPcss {
77
background-color: purple;
8+
9+
& .nestedClass {
10+
background-color: purple;
11+
}
812
}
913
</style>
1014

1115
<style module lang="pcss">
1216
/* This syntax is for postcss-custom-properties */
13-
--primary-color: green;
17+
:root {
18+
primary-color: green;
19+
}
1420
1521
/* This syntax is for postcss-nesting, but invalid as Pure CSS */
1622
body {
1723
@media screen {
18-
background-color: grey;
24+
background-color: var(--primary-color);
1925
}
2026
}
2127
</style>

0 commit comments

Comments
 (0)