@@ -2,7 +2,9 @@ const SSR = require('vue-server-renderer')
22
33const {
44 genId,
5- bundle
5+ bundle,
6+ baseConfig,
7+ interopDefault
68} = require ( './utils' )
79
810test ( 'SSR style and moduleId extraction' , done => {
@@ -96,29 +98,53 @@ test('SSR with scoped CSS', done => {
9698 } )
9799} )
98100
99- // TODO
100- // test('css-modules in SSR', done => {
101- // bundle({
102- // entry: 'css-modules.vue',
103- // target: 'node',
104- // output: Object.assign({}, globalConfig.output, {
105- // libraryTarget: 'commonjs2'
106- // })
107- // }, (code, warnings) => {
108- // // http://stackoverflow.com/questions/17581830/load-node-js-module-from-string-in-memory
109- // function requireFromString (src, filename) {
110- // const Module = module.constructor
111- // const m = new Module()
112- // m._compile(src, filename)
113- // return m.exports
114- // }
101+ test ( 'SSR + CSS Modules' , done => {
102+ const baseLoaders = [
103+ 'vue-style-loader' ,
104+ {
105+ loader : 'css-loader' ,
106+ options : { modules : true }
107+ }
108+ ]
109+
110+ bundle ( {
111+ entry : 'css-modules.vue' ,
112+ target : 'node' ,
113+ output : Object . assign ( { } , baseConfig . output , {
114+ libraryTarget : 'commonjs2'
115+ } ) ,
116+ modify : config => {
117+ config . module . rules = [
118+ { test : / \. v u e $ / , loader : 'vue-loader' } ,
119+ {
120+ test : / \. c s s $ / ,
121+ use : baseLoaders
122+ } ,
123+ {
124+ test : / \. s t y l u s $ / ,
125+ use : [
126+ ...baseLoaders ,
127+ 'stylus-loader'
128+ ]
129+ }
130+ ]
131+ }
132+ } , code => {
133+ // http://stackoverflow.com/questions/17581830/load-node-js-module-from-string-in-memory
134+ function requireFromString ( src , filename ) {
135+ const Module = require ( 'module' )
136+ const m = new Module ( )
137+ m . _compile ( src , filename )
138+ return m . exports
139+ }
115140
116- // const output = interopDefault(requireFromString(code, './test.build.js'))
117- // const mockInstance = {}
141+ const output = interopDefault ( requireFromString ( code , './test.build.js' ) )
142+ const mockInstance = { }
118143
119- // output.beforeCreate.forEach(hook => hook.call(mockInstance))
120- // expect(mockInstance.style.red).toBeDefined()
144+ output . beforeCreate . forEach ( hook => hook . call ( mockInstance ) )
145+ expect ( mockInstance . style . red ) . toBeDefined ( )
146+ expect ( mockInstance . $style . red ) . toBeDefined ( )
121147
122- // done()
123- // })
124- // })
148+ done ( )
149+ } )
150+ } )
0 commit comments