Muthu Kumar
7 years ago
commit
1151d95fd6
6 changed files with 4221 additions and 0 deletions
@ -0,0 +1,25 @@ |
|||||
|
module.exports = { |
||||
|
"env": { |
||||
|
"commonjs": true, |
||||
|
"es6": true, |
||||
|
"node": true |
||||
|
}, |
||||
|
"extends": "eslint:recommended", |
||||
|
"rules": { |
||||
|
"no-nested-ternary": "warn", |
||||
|
"no-self-compare": "error", |
||||
|
"no-trailing-spaces": "error", |
||||
|
"no-unmodified-loop-condition": "error", |
||||
|
"no-unneeded-ternary": "error", |
||||
|
"no-console": "off", |
||||
|
"no-undef": "off", |
||||
|
"indent": [ |
||||
|
"error", |
||||
|
"tab", |
||||
|
{ MemberExpression: 0, } |
||||
|
], |
||||
|
"linebreak-style": [ "error", "unix" ], |
||||
|
"semi": [ "error", "always" ], |
||||
|
"eqeqeq": [ "error", "always", {"null": "ignore"} ], |
||||
|
} |
||||
|
}; |
@ -0,0 +1,4 @@ |
|||||
|
node_modules |
||||
|
config.js |
||||
|
testsuite |
||||
|
app |
@ -0,0 +1,53 @@ |
|||||
|
const isEq = require('@codefeathers/iseq'); |
||||
|
|
||||
|
const constants = { |
||||
|
pass: 'pass', |
||||
|
fail: 'fail', |
||||
|
}; |
||||
|
|
||||
|
const _assert = (bool, assertion) => bool ? Promise.resolve() : Promise.reject(assertion); |
||||
|
|
||||
|
const stringify = obj => |
||||
|
typeof obj === 'object' |
||||
|
? JSON.stringify(obj) |
||||
|
: obj; |
||||
|
|
||||
|
const be = a => { |
||||
|
const fn = b => _assert(a === b, `${a} is not equal to ${b}`); |
||||
|
fn.deepEqual = b => _assert(isEq(a, b), `${stringify(a)} is not deeply equal to ${stringify(b)}`); |
||||
|
fn.true = () => _assert(a === true, `${a} is not true`); |
||||
|
return fn; |
||||
|
}; |
||||
|
|
||||
|
const expect = thing => ({ |
||||
|
to: { |
||||
|
be: be(thing), |
||||
|
}, |
||||
|
}); |
||||
|
|
||||
|
const runTests = tests => tests.map(test => |
||||
|
test.test() |
||||
|
.then(() => ({ description: test.description, result: constants.pass })) |
||||
|
.catch(e => ({ description: test.description, result: constants.fail, error: e })) |
||||
|
); |
||||
|
|
||||
|
class Gunner { |
||||
|
|
||||
|
constructor () { |
||||
|
this.tests = []; |
||||
|
} |
||||
|
|
||||
|
test (description, test) { |
||||
|
this.tests.push({ |
||||
|
description, |
||||
|
test: () => test(expect), |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
run () { |
||||
|
return Promise.all(runTests(this.tests)); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
module.exports = Gunner; |
@ -0,0 +1,29 @@ |
|||||
|
{ |
||||
|
"name": "@klenty/gunner", |
||||
|
"version": "0.0.1", |
||||
|
"description": "Multi-strategy test runner.", |
||||
|
"main": "index.js", |
||||
|
"scripts": { |
||||
|
"test": "npm run start" |
||||
|
}, |
||||
|
"repository": { |
||||
|
"type": "git", |
||||
|
"url": "git+https://github.com/vengatkrishnaraj/gunner.git" |
||||
|
}, |
||||
|
"keywords": [ |
||||
|
"klenty", |
||||
|
"test", |
||||
|
"mocha" |
||||
|
], |
||||
|
"author": "Muthu Kumar <@MKRhere> (https://mkr.pw)", |
||||
|
"license": "ISC", |
||||
|
"bugs": { |
||||
|
"url": "https://github.com/vengatkrishnaraj/testsuite/issues" |
||||
|
}, |
||||
|
"homepage": "https://github.com/vengatkrishnaraj/testsuite#readme", |
||||
|
"dependencies": { |
||||
|
"@codefeathers/iseq": "^1.2.1", |
||||
|
"eslint": "^5.2.0", |
||||
|
"fs-extra": "^7.0.0" |
||||
|
} |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
const Gunner = require('./gunner'); |
||||
|
const gunner = new Gunner(); |
||||
|
|
||||
|
gunner.test('should return okay', expect => expect(1).to.be(1)); |
||||
|
gunner.test('objects are equal', expect => expect({ a: 1 }).to.be.deepEqual({ a: 1 })); |
||||
|
gunner.test('test should break', expect => expect({a : 1}).to.be.deepEqual({ a: 2 })); |
||||
|
|
||||
|
const a = 1; |
||||
|
gunner.test('should be true', expect => expect(a === 1).to.be.true()); |
||||
|
|
||||
|
gunner.run().then(results => { |
||||
|
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)}` : ''}`); |
||||
|
}); |
||||
|
}); |
File diff suppressed because it is too large
Loading…
Reference in new issue