| 
									
										
										
										
											2021-01-06 11:23:15 -06:00
										 |  |  | // Copyright 2021 Signal Messenger, LLC
 | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 07:41:43 -08:00
										 |  |  | /* eslint-disable no-console */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-28 12:11:19 -07:00
										 |  |  | const chai = require('chai'); | 
					
						
							|  |  |  | const chaiAsPromised = require('chai-as-promised'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 12:01:34 -08:00
										 |  |  | const ByteBuffer = require('../components/bytebuffer/dist/ByteBufferAB.js'); | 
					
						
							| 
									
										
										
										
											2021-04-09 09:19:38 -07:00
										 |  |  | const Long = require('../components/long/dist/Long.js'); | 
					
						
							| 
									
										
										
										
											2021-02-04 13:54:03 -06:00
										 |  |  | const { setEnvironment, Environment } = require('../ts/environment'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-28 12:11:19 -07:00
										 |  |  | chai.use(chaiAsPromised); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-05 13:44:02 -07:00
										 |  |  | setEnvironment(Environment.Test); | 
					
						
							| 
									
										
										
										
											2021-02-04 13:54:03 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-28 12:11:19 -07:00
										 |  |  | const storageMap = new Map(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 07:41:43 -08:00
										 |  |  | // To replicate logic we have on the client side
 | 
					
						
							|  |  |  | global.window = { | 
					
						
							|  |  |  |   log: { | 
					
						
							|  |  |  |     info: (...args) => console.log(...args), | 
					
						
							|  |  |  |     warn: (...args) => console.warn(...args), | 
					
						
							|  |  |  |     error: (...args) => console.error(...args), | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   i18n: key => `i18n(${key})`, | 
					
						
							| 
									
										
										
										
											2021-03-04 12:01:34 -08:00
										 |  |  |   dcodeIO: { | 
					
						
							|  |  |  |     ByteBuffer, | 
					
						
							| 
									
										
										
										
											2021-04-09 09:19:38 -07:00
										 |  |  |     Long, | 
					
						
							| 
									
										
										
										
											2021-03-04 12:01:34 -08:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-05-28 12:11:19 -07:00
										 |  |  |   storage: { | 
					
						
							|  |  |  |     get: key => storageMap.get(key), | 
					
						
							|  |  |  |     put: async (key, value) => storageMap.set(key, value), | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2021-01-06 07:41:43 -08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // For ducks/network.getEmptyState()
 | 
					
						
							|  |  |  | global.navigator = {}; | 
					
						
							|  |  |  | global.WebSocket = {}; |