| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | const packageJSON = require("../package.json"); | 
					
						
							|  |  |  | const MultiStats = require("../lib/MultiStats"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const createStat = overides => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 	return Object.assign({ | 
					
						
							|  |  |  | 		hash: "foo", | 
					
						
							|  |  |  | 		compilation: { | 
					
						
							|  |  |  | 			name: "bar" | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		hasErrors: () => false, | 
					
						
							|  |  |  | 		hasWarnings: () => false, | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 		toJson: () => Object.assign({ | 
					
						
							|  |  |  | 			hash: "foo", | 
					
						
							|  |  |  | 			version: "version", | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			warnings: [], | 
					
						
							|  |  |  | 			errors: [] | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 		}, overides) | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 	}, overides); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | describe("MultiStats", () => { | 
					
						
							|  |  |  | 	let packageVersion, stats, myMultiStats, result; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 	beforeEach(() => { | 
					
						
							|  |  |  | 		packageVersion = packageJSON.version; | 
					
						
							|  |  |  | 		packageJSON.version = "1.2.3"; | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 	afterEach(() => { | 
					
						
							|  |  |  | 		packageJSON.version = packageVersion; | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 	describe("created", () => { | 
					
						
							|  |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			stats = [ | 
					
						
							|  |  |  | 				createStat({ | 
					
						
							|  |  |  | 					hash: "abc123" | 
					
						
							|  |  |  | 				}), | 
					
						
							|  |  |  | 				createStat({ | 
					
						
							|  |  |  | 					hash: "xyz890" | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 			]; | 
					
						
							|  |  |  | 			myMultiStats = new MultiStats(stats); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 		it("creates a hash string", () => { | 
					
						
							|  |  |  | 			expect(myMultiStats.hash).toBe("abc123xyz890"); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 	describe("hasErrors", () => { | 
					
						
							|  |  |  | 		describe("when both have errors", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				stats = [ | 
					
						
							|  |  |  | 					createStat({ | 
					
						
							|  |  |  | 						hasErrors: () => true | 
					
						
							|  |  |  | 					}), | 
					
						
							|  |  |  | 					createStat({ | 
					
						
							|  |  |  | 						hasErrors: () => true | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 				]; | 
					
						
							|  |  |  | 				myMultiStats = new MultiStats(stats); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns true", () => { | 
					
						
							|  |  |  | 				expect(myMultiStats.hasErrors()).toBe(true); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 		describe("when one has an error", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				stats = [ | 
					
						
							|  |  |  | 					createStat({ | 
					
						
							|  |  |  | 						hasErrors: () => true | 
					
						
							|  |  |  | 					}), | 
					
						
							|  |  |  | 					createStat() | 
					
						
							|  |  |  | 				]; | 
					
						
							|  |  |  | 				myMultiStats = new MultiStats(stats); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns true", () => { | 
					
						
							|  |  |  | 				expect(myMultiStats.hasErrors()).toBe(true); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 		describe("when none have errors", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				stats = [ | 
					
						
							|  |  |  | 					createStat(), | 
					
						
							|  |  |  | 					createStat() | 
					
						
							|  |  |  | 				]; | 
					
						
							|  |  |  | 				myMultiStats = new MultiStats(stats); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns false", () => { | 
					
						
							|  |  |  | 				expect(myMultiStats.hasErrors()).toBe(false); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 	describe("hasWarnings", () => { | 
					
						
							|  |  |  | 		describe("when both have warnings", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				stats = [ | 
					
						
							|  |  |  | 					createStat({ | 
					
						
							|  |  |  | 						hasWarnings: () => true | 
					
						
							|  |  |  | 					}), | 
					
						
							|  |  |  | 					createStat({ | 
					
						
							|  |  |  | 						hasWarnings: () => true | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 				]; | 
					
						
							|  |  |  | 				myMultiStats = new MultiStats(stats); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns true", () => { | 
					
						
							|  |  |  | 				expect(myMultiStats.hasWarnings()).toBe(true); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 		describe("when one has a warning", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				stats = [ | 
					
						
							|  |  |  | 					createStat({ | 
					
						
							|  |  |  | 						hasWarnings: () => true | 
					
						
							|  |  |  | 					}), | 
					
						
							|  |  |  | 					createStat() | 
					
						
							|  |  |  | 				]; | 
					
						
							|  |  |  | 				myMultiStats = new MultiStats(stats); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns true", () => { | 
					
						
							|  |  |  | 				expect(myMultiStats.hasWarnings()).toBe(true); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 		describe("when none have warnings", () => { | 
					
						
							|  |  |  | 			beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				stats = [ | 
					
						
							|  |  |  | 					createStat(), | 
					
						
							|  |  |  | 					createStat() | 
					
						
							|  |  |  | 				]; | 
					
						
							|  |  |  | 				myMultiStats = new MultiStats(stats); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			it("returns false", () => { | 
					
						
							|  |  |  | 				expect(myMultiStats.hasWarnings()).toBe(false); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 	describe("toJson", () => { | 
					
						
							|  |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			stats = [ | 
					
						
							|  |  |  | 				createStat({ | 
					
						
							|  |  |  | 					hash: "abc123", | 
					
						
							|  |  |  | 					compilation: { | 
					
						
							|  |  |  | 						name: "abc123-compilation" | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					toJson: () => ({ | 
					
						
							|  |  |  | 						warnings: ["abc123-warning"], | 
					
						
							|  |  |  | 						errors: ["abc123-error"] | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 				}), | 
					
						
							|  |  |  | 				createStat({ | 
					
						
							|  |  |  | 					hash: "xyz890", | 
					
						
							|  |  |  | 					compilation: { | 
					
						
							|  |  |  | 						name: "xyz890-compilation" | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					toJson: () => ({ | 
					
						
							|  |  |  | 						warnings: ["xyz890-warning-1", "xyz890-warning-2"], | 
					
						
							|  |  |  | 						errors: [] | 
					
						
							|  |  |  | 					}) | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 			]; | 
					
						
							| 
									
										
										
										
											2017-03-05 05:04:35 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it("returns plain object representation", () => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			myMultiStats = new MultiStats(stats); | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 			result = myMultiStats.toJson({ | 
					
						
							|  |  |  | 				version: false, | 
					
						
							|  |  |  | 				hash: false | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			expect(result).toEqual({ | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				errors: [ | 
					
						
							|  |  |  | 					"(abc123-compilation) abc123-error" | 
					
						
							|  |  |  | 				], | 
					
						
							|  |  |  | 				warnings: [ | 
					
						
							|  |  |  | 					"(abc123-compilation) abc123-warning", | 
					
						
							|  |  |  | 					"(xyz890-compilation) xyz890-warning-1", | 
					
						
							|  |  |  | 					"(xyz890-compilation) xyz890-warning-2" | 
					
						
							|  |  |  | 				], | 
					
						
							|  |  |  | 				children: [{ | 
					
						
							|  |  |  | 						errors: [ | 
					
						
							|  |  |  | 							"abc123-error" | 
					
						
							|  |  |  | 						], | 
					
						
							|  |  |  | 						name: "abc123-compilation", | 
					
						
							|  |  |  | 						warnings: [ | 
					
						
							|  |  |  | 							"abc123-warning" | 
					
						
							|  |  |  | 						] | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						errors: [], | 
					
						
							|  |  |  | 						name: "xyz890-compilation", | 
					
						
							|  |  |  | 						warnings: [ | 
					
						
							|  |  |  | 							"xyz890-warning-1", | 
					
						
							|  |  |  | 							"xyz890-warning-2" | 
					
						
							|  |  |  | 						] | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				] | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-03-05 05:04:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it("returns plain object representation with json set to true", () => { | 
					
						
							|  |  |  | 			myMultiStats = new MultiStats(stats); | 
					
						
							|  |  |  | 			result = myMultiStats.toJson(true); | 
					
						
							| 
									
										
										
										
											2018-01-24 20:17:21 +08:00
										 |  |  | 			expect(result).toEqual({ | 
					
						
							| 
									
										
										
										
											2017-03-05 05:04:35 +08:00
										 |  |  | 				errors: [ | 
					
						
							|  |  |  | 					"(abc123-compilation) abc123-error" | 
					
						
							|  |  |  | 				], | 
					
						
							|  |  |  | 				warnings: [ | 
					
						
							|  |  |  | 					"(abc123-compilation) abc123-warning", | 
					
						
							|  |  |  | 					"(xyz890-compilation) xyz890-warning-1", | 
					
						
							|  |  |  | 					"(xyz890-compilation) xyz890-warning-2" | 
					
						
							|  |  |  | 				], | 
					
						
							|  |  |  | 				children: [{ | 
					
						
							|  |  |  | 						warnings: ["abc123-warning"], | 
					
						
							|  |  |  | 						errors: ["abc123-error"], | 
					
						
							|  |  |  | 						name: "abc123-compilation" | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						warnings: [ | 
					
						
							|  |  |  | 							"xyz890-warning-1", | 
					
						
							|  |  |  | 							"xyz890-warning-2" | 
					
						
							|  |  |  | 						], | 
					
						
							|  |  |  | 						errors: [], | 
					
						
							|  |  |  | 						name: "xyz890-compilation" | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				] | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 	describe("toString", () => { | 
					
						
							|  |  |  | 		beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			stats = [ | 
					
						
							|  |  |  | 				createStat({ | 
					
						
							|  |  |  | 					hash: "abc123", | 
					
						
							|  |  |  | 					compilation: { | 
					
						
							|  |  |  | 						name: "abc123-compilation" | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}), | 
					
						
							|  |  |  | 				createStat({ | 
					
						
							|  |  |  | 					hash: "xyz890", | 
					
						
							|  |  |  | 					compilation: { | 
					
						
							|  |  |  | 						name: "xyz890-compilation" | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}) | 
					
						
							|  |  |  | 			]; | 
					
						
							|  |  |  | 			myMultiStats = new MultiStats(stats); | 
					
						
							|  |  |  | 			result = myMultiStats.toString(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 06:31:03 +08:00
										 |  |  | 		it("returns string representation", () => { | 
					
						
							| 
									
										
										
										
											2018-01-27 05:51:03 +08:00
										 |  |  | 			expect(result).toEqual( | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				"Hash: abc123xyz890\n" + | 
					
						
							|  |  |  | 				"Version: webpack 1.2.3\n" + | 
					
						
							|  |  |  | 				"Child abc123-compilation:\n" + | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 				"    Hash: abc123\n" + | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 				"Child xyz890-compilation:\n" + | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 				"    Hash: xyz890" | 
					
						
							| 
									
										
										
										
											2017-01-07 14:56:47 +08:00
										 |  |  | 			); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }); |