catamphetamine / webpack-isomorphic-tools

Server-side rendering for your Webpack-built applications (e.g. React)
MIT License
1.25k stars 48 forks source link

How to test the component that use this tools? #93

Closed lewis617 closed 8 years ago

lewis617 commented 8 years ago

This tools is awesome, but how to test the component that use this tools?

catamphetamine commented 8 years ago

I don't understand your question. React components can be tested on Node.js because they're not coupled to a web browser.

lewis617 commented 8 years ago

I use mocha to run the test scripts.

catamphetamine commented 8 years ago

I don't understand what exactly are you asking.

lewis617 commented 8 years ago

When I run the Component, I use this file as the entry:

var Webpack_isomorphic_tools = require('webpack-isomorphic-tools')

// this must be equal to your Webpack configuration "context" parameter
var project_base_path = require('path').resolve(__dirname, '..')

// this global variable will be used later in express middleware
global.webpack_isomorphic_tools = new Webpack_isomorphic_tools(require('./webpack-isomorphic-tools-configuration'))
// enter development mode if needed 
// (you may also prefer to use a Webpack DefinePlugin variable)
.development(process.env.NODE_ENV === 'development')
// initializes a server-side instance of webpack-isomorphic-tools
// (the first parameter is the base path for your project
//  and is equal to the "context" parameter of you Webpack configuration)
// (if you prefer Promises over callbacks 
//  you can omit the callback parameter
//  and then it will return a Promise instead)
.server(project_base_path, function()
{
  // webpack-isomorphic-tools is all set now.
  // here goes all your web application code:
  // (it must reside in a separate *.js file 
  //  in order for the whole thing to work)
  require('./server')
})

but When I use mocha to test a component , where I put this file.

catamphetamine commented 8 years ago

Hmm, well, I guess you can put it in your runner.js, and replace require('./server') with

require('./tests/react/1')
require('./tests/react/2')
require('./tests/react/3')
...

Maybe something like this would work.

lewis617 commented 8 years ago

Thank you, it works.