Skip to content

Commit

Permalink
fix: try catch scss render
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed Mar 18, 2018
1 parent 990469a commit 796751e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/compilers/scss-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path')
const fs = require('fs')
const ensureRequire = require('../ensure-require')
const cwd = process.cwd()
const logger = require('../logger')

const rewriteImports = (content, filePath) => content.replace(/@import\s+(?:'([^']+)'|"([^"]+)"|([^\s;]+))/g, (entire, single, double, unquoted) => {
const oldImportPath = single || double || unquoted
Expand All @@ -24,9 +25,14 @@ module.exports = (content, filePath, config) => {
.map(scssResourcePath => rewriteImports(fs.readFileSync(scssResourcePath).toString(), scssResourcePath))
.join('\n')
}

return sass.renderSync({
data: scssResources + rewriteImports(content, filePath),
outputStyle: 'compressed'
}).css.toString()
let result
try {
sass.renderSync({

This comment has been minimized.

Copy link
@jeremyzahner

jeremyzahner Apr 9, 2018

Contributor

@eddyerburgh Here we have the problem. =) The assignment to result is missing. Should not happen anymore after the test in #79 is merged.

data: scssResources + rewriteImports(content, filePath),
outputStyle: 'compressed'
}).css.toString()
} catch (err) {
logger.warn(`There was an error rendering the SCSS in ${filePath}. SCSS is not fully supported by vue-jest, so some features will throw errors. Webpack aliases are a common cause of errors.`)
}
return result || ''
}
2 changes: 2 additions & 0 deletions test/resources/Sass.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

<style lang="scss">
@import "./styles/transitions";
@import '~@design'
.testA {
background-color: red;
Expand Down

0 comments on commit 796751e

Please sign in to comment.