| 
									
										
										
										
											2017-04-06 16:17:43 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | const fs = require("fs"); | 
					
						
							|  |  |  | const path = require("path"); | 
					
						
							| 
									
										
										
										
											2014-06-18 04:34:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | module.exports = function checkArrayExpectation(testDirectory, object, kind, filename, upperCaseKind, done) { | 
					
						
							|  |  |  | 	if(!done) { | 
					
						
							|  |  |  | 		done = upperCaseKind; | 
					
						
							|  |  |  | 		upperCaseKind = filename; | 
					
						
							| 
									
										
										
										
											2017-04-06 16:17:43 +08:00
										 |  |  | 		filename = `${kind}s`; | 
					
						
							| 
									
										
										
										
											2016-07-03 19:13:01 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-06 16:17:43 +08:00
										 |  |  | 	let array = object[`${kind}s`].slice().sort(); | 
					
						
							|  |  |  | 	if(kind === "warning") array = array.filter(item => !/from UglifyJs/.test(item)); | 
					
						
							|  |  |  | 	if(fs.existsSync(path.join(testDirectory, `${filename}.js`))) { | 
					
						
							|  |  |  | 		const expectedFilename = path.join(testDirectory, `${filename}.js`); | 
					
						
							|  |  |  | 		const expected = require(expectedFilename); | 
					
						
							| 
									
										
										
										
											2014-06-18 04:34:30 +08:00
										 |  |  | 		if(expected.length < array.length) | 
					
						
							| 
									
										
										
										
											2017-04-06 16:17:43 +08:00
										 |  |  | 			return done(new Error(`More ${kind}s while compiling than expected:\n\n${array.join("\n\n")}. Check expected warnings: ${filename}`)), true; | 
					
						
							| 
									
										
										
										
											2014-06-18 04:34:30 +08:00
										 |  |  | 		else if(expected.length > array.length) | 
					
						
							| 
									
										
										
										
											2017-04-06 16:17:43 +08:00
										 |  |  | 			return done(new Error(`Less ${kind}s while compiling than expected:\n\n${array.join("\n\n")}. Check expected warnings: ${filename}`)), true; | 
					
						
							|  |  |  | 		for(let i = 0; i < array.length; i++) { | 
					
						
							| 
									
										
										
										
											2014-06-18 04:34:30 +08:00
										 |  |  | 			if(Array.isArray(expected[i])) { | 
					
						
							| 
									
										
										
										
											2017-04-06 16:17:43 +08:00
										 |  |  | 				for(let j = 0; j < expected[i].length; j++) { | 
					
						
							| 
									
										
										
										
											2014-06-18 04:34:30 +08:00
										 |  |  | 					if(!expected[i][j].test(array[i])) | 
					
						
							| 
									
										
										
										
											2017-04-06 16:17:43 +08:00
										 |  |  | 						return done(new Error(`${upperCaseKind} ${i}: ${array[i]} doesn't match ${expected[i][j].toString()}`)), true; | 
					
						
							| 
									
										
										
										
											2014-06-18 04:34:30 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} else if(!expected[i].test(array[i])) | 
					
						
							| 
									
										
										
										
											2017-04-06 16:17:43 +08:00
										 |  |  | 				return done(new Error(`${upperCaseKind} ${i}: ${array[i]} doesn't match ${expected[i].toString()}`)), true; | 
					
						
							| 
									
										
										
										
											2014-06-18 04:34:30 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} else if(array.length > 0) { | 
					
						
							| 
									
										
										
										
											2017-04-06 16:17:43 +08:00
										 |  |  | 		return done(new Error(`${upperCaseKind}s while compiling:\n\n${array.join("\n\n")}`)), true; | 
					
						
							| 
									
										
										
										
											2014-06-18 04:34:30 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-11-15 21:08:11 +08:00
										 |  |  | }; |