Skip to content

Commit

Permalink
fix: do not compile scss
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed Feb 4, 2018
1 parent 15b899a commit d94738e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module.exports.info = function info (msg) {
console.info('\n[vue-jest] Info: ' + (msg) + '\n')
console.info('\n[vue-jest]: ' + (msg) + '\n')
}

module.exports.warn = function info (msg) {
console.warn('\n[vue-jest]: ' + (msg) + '\n')
}
9 changes: 7 additions & 2 deletions lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const extractPropsFromFunctionalTemplate = require('./extract-props')
const fs = require('fs')
const join = require('path').join
const cssExtract = require('extract-from-css')

const logger = require('./logger')
const splitRE = /\r?\n/g

function processScript (scriptPart) {
Expand Down Expand Up @@ -101,11 +101,16 @@ module.exports = function (src, path) {
if (Array.isArray(parts.styles) && parts.styles.length > 0) {
const styleStr = parts.styles.map(ast => {
if (!module) return
if (/^scss|sass/.test(ast.lang)) {
logger.warn('scss and sass are not currently compiled by vue-jest')
return false
}

const moduleName = ast.module === true ? '$style' : ast.module
const styleObj = processStyle(ast)

return '\n this[\'' + moduleName + '\'] = ' + JSON.stringify(styleObj)
})
}).filter(_ => _)

if (styleStr.length !== 0) {
output += '\n;(function() {' +
Expand Down
2 changes: 1 addition & 1 deletion test/Babel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test('logs info when there is no .babelrc', () => {

jestVue.process(fileString, filePath)
try {
expect(info).toHaveBeenCalledWith('\n[vue-jest] Info: no .babelrc found, skipping babel compilation\n')
expect(info).toHaveBeenCalledWith('\n[vue-jest]: no .babelrc found, skipping babel compilation\n')
} catch (err) {
renameSync(tempPath, babelRcPath)
throw err
Expand Down
15 changes: 15 additions & 0 deletions test/resources/Sass.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<div class="testA"></div>
</template>

<style lang="scss">
@import "./styles/transitions";
.testA {
background-color: red;
}
</style>

<style lang="sass">
$primary-color: #333
</style>
9 changes: 9 additions & 0 deletions test/scss.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { shallow } from 'vue-test-utils'
import Sass from './resources/Sass.vue'

describe('processes .vue file with Stylus style', () => {
it('does not error on scss or sass', () => {
const wrapper = shallow(Sass)
expect(wrapper.classes()).toContain('testA')
})
})

0 comments on commit d94738e

Please sign in to comment.