| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -3,7 +3,7 @@ const { log } = console; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					const _runTests = require('./lib/runTests'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					const _expect = require('./lib/expect'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					const { stringify } = require('../util/helpers'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					const { stringify, hasProp } = require('../util/helpers'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					class Gunner { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -14,32 +14,39 @@ class Gunner { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						test (description, test) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							this.tests.push({ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								description, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								test: () => test(_expect), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								test: () => { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									try { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										return test(_expect); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} catch (e) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										// If errors are thrown, reject them
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										return Promise.reject(e); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								}, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							}); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
						run (options = {}) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							process.stdout.write(`Running ${this.tests.length} tests...`); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							const shouldLog = (hasProp(options)('log') && options.log) || !(hasProp(options)('log')); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							if (shouldLog) process.stdout.write(`Running ${this.tests.length} tests...`); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							return _runTests(this.tests) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
							.then(results => { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								process.stdout.clearLine(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								process.stdout.cursorTo(0); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								const success = results.filter(r => r.result === 'pass'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								const successPercent = Math.floor(success.length/results.length * 100); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								if (('log' in options && options.log) || !('log' in options)) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								if (shouldLog) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									process.stdout.clearLine(); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									process.stdout.cursorTo(0); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									const success = results.filter(r => r.result === 'pass'); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									const successPercent = Math.floor(success.length/results.length * 100); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									log( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										`\n${success.length} tests passed of ${results.length}`, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										`[${successPercent}% success]\n` | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									results.forEach(r => { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										const trace = (options.trace && r.error) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											? `\n    Traceback:\n    ${stringify(r.error)}` | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											: ''; | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
										log(`${r.result === 'pass' ? '✅' : '❌'} ::`, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											`${r.description}`, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											`${options.stack ? | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												r.error | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													? `\n    Traceback:\n    ${stringify(r.error)}` | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
													: '' | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
												: ''}`);
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
											`${trace}`); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
									}); | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
								} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
				
				 | 
				
					
  |