| 
									
										
										
										
											2022-01-07 15:58:30 +01:00
										 |  |  | import o from "ospec" | 
					
						
							| 
									
										
										
										
											2022-05-12 16:51:15 +02:00
										 |  |  | import {LOG_SIZE, Logger} from "../../../../../src/api/common/Logger.js" | 
					
						
							| 
									
										
										
										
											2022-01-07 15:58:30 +01:00
										 |  |  | import {lastThrow} from "@tutao/tutanota-utils" | 
					
						
							|  |  |  | o.spec("Loger test", function () { | 
					
						
							|  |  |  |     let dateProvider | 
					
						
							|  |  |  |     let log | 
					
						
							|  |  |  |     o.beforeEach(function () { | 
					
						
							|  |  |  |         let dateCounter = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         dateProvider = () => new Date(dateCounter++) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         log = new Logger(dateProvider) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     o("log warn info error", function () { | 
					
						
							|  |  |  |         o(log.getEntries()).deepEquals([]) | 
					
						
							|  |  |  |         log.logInfo("info") | 
					
						
							|  |  |  |         log.logWarn("warn") | 
					
						
							|  |  |  |         log.logError("error") | 
					
						
							|  |  |  |         o(log.getEntries()).deepEquals([ | 
					
						
							|  |  |  |             log.formatLogEntry(new Date(0), "I", "info"), | 
					
						
							|  |  |  |             log.formatLogEntry(new Date(1), "W", "warn"), | 
					
						
							|  |  |  |             log.formatLogEntry(new Date(2), "E", "error"), | 
					
						
							|  |  |  |         ]) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     o("log lots of entries", function () { | 
					
						
							|  |  |  |         for (let i = 0; i < LOG_SIZE + 2; i++) { | 
					
						
							|  |  |  |             log.logInfo("info " + i) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         o(log.getEntries().length).equals(LOG_SIZE) | 
					
						
							|  |  |  |         o(log.getEntries()[0]).equals(log.formatLogEntry(new Date(2), "I", "info " + 2)) | 
					
						
							|  |  |  |         o(lastThrow(log.getEntries())).equals(log.formatLogEntry(new Date(1001), "I", "info " + 1001)) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | }) |