@@ -6,6 +6,7 @@ const compileStyle = require('@vue/component-compiler-utils').compileStyle
66const applyModuleNameMapper = require ( './module-name-mapper-helper' )
77const getCustomTransformer = require ( './utils' ) . getCustomTransformer
88const logResultErrors = require ( './utils' ) . logResultErrors
9+ const loadSrc = require ( './utils' ) . loadSrc
910
1011function getGlobalResources ( resources , lang ) {
1112 let globalResources = ''
@@ -48,9 +49,13 @@ function getPreprocessOptions(lang, filePath, jestConfig) {
4849 }
4950}
5051
51- module . exports = function processStyle ( stylePart , filename , config = { } ) {
52+ module . exports = function processStyle ( stylePart , filePath , config = { } ) {
5253 const vueJestConfig = getVueJestConfig ( config )
5354
55+ if ( stylePart . src && ! stylePart . content ) {
56+ stylePart . content = loadSrc ( stylePart . src , filePath )
57+ }
58+
5459 if ( vueJestConfig . experimentalCSSCompile === false || ! stylePart . content ) {
5560 return '{}'
5661 }
@@ -64,21 +69,21 @@ module.exports = function processStyle(stylePart, filename, config = {}) {
6469
6570 // pre process
6671 if ( transformer . preprocess ) {
67- content = transformer . preprocess ( content , filename , config , stylePart . attrs )
72+ content = transformer . preprocess ( content , filePath , config , stylePart . attrs )
6873 }
6974
7075 // transform
7176 if ( transformer . process ) {
72- content = transformer . process ( content , filename , config , stylePart . attrs )
77+ content = transformer . process ( content , filePath , config , stylePart . attrs )
7378 } else {
7479 const preprocessOptions = getPreprocessOptions (
7580 stylePart . lang ,
76- filename ,
81+ filePath ,
7782 config
7883 )
7984 const result = compileStyle ( {
8085 source : content ,
81- filename ,
86+ filePath ,
8287 preprocessLang : stylePart . lang ,
8388 preprocessOptions,
8489 scoped : false
@@ -89,7 +94,7 @@ module.exports = function processStyle(stylePart, filename, config = {}) {
8994
9095 // post process
9196 if ( transformer . postprocess ) {
92- return transformer . postprocess ( content , filename , config , stylePart . attrs )
97+ return transformer . postprocess ( content , filePath , config , stylePart . attrs )
9398 }
9499
95100 return JSON . stringify ( extractClassMap ( content ) )
0 commit comments