| 
									
										
										
										
											2013-12-03 20:01:03 +08:00
										 |  |  | var should = require("should"); | 
					
						
							|  |  |  | var path = require("path"); | 
					
						
							|  |  |  | var fs = require("fs"); | 
					
						
							|  |  |  | var webpack = require("../"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe("Examples", function() { | 
					
						
							|  |  |  | 	var examples = fs.readdirSync(path.join(__dirname, "..", "examples")).map(function(name) { | 
					
						
							|  |  |  | 		return path.join(__dirname, "..", "examples", name); | 
					
						
							|  |  |  | 	}).filter(function(p) { | 
					
						
							|  |  |  | 		return fs.statSync(p).isDirectory(); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	examples.forEach(function(examplePath) { | 
					
						
							|  |  |  | 		it("should compile " + path.basename(examplePath), function(done) { | 
					
						
							|  |  |  | 			var options = {}; | 
					
						
							| 
									
										
										
										
											2014-06-03 03:26:57 +08:00
										 |  |  | 			var webpackConfigPath = path.join(examplePath, "webpack.config.js"); | 
					
						
							|  |  |  | 			webpackConfigPath = webpackConfigPath.substr(0, 1).toUpperCase() + webpackConfigPath.substr(1); | 
					
						
							|  |  |  | 			if(fs.existsSync(webpackConfigPath)) | 
					
						
							|  |  |  | 				options = require(webpackConfigPath); | 
					
						
							| 
									
										
										
										
											2013-12-03 20:01:03 +08:00
										 |  |  | 			options.context = examplePath; | 
					
						
							|  |  |  | 			options.optimize = options.optimize || {}; | 
					
						
							|  |  |  | 			options.output = options.output || {}; | 
					
						
							|  |  |  | 			options.optimize.occurenceOrder = true; | 
					
						
							|  |  |  | 			options.output.pathInfo = true; | 
					
						
							| 
									
										
										
										
											2013-12-20 06:36:26 +08:00
										 |  |  | 			options.output.path = path.join(examplePath, "js"); | 
					
						
							|  |  |  | 			options.output.publicPath = "js/"; | 
					
						
							| 
									
										
										
										
											2013-12-03 20:01:03 +08:00
										 |  |  | 			if(!options.output.filename) | 
					
						
							|  |  |  | 				options.output.filename = "output.js"; | 
					
						
							|  |  |  | 			if(!options.entry) | 
					
						
							|  |  |  | 				options.entry = "./example.js"; | 
					
						
							|  |  |  | 			webpack(options, function(err, stats) { | 
					
						
							|  |  |  | 				if(err) return done(err); | 
					
						
							|  |  |  | 				stats = stats.toJson(); | 
					
						
							|  |  |  | 				if(stats.errors.length > 0) | 
					
						
							|  |  |  | 					return done(stats.errors[0]); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); |