Skip to content

Commit

Permalink
feat: add expirmentalCSSCompile flag
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed Mar 22, 2018
1 parent cf66298 commit dae9ab6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/process-style.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const cssExtract = require('extract-from-css')

module.exports = function processStyle (stylePart, filePath, config) {
if (!stylePart) return {}

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

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

const cssNames = cssExtract.extractClasses(cssCode)
const obj = {}

const obj = {}
for (let i = 0, l = cssNames.length; i < l; i++) {
obj[cssNames[i]] = cssNames[i]
}
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/vue-jest.js"
},
"mapCoverage": true
"mapCoverage": true,
"globals": {
"vue-jest": {
"experimentalStyles": true
}
}
},
"repository": {
"type": "git",
Expand Down
13 changes: 13 additions & 0 deletions test/stylus.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { shallow } from 'vue-test-utils'
import Stylus from './resources/Stylus.vue'
import StylusRelative from './resources/StylusRelative.vue'
import { resolve } from 'path'
import { readFileSync } from 'fs'
import jestVue from '../vue-jest'

describe('processes .vue file with Stylus style', () => {
let wrapper
Expand All @@ -23,4 +26,14 @@ describe('processes .vue file with Stylus style', () => {
it('should handle relative imports', () => {
expect(() => shallow(StylusRelative)).not.toThrow()
})

it('does not attempty to compile if experimentalStyles flag is passed', () => {
const filePath = resolve(__dirname, './resources/Basic.vue')
const fileString = readFileSync(filePath, { encoding: 'utf8' })
const fileStringWithInvalidSass = `
${fileString}
<style lang="stylus">@something</style>
`
jestVue.process(fileStringWithInvalidSass, filePath, { globals: { 'vue-jest': { experimentalCSSCompile: false }}})
})
})

0 comments on commit dae9ab6

Please sign in to comment.