Skip to content

Commit

Permalink
Merge pull request #2 from holidaycheck/switch-to-ava
Browse files Browse the repository at this point in the history
Switch from jest to ava and sinon
  • Loading branch information
HeeL authored Feb 23, 2018
2 parents 34f70ef + 5adebfa commit f009950
Show file tree
Hide file tree
Showing 8 changed files with 2,009 additions and 2,185 deletions.
10 changes: 2 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ module.exports = {
"extends": [ "airbnb-base", "plugin:ramda/recommended" ],
"rules": {
"comma-dangle": 0,
"arrow-parens": 0,
"indent": ["error", 4]
},
"plugins": [
"ramda"
],
"globals": {
"it": true,
"describe": true,
"jest": true,
"expect": true,
"afterEach": true
}
]
};
3,816 changes: 1,827 additions & 1,989 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@
"scripts": {
"start": "probot run ./index.js",
"dev:start": "nodemon --exec 'npm start'",
"test": "jest",
"test:watch": "jest . --watch",
"test": "ava",
"test:watch": "ava --watch",
"pretest": "npm run lint",
"lint": "eslint ."
},
"jest": {
"testRegex": "/test/unit/.*Spec.js$",
"setupTestFrameworkScriptFile": "<rootDir>/test/unit/setup.js"
},
"dependencies": {
"probot": "^5.0.0",
"ramda": "^0.25.0"
},
"devDependencies": {
"ava": "^1.0.0-beta.3",
"eslint": "^4.17.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-ramda": "^2.4.0",
"jest": "^21.2.1",
"nodemon": "^1.14.12",
"sinon": "^4.3.0",
"smee-client": "^1.0.1"
},
"engines": {
Expand Down
19 changes: 9 additions & 10 deletions test/unit/indexSpec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const index = require('../../index');
import test from 'ava';
import sinon from 'sinon';
import index from '../../index';

describe('index', () => {
it('handles issue labels events', () => {
const expectedEvents = ['issues.labeled', 'issues.unlabeled', 'issues.opened'];
const robot = { on: jest.fn() };
index(robot);
test('handles issue labels events', t => {
const expectedEvents = ['issues.labeled', 'issues.unlabeled', 'issues.opened'];
const robot = { on: sinon.spy() };
index(robot);

expect(robot.on).toHaveBeenCalledTimes(1);
const firstArgument = robot.on.mock.calls[0][0];
expect(firstArgument).toEqual(expectedEvents);
});
t.is(robot.on.callCount, 1);
t.deepEqual(robot.on.firstCall.args[0], expectedEvents);
});
3 changes: 0 additions & 3 deletions test/unit/setup.js

This file was deleted.

56 changes: 28 additions & 28 deletions test/unit/src/addLabelSpec.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
const addLabel = require('../../../src/addLabel');
import test from 'ava';
import sinon from 'sinon';
import addLabel from '../../../src/addLabel';

describe('addLabel', () => {
const issueNumber = 123;
const owner = 'foo bar owner';
const repo = 'foobaria repo';
const labelName = 'some labelzzz';
const issueNumber = 123;
const owner = 'foo bar owner';
const repo = 'foobaria repo';
const labelName = 'some labelzzz';

const createContext = (addLabels) => {
const issue = { number: issueNumber };
const repository = {
name: repo,
owner: { login: owner }
};
const createContext = (addLabels) => {
const issue = { number: issueNumber };
const repository = {
name: repo,
owner: { login: owner }
};

return {
payload: { issue, repository },
github: { issues: { addLabels } }
};
return {
payload: { issue, repository },
github: { issues: { addLabels } }
};
};

it('calls addLabel with correct issue object', () => {
const addLabelsStub = jest.fn();
const context = createContext(addLabelsStub);
addLabel(context, labelName);
test('calls addLabel with correct issue object', t => {
const addLabelsStub = sinon.stub();
const context = createContext(addLabelsStub);
addLabel(context, labelName);

expect(addLabelsStub).toHaveBeenCalledTimes(1);
expect(addLabelsStub).toHaveBeenCalledWith({
number: issueNumber,
labels: [labelName],
owner,
repo
});
});
t.is(addLabelsStub.callCount, 1);
t.true(addLabelsStub.calledWith({
number: issueNumber,
labels: [labelName],
owner,
repo
}));
});
83 changes: 41 additions & 42 deletions test/unit/src/calculatePrioritySpec.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
const calculatePriority = require('../../../src/calculatePriority');

describe('calculatePriority', () => {
it('calculate priority based on effort, potential and weight', () => {
const metrics = {
effort: 0.3,
potential: 0.9,
weight: 0.2
};

expect(calculatePriority(metrics)).toEqual('2.7');
});

it('rounds calculated priority', () => {
const metrics = {
effort: 0.1,
potential: 0.2,
weight: 0.3
};

expect(calculatePriority(metrics)).toEqual('1.6');
});

it('calculates max priority', () => {
const metrics = {
effort: 0.1,
potential: 1,
weight: 1
};

expect(calculatePriority(metrics)).toEqual('3.9');
});

it('calculates min priority', () => {
const metrics = {
effort: 1.0,
potential: 0.1,
weight: 0.1
};

expect(calculatePriority(metrics)).toEqual('0.3');
});
import test from 'ava';
import calculatePriority from '../../../src/calculatePriority';

test('calculates priority based on effort, potential and weight', t => {
const metrics = {
effort: 0.3,
potential: 0.9,
weight: 0.2
};

t.is(calculatePriority(metrics), '2.7');
});

test('rounds calculated priority', t => {
const metrics = {
effort: 0.1,
potential: 0.2,
weight: 0.3
};

t.is(calculatePriority(metrics), '1.6');
});

test('calculates max priority', t => {
const metrics = {
effort: 0.1,
potential: 1,
weight: 1
};

t.is(calculatePriority(metrics), '3.9');
});

test('calculates min priority', t => {
const metrics = {
effort: 1.0,
potential: 0.1,
weight: 0.1
};

t.is(calculatePriority(metrics), '0.3');
});
Loading

0 comments on commit f009950

Please sign in to comment.