Skip to content

Commit dae9ab6

Browse files
committed
feat: add expirmentalCSSCompile flag
1 parent cf66298 commit dae9ab6

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

lib/process-style.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const cssExtract = require('extract-from-css')
22

3-
module.exports = function processStyle (stylePart, filePath, config) {
4-
if (!stylePart) return {}
5-
3+
module.exports = function processStyle (stylePart, filePath, config = {}) {
4+
if (!stylePart || config.experimentalCSSCompile === false) {
5+
return {}
6+
}
67
const processStyleByLang = lang => require('./compilers/' + lang + '-compiler')(stylePart.content, filePath, config)
78

89
let cssCode = stylePart.content
@@ -17,8 +18,8 @@ module.exports = function processStyle (stylePart, filePath, config) {
1718
}
1819

1920
const cssNames = cssExtract.extractClasses(cssCode)
20-
const obj = {}
2121

22+
const obj = {}
2223
for (let i = 0, l = cssNames.length; i < l; i++) {
2324
obj[cssNames[i]] = cssNames[i]
2425
}

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@
7979
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
8080
".*\\.(vue)$": "<rootDir>/vue-jest.js"
8181
},
82-
"mapCoverage": true
82+
"mapCoverage": true,
83+
"globals": {
84+
"vue-jest": {
85+
"experimentalStyles": true
86+
}
87+
}
8388
},
8489
"repository": {
8590
"type": "git",

test/stylus.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { shallow } from 'vue-test-utils'
22
import Stylus from './resources/Stylus.vue'
33
import StylusRelative from './resources/StylusRelative.vue'
4+
import { resolve } from 'path'
5+
import { readFileSync } from 'fs'
6+
import jestVue from '../vue-jest'
47

58
describe('processes .vue file with Stylus style', () => {
69
let wrapper
@@ -23,4 +26,14 @@ describe('processes .vue file with Stylus style', () => {
2326
it('should handle relative imports', () => {
2427
expect(() => shallow(StylusRelative)).not.toThrow()
2528
})
29+
30+
it('does not attempty to compile if experimentalStyles flag is passed', () => {
31+
const filePath = resolve(__dirname, './resources/Basic.vue')
32+
const fileString = readFileSync(filePath, { encoding: 'utf8' })
33+
const fileStringWithInvalidSass = `
34+
${fileString}
35+
<style lang="stylus">@something</style>
36+
`
37+
jestVue.process(fileStringWithInvalidSass, filePath, { globals: { 'vue-jest': { experimentalCSSCompile: false }}})
38+
})
2639
})

0 commit comments

Comments
 (0)