Browse Source

[init] MVP --

0.7.0-breaking-rewrite
Muthu Kumar 6 years ago
commit
1151d95fd6
  1. 25
      .eslintrc.js
  2. 4
      .gitignore
  3. 53
      gunner/index.js
  4. 29
      package.json
  5. 18
      sample.test.js
  6. 4092
      shrinkwrap.yaml

25
.eslintrc.js

@ -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"} ],
}
};

4
.gitignore

@ -0,0 +1,4 @@
node_modules
config.js
testsuite
app

53
gunner/index.js

@ -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;

29
package.json

@ -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"
}
}

18
sample.test.js

@ -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)}` : ''}`);
});
});

4092
shrinkwrap.yaml

File diff suppressed because it is too large
Loading…
Cancel
Save