From 27da010e8a2c462c860f16a90594716844e1aef1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Wed, 19 Dec 2018 00:32:01 +0100 Subject: [PATCH] add tests using mocha and chai MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- package.json | 38 +++++++++++--------------------------- src/builds.js | 2 +- test/comments.js | 28 ++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 28 deletions(-) create mode 100644 test/comments.js diff --git a/package.json b/package.json index ee23b7b..8529c48 100644 --- a/package.json +++ b/package.json @@ -23,50 +23,34 @@ "@babel/plugin-transform-async-to-generator": "^7.1.0", "@babel/preset-env": "^7.1.0", "babel-core": "^7.0.0-bridge.0", + "chai": "^4.2.0", + "chai-as-promised": "^7.1.1", "gulp": "^3.9.1", "gulp-babel": "^8.0.0-beta.2", "gulp-clean": "^0.4.0", "gulp-nodemon": "^2.2.1", "gulp-print": "^5.0.0", - "jest": "^23.6.0", + "mocha": "^5.2.0", "nodemon": "^1.18.4", "sinon": "^7.1.1", "supertest": "^3.3.0" }, "scripts": { "start": "node server.js", - "test": "jest", - "testw": "jest --watchAll", + "test": "mocha --require @babel/register", + "testw": "mocha --require @babel/register --watch", "devel": "gulp devel", "clean": "gulp clean", "build": "gulp build", "image": "docker build -t statusteam/ghcmgr .", "push": "docker push statusteam/ghcmgr" }, - "jest": { - "moduleFileExtensions": [ - "js", - "json" - ], - "collectCoverage": true, - "collectCoverageFrom": [ - "src/**/*.js", - "!**/node_modules/**", - "!**/build/**", - "!**/coverage/**" - ], - "coverageReporters": [ - "text", - "text-summary" - ], - "testRegex": "/test/.*.js$", - "testPathIgnorePatterns": [ - "/node_modules/", - "/build/", - "/coverage/" - ] - }, - "keywords": [], + "keywords": [ + "github", + "comments", + "ci", + "builds" + ], "author": "", "license": "ISC" } diff --git a/src/builds.js b/src/builds.js index b4c94cb..de0566a 100644 --- a/src/builds.js +++ b/src/builds.js @@ -39,7 +39,7 @@ class Builds { async getBuilds (pr) { const builds = await this.builds.chain() .find({pr}) - .compoundsort(['$loki', 'platform', 'id']) + .compoundsort(['$loki', 'id']) .data() /* strip the $loki attribute */ return builds.map((b) => { diff --git a/test/comments.js b/test/comments.js new file mode 100644 index 0000000..0e1bf2e --- /dev/null +++ b/test/comments.js @@ -0,0 +1,28 @@ +import { expect } from 'chai' +import sinon from 'sinon' +import Octokit from '@octokit/rest' + +import Builds from '../src/builds' +import Comments from '../src/comments' + +let comments, client, builds + +describe('Comments', () => { + before(() => { + //client = sinon.createStubInstance(Octokit, {what: 2}) + builds = sinon.createStubInstance(Builds, { + getBuilds: [] + }) + comments = new Comments(client, 'owner', 'repo', builds) + }) + + describe('renderComment', () => { + it('should fail with no builds', async () => { + try { + await comments.renderComment('PR') + } catch(err) { + expect(err.message).to.eq('No builds exist for this PR') + } + }) + }) +})