From be368f7a77c1be37f0f9f8db4f3f28b4a5699b80 Mon Sep 17 00:00:00 2001 From: Jeffrey Dean Morgan Date: Sun, 5 Apr 2015 19:51:45 -0400 Subject: [PATCH] Adding code coverage to unit tests Signed-off-by: Jeffrey Morgan --- .gitignore | 1 + .jshintrc | 2 +- README.md | 1 + package.json | 21 ++++++++++++++------- src/ContainerHome.react.js | 4 +++- src/ContainerStore.js | 9 ++++++++- src/ImageCard.react.js | 12 ++++++++++-- {__tests__ => src}/SetupStore-test.js | 13 ++++++------- {__tests__ => src}/Virtualbox-test.js | 7 +++---- 9 files changed, 47 insertions(+), 23 deletions(-) rename {__tests__ => src}/SetupStore-test.js (92%) rename {__tests__ => src}/Virtualbox-test.js (76%) diff --git a/.gitignore b/.gitignore index 7b9e66caf1..ca23db9e8a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build dist node_modules +coverage npm-debug.log # Signing Identity diff --git a/.jshintrc b/.jshintrc index 9240a3ae9f..daeaf45072 100644 --- a/.jshintrc +++ b/.jshintrc @@ -27,5 +27,5 @@ "jest": true, "pit": true }, - "predef": [ "-Promise" ] + "predef": [ "Promise" ] } diff --git a/README.md b/README.md index ce35ee50c7..9d8d3fe3b2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ [![CircleCI](https://img.shields.io/circleci/project/kitematic/kitematic.svg)](https://circleci.com/gh/kitematic/kitematic/tree/master) +[![Coverage Status](https://coveralls.io/repos/kitematic/kitematic/badge.svg)](https://coveralls.io/r/kitematic/kitematic) [![bitHound Score](https://app.bithound.io/kitematic/kitematic/badges/score.svg)](http://app.bithound.io/kitematic/kitematic) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/kitematic/kitematic?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) diff --git a/package.json b/package.json index bbb611d8c7..057aac3a84 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "bugs": "https://github.com/kitematic/kitematic/issues", "scripts": { "start": "gulp", - "test": "jest", + "test": "jest --coverage", "release": "gulp release", "release:beta": "gulp release --beta", "preinstall": "./util/deps", @@ -28,16 +28,21 @@ "jest": { "scriptPreprocessor": "/util/preprocessor.js", "setupEnvScriptFile": "/util/testenv.js", + "collectCoverage": true, + "testDirectoryName": "src", + "testPathIgnorePatterns": [ + "/node_modules/", + "^((?!-test).)*$" + ], "unmockedModulePathPatterns": [ + "stream", "tty", "net", "crypto", - "stream", + "/node_modules/.*JSONStream", "/node_modules/object-assign", "/node_modules/underscore", - "/node_modules/react", - "/node_modules/bluebird", - "/node_modules/babel" + "/node_modules/bluebird" ] }, "docker-version": "1.5.0", @@ -51,7 +56,8 @@ "async": "^0.9.0", "bluebird": "^2.9.12", "bugsnag-js": "^2.4.7", - "dockerode": "^2.0.7", + "coveralls": "^2.11.2", + "dockerode": "^2.1.1", "exec": "0.2.0", "jquery": "^2.1.3", "minimist": "^1.1.0", @@ -76,6 +82,7 @@ "gulp-cssmin": "^0.1.6", "gulp-download-atom-shell": "0.0.4", "gulp-if": "^1.2.5", + "gulp-insert": "^0.4.0", "gulp-less": "^3.0.1", "gulp-livereload": "^3.8.0", "gulp-plumber": "^0.6.6", @@ -83,7 +90,7 @@ "gulp-shell": "^0.3.0", "gulp-sourcemaps": "^1.5.0", "gulp-util": "^3.0.4", - "jest-cli": "^0.4.0", + "jest-cli": "kitematic/jest", "jsxhint": "^0.12.1", "react-tools": "^0.12.2", "run-sequence": "^1.0.2" diff --git a/src/ContainerHome.react.js b/src/ContainerHome.react.js index bb3c4655f1..530e1b2668 100644 --- a/src/ContainerHome.react.js +++ b/src/ContainerHome.react.js @@ -74,7 +74,9 @@ var ContainerHome = React.createClass({ if (this.props.error) { body = (
-

