Commit f35f233b authored by Evan You's avatar Evan You

test: ssr + css modules

parent 542aacca
...@@ -42,7 +42,7 @@ module.exports = function genStyleInjectionCode ( ...@@ -42,7 +42,7 @@ module.exports = function genStyleInjectionCode (
const name = JSON.stringify(moduleName) const name = JSON.stringify(moduleName)
if (!needsHotReload) { if (!needsHotReload) {
styleInjectionCode += `this[${name}] = ${locals}` styleInjectionCode += `this[${name}] = ${locals}\n`
} else { } else {
styleInjectionCode += ` styleInjectionCode += `
cssModules[${name}] = ${locals} cssModules[${name}] = ${locals}
......
...@@ -2,7 +2,9 @@ const SSR = require('vue-server-renderer') ...@@ -2,7 +2,9 @@ const SSR = require('vue-server-renderer')
const { const {
genId, genId,
bundle bundle,
baseConfig,
interopDefault
} = require('./utils') } = require('./utils')
test('SSR style and moduleId extraction', done => { test('SSR style and moduleId extraction', done => {
...@@ -96,29 +98,53 @@ test('SSR with scoped CSS', done => { ...@@ -96,29 +98,53 @@ test('SSR with scoped CSS', done => {
}) })
}) })
// TODO test('SSR + CSS Modules', done => {
// test('css-modules in SSR', done => { const baseLoaders = [
// bundle({ 'vue-style-loader',
// entry: 'css-modules.vue', {
// target: 'node', loader: 'css-loader',
// output: Object.assign({}, globalConfig.output, { options: { modules: true }
// libraryTarget: 'commonjs2' }
// }) ]
// }, (code, warnings) => {
// // http://stackoverflow.com/questions/17581830/load-node-js-module-from-string-in-memory
// function requireFromString (src, filename) {
// const Module = module.constructor
// const m = new Module()
// m._compile(src, filename)
// return m.exports
// }
// const output = interopDefault(requireFromString(code, './test.build.js')) bundle({
// const mockInstance = {} entry: 'css-modules.vue',
target: 'node',
output: Object.assign({}, baseConfig.output, {
libraryTarget: 'commonjs2'
}),
modify: config => {
config.module.rules = [
{ test: /\.vue$/, loader: 'vue-loader' },
{
test: /\.css$/,
use: baseLoaders
},
{
test: /\.stylus$/,
use: [
...baseLoaders,
'stylus-loader'
]
}
]
}
}, code => {
// http://stackoverflow.com/questions/17581830/load-node-js-module-from-string-in-memory
function requireFromString (src, filename) {
const Module = require('module')
const m = new Module()
m._compile(src, filename)
return m.exports
}
const output = interopDefault(requireFromString(code, './test.build.js'))
const mockInstance = {}
// output.beforeCreate.forEach(hook => hook.call(mockInstance)) output.beforeCreate.forEach(hook => hook.call(mockInstance))
// expect(mockInstance.style.red).toBeDefined() expect(mockInstance.style.red).toBeDefined()
expect(mockInstance.$style.red).toBeDefined()
// done() done()
// }) })
// }) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment