6 changed files with 81 additions and 46 deletions
			
			
		| @ -0,0 +1,6 @@ | |||||
|  | const constants = { | ||||
|  | 	pass: 'pass', | ||||
|  | 	fail: 'fail', | ||||
|  | }; | ||||
|  | 
 | ||||
|  | module.exports = constants; | ||||
| @ -0,0 +1,3 @@ | |||||
|  | const _assertPromise = (bool, assertion) => bool ? Promise.resolve() : Promise.reject(assertion); | ||||
|  | 
 | ||||
|  | module.exports = _assertPromise; | ||||
| @ -0,0 +1,32 @@ | |||||
|  | const isEq = require('@codefeathers/iseq'); | ||||
|  | 
 | ||||
|  | const { liftPromise, stringify } = require('../../util/helpers'); | ||||
|  | const _assertPromise = require('./assertPromise'); | ||||
|  | 
 | ||||
|  | const expect = a => { | ||||
|  | 
 | ||||
|  | 	return ({ | ||||
|  | 		done : () => Promise.resolve(), | ||||
|  | 		equal : (b) => | ||||
|  | 			liftPromise( | ||||
|  | 				x => _assertPromise( | ||||
|  | 					x === b, | ||||
|  | 					`${a} is not equal to ${b}`), | ||||
|  | 				a), | ||||
|  | 		deepEqual : b => | ||||
|  | 			liftPromise( | ||||
|  | 				x => _assertPromise( | ||||
|  | 					isEq(x, b), | ||||
|  | 					`${stringify(a)} is not deeply equal to ${stringify(b)}`, | ||||
|  | 					a), | ||||
|  | 				a), | ||||
|  | 		isTrue : () => | ||||
|  | 			liftPromise( | ||||
|  | 				x => _assertPromise( | ||||
|  | 					x === true, | ||||
|  | 					`${a} is not true`), | ||||
|  | 				a), | ||||
|  | 	}); | ||||
|  | }; | ||||
|  | 
 | ||||
|  | module.exports = expect; | ||||
| @ -0,0 +1,11 @@ | |||||
|  | 'use strict'; | ||||
|  | 
 | ||||
|  | const { pass, fail } = require('../constants'); | ||||
|  | 
 | ||||
|  | const runTests = tests => Promise.all(tests.map(test => | ||||
|  | 	test.test() | ||||
|  | 	.then(() => ({ description: test.description, result: pass })) | ||||
|  | 	.catch(e => ({ description: test.description, result: fail, error: e })) | ||||
|  | )); | ||||
|  | 
 | ||||
|  | module.exports = runTests; | ||||
| @ -1,18 +1,13 @@ | |||||
| const Gunner = require('./gunner'); | const Gunner = require('./gunner'); | ||||
| const gunner = new Gunner(); | const gunner = new Gunner(); | ||||
| 
 | 
 | ||||
| gunner.test('should return okay', expect => expect(1).to.be(1)); | gunner.test('should automatically pass', expect => expect().done()); | ||||
| gunner.test('objects are equal', expect => expect({ a: 1 }).to.be.deepEqual({ a: 1 })); | gunner.test(`should be equal`, expect => expect(1).equal(1)); | ||||
| gunner.test('test should break', expect => expect({a : 1}).to.be.deepEqual({ a: 2 })); | gunner.test(`objects are deep equal`, expect => expect({ a: 1 }).deepEqual({ a: 1 })); | ||||
|  | gunner.test(`objects aren't deeply equal`, expect => expect({a : 1}).deepEqual({ a: 2 })); | ||||
| 
 | 
 | ||||
| const a = 1; | const a = 1; | ||||
| gunner.test('should be true', expect => expect(a === 1).to.be.true()); | gunner.test('expression should be true', expect => expect(a === 1).isTrue()); | ||||
|  | gunner.test('promise must reject', expect => expect(Promise.reject(new Error('no'))).equal('rejection')); | ||||
| 
 | 
 | ||||
| gunner.run().then(results => { | gunner.run(); | ||||
| 	const success = results.filter(r => r.result === 'pass'); |  | ||||
| 
 |  | ||||
| 	console.log(`\n${success.length} tests passed of ${results.length}\n`); |  | ||||
| 	results.forEach(r => { |  | ||||
| 		console.log(`${r.result === 'pass' ? '✅' : '❌'} :: ${r.description}${r.error ? `\n  ${JSON.stringify(r.error)}` : ''}`); |  | ||||
| 	}); |  | ||||
| }); |  | ||||
|  | |||||
					Loading…
					
					
				
		Reference in new issue