There was a problem connecting to the Docker Engine in the VirtualBox VM.
This could be caused because this Mac is currently connected to a VPN, blocking access to the VM. If the issue persists, please file a ticket on our GitHub repo.

+

An error occurred:

+

{this.props.error.statusCode} {this.props.error.reason} - {this.props.error.json}

+

If you feel that this error is invalid, please file a ticket on our GitHub repo.

); diff --git a/src/ContainerStore.js b/src/ContainerStore.js index b0cc3940df..109a022d19 100644 --- a/src/ContainerStore.js +++ b/src/ContainerStore.js @@ -56,6 +56,12 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), { var data = JSON.parse(str); console.log(data); + if (data.error) { + _error = data.error; + callback(data.error); + return; + } + if (data.status && (data.status === 'Pulling dependent layers' || data.status.indexOf('already being pulled by another client') !== -1)) { blockedCallback(); return; @@ -82,7 +88,8 @@ var ContainerStore = assign(Object.create(EventEmitter.prototype), { progressCallback(totalProgress); }); stream.on('end', function () { - callback(); + callback(_error); + _error = null; }); }); }); diff --git a/src/ImageCard.react.js b/src/ImageCard.react.js index db895f6e32..659d1407e6 100644 --- a/src/ImageCard.react.js +++ b/src/ImageCard.react.js @@ -31,11 +31,11 @@ var ImageCard = React.createClass({ handleTagOverlayClick: function (name) { var $tagOverlay = $(this.getDOMNode()).find('.tag-overlay'); $tagOverlay.fadeIn(300); - $.get('https://registry.hub.docker.com/v1/repositories/' + name + '/tags', function (result) { + $.get('https://registry.hub.docker.com/v1/repositories/' + name + '/tags', result => { this.setState({ tags: result }); - }.bind(this)); + }); }, handleCloseTagOverlay: function () { var $tagOverlay = $(this.getDOMNode()).find('.tag-overlay'); @@ -50,6 +50,14 @@ var ImageCard = React.createClass({ } util.exec(['open', $repoUri + this.props.image.name]); }, + componentDidMount: function() { + $.get('https://registry.hub.docker.com/v1/repositories/' + this.props.image.name + '/tags', result => { + this.setState({ + tags: result, + chosenTag: result[0].name + }); + }); + }, render: function () { var self = this; var name; diff --git a/__tests__/SetupStore-test.js b/src/SetupStore-test.js similarity index 92% rename from __tests__/SetupStore-test.js rename to src/SetupStore-test.js index 1410a883b0..42add6fd37 100644 --- a/__tests__/SetupStore-test.js +++ b/src/SetupStore-test.js @@ -1,10 +1,9 @@ -jest.dontMock('../src/SetupStore'); -var setupStore = require('../src/SetupStore'); -var virtualBox = require('../src/VirtualBox'); -var util = require('../src/Util'); -var machine = require('../src/DockerMachine'); -var setupUtil = require('../src/SetupUtil'); -var Promise = require('bluebird'); +jest.dontMock('./SetupStore'); +var setupStore = require('./SetupStore'); +var virtualBox = require('./VirtualBox'); +var util = require('./Util'); +var machine = require('./DockerMachine'); +var setupUtil = require('./SetupUtil'); describe('SetupStore', function () { describe('download step', function () { diff --git a/__tests__/Virtualbox-test.js b/src/Virtualbox-test.js similarity index 76% rename from __tests__/Virtualbox-test.js rename to src/Virtualbox-test.js index 1a8efa7aab..567210a08a 100644 --- a/__tests__/Virtualbox-test.js +++ b/src/Virtualbox-test.js @@ -1,7 +1,6 @@ -jest.dontMock('../src/VirtualBox'); -var virtualBox = require('../src/VirtualBox'); -var util = require('../src/Util'); -var Promise = require('bluebird'); +jest.dontMock('./VirtualBox'); +var virtualBox = require('./VirtualBox'); +var util = require('./Util'); describe('VirtualBox', function () { it('returns the right command', function () {