11const { compileStyle } = require ( '@vue/compiler-sfc' )
22const path = require ( 'path' )
3- const fs = require ( 'fs' )
43const cssTree = require ( 'css-tree' )
54const getVueJestConfig = require ( './utils' ) . getVueJestConfig
65const applyModuleNameMapper = require ( './module-name-mapper-helper' )
@@ -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 ast = cssTree . parse ( cssCode )
2533
@@ -35,6 +43,7 @@ function extractClassMap(cssCode) {
3543function getPreprocessOptions ( lang , filePath , jestConfig ) {
3644 if ( lang === 'scss' || lang === 'sass' ) {
3745 return {
46+ filename : filePath ,
3847 importer : ( url , prev ) => ( {
3948 file : applyModuleNameMapper (
4049 url ,
0 commit comments