| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | const path = require("path"); | 
					
						
							| 
									
										
										
										
											2019-06-11 19:09:42 +08:00
										 |  |  | const fs = require("graceful-fs"); | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | const vm = require("vm"); | 
					
						
							| 
									
										
										
										
											2017-11-21 17:41:01 +08:00
										 |  |  | const mkdirp = require("mkdirp"); | 
					
						
							| 
									
										
										
										
											2018-05-01 21:56:18 +08:00
										 |  |  | const rimraf = require("rimraf"); | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | const checkArrayExpectation = require("./checkArrayExpectation"); | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | const createLazyTestEnv = require("./helpers/createLazyTestEnv"); | 
					
						
							| 
									
										
										
										
											2018-04-11 04:52:22 +08:00
										 |  |  | const { remove } = require("./helpers/remove"); | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-09 21:26:35 +08:00
										 |  |  | const webpack = require(".."); | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-30 16:58:41 +08:00
										 |  |  | function copyDiff(src, dest, initial) { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 	if (!fs.existsSync(dest)) fs.mkdirSync(dest); | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | 	const files = fs.readdirSync(src); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 	files.forEach(filename => { | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | 		const srcFile = path.join(src, filename); | 
					
						
							|  |  |  | 		const destFile = path.join(dest, filename); | 
					
						
							|  |  |  | 		const directory = fs.statSync(srcFile).isDirectory(); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 		if (directory) { | 
					
						
							| 
									
										
										
										
											2018-04-30 16:58:41 +08:00
										 |  |  | 			copyDiff(srcFile, destFile, initial); | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-01-18 05:26:38 +08:00
										 |  |  | 			var content = fs.readFileSync(srcFile); | 
					
						
							| 
									
										
										
										
											2018-04-30 16:58:41 +08:00
										 |  |  | 			if (/^DELETE\s*$/.test(content.toString("utf-8"))) { | 
					
						
							| 
									
										
										
										
											2017-01-18 05:26:38 +08:00
										 |  |  | 				fs.unlinkSync(destFile); | 
					
						
							| 
									
										
										
										
											2018-04-30 16:58:41 +08:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				fs.writeFileSync(destFile, content); | 
					
						
							|  |  |  | 				if (initial) { | 
					
						
							|  |  |  | 					const longTimeAgo = Date.now() - 1000 * 60 * 60 * 24; | 
					
						
							|  |  |  | 					fs.utimesSync( | 
					
						
							|  |  |  | 						destFile, | 
					
						
							|  |  |  | 						Date.now() - longTimeAgo, | 
					
						
							|  |  |  | 						Date.now() - longTimeAgo | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | describe("WatchTestCases", () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 	if (process.env.NO_WATCH_TESTS) { | 
					
						
							| 
									
										
										
										
											2018-04-12 05:54:02 +08:00
										 |  |  | 		it.skip("long running tests excluded", () => {}); | 
					
						
							| 
									
										
										
										
											2017-12-20 23:53:56 +08:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | 	const casesPath = path.join(__dirname, "watchCases"); | 
					
						
							|  |  |  | 	let categories = fs.readdirSync(casesPath); | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 	categories = categories.map(cat => { | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		return { | 
					
						
							|  |  |  | 			name: cat, | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 			tests: fs | 
					
						
							|  |  |  | 				.readdirSync(path.join(casesPath, cat)) | 
					
						
							|  |  |  | 				.filter(folder => folder.indexOf("_") < 0) | 
					
						
							| 
									
										
										
										
											2018-05-02 15:31:22 +08:00
										 |  |  | 				.filter(testName => { | 
					
						
							|  |  |  | 					const testDirectory = path.join(casesPath, cat, testName); | 
					
						
							|  |  |  | 					const filterPath = path.join(testDirectory, "test.filter.js"); | 
					
						
							|  |  |  | 					if (fs.existsSync(filterPath) && !require(filterPath)()) { | 
					
						
							|  |  |  | 						describe.skip(testName, () => it("filtered")); | 
					
						
							|  |  |  | 						return false; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					return true; | 
					
						
							|  |  |  | 				}) | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 				.sort() | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2018-01-27 23:34:11 +08:00
										 |  |  | 	beforeAll(() => { | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | 		let dest = path.join(__dirname, "js"); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 		if (!fs.existsSync(dest)) fs.mkdirSync(dest); | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		dest = path.join(__dirname, "js", "watch-src"); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 		if (!fs.existsSync(dest)) fs.mkdirSync(dest); | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 	categories.forEach(category => { | 
					
						
							| 
									
										
										
										
											2018-01-31 04:03:23 +08:00
										 |  |  | 		beforeAll(() => { | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | 			const dest = path.join(__dirname, "js", "watch-src", category.name); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 			if (!fs.existsSync(dest)) fs.mkdirSync(dest); | 
					
						
							| 
									
										
										
										
											2017-11-15 21:08:11 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | 		describe(category.name, () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 			category.tests.forEach(testName => { | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | 				describe(testName, () => { | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 					const tempDirectory = path.join( | 
					
						
							|  |  |  | 						__dirname, | 
					
						
							|  |  |  | 						"js", | 
					
						
							|  |  |  | 						"watch-src", | 
					
						
							|  |  |  | 						category.name, | 
					
						
							| 
									
										
										
										
											2018-05-01 21:56:18 +08:00
										 |  |  | 						testName | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 					); | 
					
						
							| 
									
										
										
										
											2017-01-18 23:47:00 +08:00
										 |  |  | 					const testDirectory = path.join(casesPath, category.name, testName); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 					const runs = fs | 
					
						
							|  |  |  | 						.readdirSync(testDirectory) | 
					
						
							|  |  |  | 						.sort() | 
					
						
							|  |  |  | 						.filter(name => { | 
					
						
							|  |  |  | 							return fs.statSync(path.join(testDirectory, name)).isDirectory(); | 
					
						
							|  |  |  | 						}) | 
					
						
							|  |  |  | 						.map(name => ({ name })); | 
					
						
							| 
									
										
										
										
											2018-02-25 08:18:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 21:56:18 +08:00
										 |  |  | 					beforeAll(done => { | 
					
						
							|  |  |  | 						rimraf(tempDirectory, done); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2018-02-25 08:18:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 					it( | 
					
						
							|  |  |  | 						testName + " should compile", | 
					
						
							|  |  |  | 						done => { | 
					
						
							|  |  |  | 							const outputDirectory = path.join( | 
					
						
							|  |  |  | 								__dirname, | 
					
						
							|  |  |  | 								"js", | 
					
						
							|  |  |  | 								"watch", | 
					
						
							|  |  |  | 								category.name, | 
					
						
							|  |  |  | 								testName | 
					
						
							|  |  |  | 							); | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 							let options = {}; | 
					
						
							|  |  |  | 							const configPath = path.join(testDirectory, "webpack.config.js"); | 
					
						
							|  |  |  | 							if (fs.existsSync(configPath)) options = require(configPath); | 
					
						
							|  |  |  | 							const applyConfig = options => { | 
					
						
							|  |  |  | 								if (!options.mode) options.mode = "development"; | 
					
						
							|  |  |  | 								if (!options.context) options.context = tempDirectory; | 
					
						
							|  |  |  | 								if (!options.entry) options.entry = "./index.js"; | 
					
						
							|  |  |  | 								if (!options.target) options.target = "async-node"; | 
					
						
							|  |  |  | 								if (!options.output) options.output = {}; | 
					
						
							|  |  |  | 								if (!options.output.path) options.output.path = outputDirectory; | 
					
						
							|  |  |  | 								if (typeof options.output.pathinfo === "undefined") | 
					
						
							|  |  |  | 									options.output.pathinfo = true; | 
					
						
							|  |  |  | 								if (!options.output.filename) | 
					
						
							|  |  |  | 									options.output.filename = "bundle.js"; | 
					
						
							|  |  |  | 							}; | 
					
						
							|  |  |  | 							if (Array.isArray(options)) { | 
					
						
							|  |  |  | 								options.forEach(applyConfig); | 
					
						
							|  |  |  | 							} else { | 
					
						
							|  |  |  | 								applyConfig(options); | 
					
						
							|  |  |  | 							} | 
					
						
							| 
									
										
										
										
											2018-01-13 06:50:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 							const state = {}; | 
					
						
							|  |  |  | 							let runIdx = 0; | 
					
						
							|  |  |  | 							let waitMode = false; | 
					
						
							|  |  |  | 							let run = runs[runIdx]; | 
					
						
							|  |  |  | 							let triggeringFilename; | 
					
						
							|  |  |  | 							let lastHash = ""; | 
					
						
							|  |  |  | 							const currentWatchStepModule = require("./helpers/currentWatchStep"); | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 							let compilationFinished = done; | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 							currentWatchStepModule.step = run.name; | 
					
						
							| 
									
										
										
										
											2018-04-30 23:45:33 +08:00
										 |  |  | 							copyDiff(path.join(testDirectory, run.name), tempDirectory, true); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 							setTimeout(() => { | 
					
						
							|  |  |  | 								const compiler = webpack(options); | 
					
						
							|  |  |  | 								compiler.hooks.invalid.tap( | 
					
						
							|  |  |  | 									"WatchTestCasesTest", | 
					
						
							|  |  |  | 									(filename, mtime) => { | 
					
						
							|  |  |  | 										triggeringFilename = filename; | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 								); | 
					
						
							|  |  |  | 								const watching = compiler.watch( | 
					
						
							|  |  |  | 									{ | 
					
						
							|  |  |  | 										aggregateTimeout: 1000 | 
					
						
							|  |  |  | 									}, | 
					
						
							|  |  |  | 									(err, stats) => { | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 										if (err) return compilationFinished(err); | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 										if (!stats) | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 											return compilationFinished( | 
					
						
							|  |  |  | 												new Error("No stats reported from Compiler") | 
					
						
							|  |  |  | 											); | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 										if (stats.hash === lastHash) return; | 
					
						
							|  |  |  | 										lastHash = stats.hash; | 
					
						
							|  |  |  | 										if (run.done && lastHash !== stats.hash) { | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 											return compilationFinished( | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 												new Error( | 
					
						
							|  |  |  | 													"Compilation changed but no change was issued " + | 
					
						
							|  |  |  | 														lastHash + | 
					
						
							|  |  |  | 														" != " + | 
					
						
							|  |  |  | 														stats.hash + | 
					
						
							|  |  |  | 														" (run " + | 
					
						
							|  |  |  | 														runIdx + | 
					
						
							|  |  |  | 														")\n" + | 
					
						
							|  |  |  | 														"Triggering change: " + | 
					
						
							|  |  |  | 														triggeringFilename | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 												) | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 											); | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 										if (waitMode) return; | 
					
						
							|  |  |  | 										run.done = true; | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 										if (err) return compilationFinished(err); | 
					
						
							| 
									
										
										
										
											2018-12-19 01:29:12 +08:00
										 |  |  | 										const statOptions = { | 
					
						
							|  |  |  | 											preset: "verbose", | 
					
						
							|  |  |  | 											colors: false | 
					
						
							|  |  |  | 										}; | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 										mkdirp.sync(outputDirectory); | 
					
						
							|  |  |  | 										fs.writeFileSync( | 
					
						
							|  |  |  | 											path.join(outputDirectory, "stats.txt"), | 
					
						
							|  |  |  | 											stats.toString(statOptions), | 
					
						
							|  |  |  | 											"utf-8" | 
					
						
							|  |  |  | 										); | 
					
						
							|  |  |  | 										const jsonStats = stats.toJson({ | 
					
						
							|  |  |  | 											errorDetails: true | 
					
						
							|  |  |  | 										}); | 
					
						
							|  |  |  | 										if ( | 
					
						
							|  |  |  | 											checkArrayExpectation( | 
					
						
							|  |  |  | 												path.join(testDirectory, run.name), | 
					
						
							|  |  |  | 												jsonStats, | 
					
						
							|  |  |  | 												"error", | 
					
						
							|  |  |  | 												"Error", | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 												compilationFinished | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 											) | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 										) | 
					
						
							|  |  |  | 											return; | 
					
						
							|  |  |  | 										if ( | 
					
						
							|  |  |  | 											checkArrayExpectation( | 
					
						
							|  |  |  | 												path.join(testDirectory, run.name), | 
					
						
							|  |  |  | 												jsonStats, | 
					
						
							|  |  |  | 												"warning", | 
					
						
							|  |  |  | 												"Warning", | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 												compilationFinished | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 											) | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 										) | 
					
						
							|  |  |  | 											return; | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 										const globalContext = { | 
					
						
							|  |  |  | 											console: console, | 
					
						
							|  |  |  | 											expect: expect | 
					
						
							|  |  |  | 										}; | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 										function _require(currentDirectory, module) { | 
					
						
							|  |  |  | 											if (Array.isArray(module) || /^\.\.?\//.test(module)) { | 
					
						
							|  |  |  | 												let fn; | 
					
						
							|  |  |  | 												let content; | 
					
						
							|  |  |  | 												let p; | 
					
						
							|  |  |  | 												if (Array.isArray(module)) { | 
					
						
							|  |  |  | 													p = path.join(currentDirectory, module[0]); | 
					
						
							|  |  |  | 													content = module | 
					
						
							|  |  |  | 														.map(arg => { | 
					
						
							|  |  |  | 															p = path.join(currentDirectory, arg); | 
					
						
							|  |  |  | 															return fs.readFileSync(p, "utf-8"); | 
					
						
							|  |  |  | 														}) | 
					
						
							|  |  |  | 														.join("\n"); | 
					
						
							|  |  |  | 												} else { | 
					
						
							|  |  |  | 													p = path.join(currentDirectory, module); | 
					
						
							|  |  |  | 													content = fs.readFileSync(p, "utf-8"); | 
					
						
							|  |  |  | 												} | 
					
						
							|  |  |  | 												if ( | 
					
						
							|  |  |  | 													options.target === "web" || | 
					
						
							|  |  |  | 													options.target === "webworker" | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 												) { | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 													fn = vm.runInNewContext( | 
					
						
							|  |  |  | 														"(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE, expect, window) {" + | 
					
						
							| 
									
										
										
										
											2018-07-10 18:18:34 +08:00
										 |  |  | 															'function nsObj(m) { Object.defineProperty(m, Symbol.toStringTag, { value: "Module" }); return m; }' + | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 															content + | 
					
						
							|  |  |  | 															"\n})", | 
					
						
							|  |  |  | 														globalContext, | 
					
						
							|  |  |  | 														p | 
					
						
							|  |  |  | 													); | 
					
						
							|  |  |  | 												} else { | 
					
						
							|  |  |  | 													fn = vm.runInThisContext( | 
					
						
							|  |  |  | 														"(function(require, module, exports, __dirname, __filename, it, WATCH_STEP, STATS_JSON, STATE, expect) {" + | 
					
						
							| 
									
										
										
										
											2018-03-07 07:16:19 +08:00
										 |  |  | 															"global.expect = expect;" + | 
					
						
							| 
									
										
										
										
											2018-07-10 18:18:34 +08:00
										 |  |  | 															'function nsObj(m) { Object.defineProperty(m, Symbol.toStringTag, { value: "Module" }); return m; }' + | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 															content + | 
					
						
							|  |  |  | 															"\n})", | 
					
						
							|  |  |  | 														p | 
					
						
							|  |  |  | 													); | 
					
						
							|  |  |  | 												} | 
					
						
							|  |  |  | 												const m = { | 
					
						
							|  |  |  | 													exports: {} | 
					
						
							|  |  |  | 												}; | 
					
						
							|  |  |  | 												fn.call( | 
					
						
							|  |  |  | 													m.exports, | 
					
						
							|  |  |  | 													_require.bind(null, path.dirname(p)), | 
					
						
							|  |  |  | 													m, | 
					
						
							|  |  |  | 													m.exports, | 
					
						
							|  |  |  | 													path.dirname(p), | 
					
						
							|  |  |  | 													p, | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 													run.it, | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 													run.name, | 
					
						
							|  |  |  | 													jsonStats, | 
					
						
							|  |  |  | 													state, | 
					
						
							|  |  |  | 													expect, | 
					
						
							|  |  |  | 													globalContext | 
					
						
							|  |  |  | 												); | 
					
						
							|  |  |  | 												return module.exports; | 
					
						
							|  |  |  | 											} else if ( | 
					
						
							|  |  |  | 												testConfig.modules && | 
					
						
							|  |  |  | 												module in testConfig.modules | 
					
						
							|  |  |  | 											) { | 
					
						
							|  |  |  | 												return testConfig.modules[module]; | 
					
						
							|  |  |  | 											} else return require.requireActual(module); | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 										let testConfig = {}; | 
					
						
							|  |  |  | 										try { | 
					
						
							|  |  |  | 											// try to load a test file
 | 
					
						
							|  |  |  | 											testConfig = require(path.join( | 
					
						
							|  |  |  | 												testDirectory, | 
					
						
							|  |  |  | 												"test.config.js" | 
					
						
							|  |  |  | 											)); | 
					
						
							|  |  |  | 										} catch (e) { | 
					
						
							|  |  |  | 											// empty
 | 
					
						
							|  |  |  | 										} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 										if (testConfig.noTests) | 
					
						
							|  |  |  | 											return process.nextTick(compilationFinished); | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 										_require( | 
					
						
							|  |  |  | 											outputDirectory, | 
					
						
							|  |  |  | 											testConfig.bundlePath || "./bundle.js" | 
					
						
							|  |  |  | 										); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 										if (run.getNumberOfTests() < 1) | 
					
						
							|  |  |  | 											return compilationFinished( | 
					
						
							|  |  |  | 												new Error("No tests exported by test case") | 
					
						
							|  |  |  | 											); | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 										run.it("should compile the next step", done => { | 
					
						
							| 
									
										
										
										
											2018-05-01 21:56:18 +08:00
										 |  |  | 											runIdx++; | 
					
						
							|  |  |  | 											if (runIdx < runs.length) { | 
					
						
							|  |  |  | 												run = runs[runIdx]; | 
					
						
							|  |  |  | 												waitMode = true; | 
					
						
							|  |  |  | 												setTimeout(() => { | 
					
						
							|  |  |  | 													waitMode = false; | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 													compilationFinished = done; | 
					
						
							| 
									
										
										
										
											2018-05-01 21:56:18 +08:00
										 |  |  | 													currentWatchStepModule.step = run.name; | 
					
						
							|  |  |  | 													copyDiff( | 
					
						
							|  |  |  | 														path.join(testDirectory, run.name), | 
					
						
							|  |  |  | 														tempDirectory, | 
					
						
							|  |  |  | 														false | 
					
						
							|  |  |  | 													); | 
					
						
							|  |  |  | 												}, 1500); | 
					
						
							|  |  |  | 											} else { | 
					
						
							|  |  |  | 												watching.close(); | 
					
						
							| 
									
										
										
										
											2018-03-07 07:16:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 21:56:18 +08:00
										 |  |  | 												done(); | 
					
						
							|  |  |  | 											} | 
					
						
							|  |  |  | 										}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 										compilationFinished(); | 
					
						
							| 
									
										
										
										
											2018-03-06 05:48:18 +08:00
										 |  |  | 									} | 
					
						
							|  |  |  | 								); | 
					
						
							|  |  |  | 							}, 300); | 
					
						
							|  |  |  | 						}, | 
					
						
							| 
									
										
										
										
											2018-02-25 18:46:17 +08:00
										 |  |  | 						45000 | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2018-02-25 08:18:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-02 22:58:41 +08:00
										 |  |  | 					for (const run of runs) { | 
					
						
							|  |  |  | 						const { it: _it, getNumberOfTests } = createLazyTestEnv( | 
					
						
							|  |  |  | 							jasmine.getEnv(), | 
					
						
							|  |  |  | 							10000, | 
					
						
							|  |  |  | 							run.name | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 						run.it = _it; | 
					
						
							|  |  |  | 						run.getNumberOfTests = getNumberOfTests; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 08:18:51 +08:00
										 |  |  | 					afterAll(() => { | 
					
						
							|  |  |  | 						remove(tempDirectory); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); |