11const path = require ( 'path' )
2- const fs = require ( 'fs' )
32const cssExtract = require ( 'extract-from-css' )
43const getVueJestConfig = require ( './utils' ) . getVueJestConfig
54const compileStyle = require ( '@vue/component-compiler-utils' ) . compileStyle
@@ -12,14 +11,23 @@ function getGlobalResources(resources, lang) {
1211 let globalResources = ''
1312 if ( resources && resources [ lang ] ) {
1413 globalResources = resources [ lang ]
15- . map ( resource => path . resolve ( process . cwd ( ) , resource ) )
16- . filter ( resourcePath => fs . existsSync ( resourcePath ) )
17- . map ( resourcePath => fs . readFileSync ( resourcePath ) . toString ( ) )
18- . join ( '\n' )
14+ . map ( resource => {
15+ const absolutePath = path . resolve ( process . cwd ( ) , resource )
16+ return `${ getImportLine ( lang , absolutePath ) } \n`
17+ } )
18+ . join ( '' )
1919 }
2020 return globalResources
2121}
2222
23+ function getImportLine ( lang , filePath ) {
24+ const importLines = {
25+ default : `@import "${ filePath } ";` ,
26+ sass : `@import "${ filePath } "`
27+ }
28+ return importLines [ lang ] || importLines . default
29+ }
30+
2331function extractClassMap ( cssCode ) {
2432 const cssNames = cssExtract . extractClasses ( cssCode )
2533 const cssMap = { }
@@ -32,6 +40,7 @@ function extractClassMap(cssCode) {
3240function getPreprocessOptions ( lang , filePath , jestConfig ) {
3341 if ( lang === 'scss' || lang === 'sass' ) {
3442 return {
43+ filename : filePath ,
3544 importer : ( url , prev , done ) => ( {
3645 file : applyModuleNameMapper (
3746 url ,
0 commit comments