diff --git a/.gitignore b/.gitignore index cd839233db..4316ad2eb7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,13 +8,12 @@ npm-debug.log identity # Resources -resources/boot2docker* +resources/boot2docker-* +resources/docker-* # Cache cache -resources/settings* - # Tests .test settings.json diff --git a/__tests__/SetupStore-test.js b/__tests__/SetupStore-test.js new file mode 100644 index 0000000000..bc44bb4bae --- /dev/null +++ b/__tests__/SetupStore-test.js @@ -0,0 +1,119 @@ +jest.dontMock('../src/SetupStore'); +var setupStore = require('../src/SetupStore'); +var virtualBox = require('../src/VirtualBox'); +var util = require('../src/Util'); +var boot2docker = require('../src/Boot2Docker'); +var setupUtil = require('../src/SetupUtil'); +var Promise = require('bluebird'); + +describe('SetupStore', function () { + describe('download step', function () { + util.packagejson.mockReturnValue({}); + pit('downloads virtualbox if it is not installed', function () { + virtualBox.installed.mockReturnValue(false); + setupUtil.download.mockReturnValue(Promise.resolve()); + return setupStore.steps().downloadVirtualBox.run().then(() => { + // TODO: make sure download was called with the right args + expect(setupUtil.download).toBeCalled(); + }); + }); + + pit('downloads virtualbox if it is installed but has an outdated version', function () { + virtualBox.installed.mockReturnValue(true); + virtualBox.version.mockReturnValue(Promise.resolve('4.3.16')); + setupUtil.compareVersions.mockReturnValue(-1); + setupUtil.download.mockReturnValue(Promise.resolve()); + return setupStore.steps().downloadVirtualBox.run().then(() => { + expect(setupUtil.download).toBeCalled(); + }); + }); + + pit('skips download if virtualbox is already installed', function () { + virtualBox.installed.mockReturnValue(true); + virtualBox.version.mockReturnValue(Promise.resolve('4.3.20')); + setupUtil.download.mockClear(); + setupUtil.download.mockReturnValue(Promise.resolve()); + setupUtil.compareVersions.mockReturnValue(1); + return setupStore.steps().downloadVirtualBox.run().then(() => { + expect(setupUtil.download).not.toBeCalled(); + }); + }); + }); + + describe('install step', function () { + pit('installs virtualbox if it is not installed', function () { + virtualBox.installed.mockReturnValue(false); + virtualBox.killall.mockReturnValue(Promise.resolve()); + setupUtil.isSudo.mockReturnValue(Promise.resolve(false)); + util.exec.mockReturnValue(Promise.resolve()); + return setupStore.steps().installVirtualBox.run().then(() => { + // TODO: make sure that the right install command was executed + expect(util.exec).toBeCalled(); + }); + }); + + pit('installs virtualbox if it is installed but has an outdated version', function () { + virtualBox.installed.mockReturnValue(true); + virtualBox.version.mockReturnValue(Promise.resolve('4.3.16')); + virtualBox.killall.mockReturnValue(Promise.resolve()); + setupUtil.isSudo.mockReturnValue(Promise.resolve(false)); + setupUtil.compareVersions.mockReturnValue(-1); + util.exec.mockReturnValue(Promise.resolve()); + return setupStore.steps().installVirtualBox.run().then(() => { + // TODO: make sure the right install command was executed + expect(virtualBox.killall).toBeCalled(); + expect(util.exec).toBeCalled(); + }); + }); + + pit('skips install if virtualbox is already installed', function () { + virtualBox.installed.mockReturnValue(true); + virtualBox.version.mockReturnValue(Promise.resolve('4.3.20')); + setupUtil.isSudo.mockReturnValue(Promise.resolve(false)); + setupUtil.compareVersions.mockReturnValue(-1); + util.exec.mockReturnValue(Promise.resolve()); + return setupStore.steps().installVirtualBox.run().then(() => { + virtualBox.killall.mockClear(); + util.exec.mockClear(); + expect(virtualBox.killall).not.toBeCalled(); + expect(util.exec).not.toBeCalled(); + }); + }); + }); + + describe('init step', function () { + virtualBox.vmdestroy.mockReturnValue(Promise.resolve()); + pit('inintializes the boot2docker vm if it does not exist', function () { + boot2docker.exists.mockReturnValue(Promise.resolve(false)); + boot2docker.init.mockReturnValue(Promise.resolve()); + return setupStore.steps().initBoot2Docker.run().then(() => { + expect(boot2docker.init).toBeCalled(); + }); + }); + + pit('upgrades the boot2docker vm if it exists and is out of date', function () { + boot2docker.exists.mockReturnValue(Promise.resolve(true)); + boot2docker.isoversion.mockReturnValue('1.0'); + boot2docker.haskeys.mockReturnValue(true); + boot2docker.stop.mockReturnValue(Promise.resolve()); + boot2docker.upgrade.mockReturnValue(Promise.resolve()); + setupUtil.compareVersions.mockReturnValue(-1); + return setupStore.steps().initBoot2Docker.run().then(() => { + boot2docker.init.mockClear(); + expect(boot2docker.init).not.toBeCalled(); + expect(boot2docker.upgrade).toBeCalled(); + }); + }); + }); + + describe('start step', function () { + pit('starts the boot2docker vm if it is not running', function () { + boot2docker.status.mockReturnValue(false); + boot2docker.waitstatus.mockReturnValue(Promise.resolve()); + boot2docker.start.mockReturnValue(Promise.resolve()); + return setupStore.steps().startBoot2Docker.run().then(() => { + expect(boot2docker.start).toBeCalled(); + }); + }); + }); +}); diff --git a/__tests__/Virtualbox-test.js b/__tests__/Virtualbox-test.js index e8f4a2fe72..1a8efa7aab 100644 --- a/__tests__/Virtualbox-test.js +++ b/__tests__/Virtualbox-test.js @@ -1,11 +1,11 @@ -jest.dontMock('../src/Virtualbox'); -var virtualbox = require('../src/Virtualbox'); +jest.dontMock('../src/VirtualBox'); +var virtualBox = require('../src/VirtualBox'); var util = require('../src/Util'); var Promise = require('bluebird'); -describe('Virtualbox', function () { +describe('VirtualBox', function () { it('returns the right command', function () { - expect(virtualbox.command()).toBe('/usr/bin/VBoxManage'); + expect(virtualBox.command()).toBe('/usr/bin/VBoxManage'); }); describe('version 4.3.20r96996', function () { @@ -13,7 +13,7 @@ describe('Virtualbox', function () { util.exec.mockImplementation(function () { return Promise.resolve('4.3.20r96996'); }); - return virtualbox.version().then(function (version) { + return virtualBox.version().then(function (version) { expect(version).toBe('4.3.20'); }); }); diff --git a/browser/main.js b/browser/main.js index 4ecb4688c8..1a3a6a4852 100644 --- a/browser/main.js +++ b/browser/main.js @@ -6,7 +6,12 @@ var autoUpdater = require('auto-updater'); var BrowserWindow = require('browser-window'); var ipc = require('ipc'); var argv = require('minimist')(process.argv); -var settingsjson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'settings.json'), 'utf8')); +var settingsjson; +try { + settingsjson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'settings.json'), 'utf8')); +} catch (err) { + settingsjson = {}; +} process.env.NODE_PATH = __dirname + '/../node_modules'; process.env.RESOURCES_PATH = __dirname + '/../resources'; @@ -65,7 +70,7 @@ app.on('ready', function() { // Auto Updates if (process.env.NODE_ENV !== 'development' && !argv.test) { - autoUpdater.setFeedUrl('https://updates.kitematic.com/releases/latest?version=' + app.getVersion() + '&beta=' + settingsjson.beta); + autoUpdater.setFeedUrl('https://updates.kitematic.com/releases/latest?version=' + app.getVersion() + '&beta=' + !!settingsjson.beta); autoUpdater.on('checking-for-update', function () { console.log('Checking for update...'); diff --git a/deps b/deps index 7e1cbc3cc2..9f44db32c3 100755 --- a/deps +++ b/deps @@ -2,14 +2,26 @@ BASE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" BOOT2DOCKER_CLI_VERSION=$(node -pe "JSON.parse(process.argv[1])['boot2docker-version']" "$(cat $BASE/package.json)") BOOT2DOCKER_CLI_FILE=boot2docker-$BOOT2DOCKER_CLI_VERSION +DOCKER_CLI_VERSION=$(node -pe "JSON.parse(process.argv[1])['docker-version']" "$(cat $BASE/package.json)") +DOCKER_CLI_FILE=docker-$DOCKER_CLI_VERSION pushd $BASE/resources > /dev/null if [ ! -f $BOOT2DOCKER_CLI_FILE ]; then echo "-----> Downloading Boot2docker CLI..." rm -rf boot2docker-* - curl -L -o $BOOT2DOCKER_CLI_FILE https://github.com/boot2docker/boot2docker-cli/releases/download/v${BOOT2DOCKER_CLI_VERSION}/boot2docker-v${BOOT2DOCKER_CLI_VERSION}-darwin-amd64 + curl -L -o $BOOT2DOCKER_CLI_FILE https://github.com/boot2docker/boot2docker-cli/releases/download/v$BOOT2DOCKER_CLI_VERSION/boot2docker-v$BOOT2DOCKER_CLI_VERSION-darwin-amd64 chmod +x $BOOT2DOCKER_CLI_FILE fi +if [ ! -f $DOCKER_CLI_FILE ]; then + echo "-----> Downloading Docker CLI..." + rm -rf docker-* + curl -L -o docker-$DOCKER_CLI_VERSION.tgz https://get.docker.com/builds/Darwin/x86_64/docker-$DOCKER_CLI_VERSION.tgz + tar xvzf docker-$DOCKER_CLI_VERSION.tgz --strip=3 + rm docker-$DOCKER_CLI_VERSION.tgz + mv docker docker-$DOCKER_CLI_VERSION + chmod +x $DOCKER_CLI_FILE +fi + popd > /dev/null diff --git a/package.json b/package.json index a7566e1948..dbcf32a0ba 100644 --- a/package.json +++ b/package.json @@ -27,12 +27,18 @@ "jest": { "scriptPreprocessor": "preprocessor.js", "unmockedModulePathPatterns": [ - "node_modules/request", + "tty", + "net", + "crypto", + "stream", + "object-assign", + "underscore", "node_modules/react", "node_modules/bluebird", "node_modules/6to5" ] }, + "docker-version": "1.4.1", "boot2docker-version": "1.4.1", "atom-shell-version": "0.21.1", "virtualbox-version": "4.3.20", @@ -45,20 +51,17 @@ "bluebird": "^2.9.6", "bugsnag-js": "git+https://git@github.com/bugsnag/bugsnag-js", "dockerode": "2.0.4", + "download": "^4.0.0", "exec": "0.1.2", - "html2canvas": "^0.5.0-alpha2", "jquery": "^2.1.3", "minimist": "^1.1.0", - "node-uuid": "1.4.1", "object-assign": "^2.0.0", - "open": "0.0.5", "react": "^0.12.2", "react-bootstrap": "^0.13.2", "react-retina-image": "^1.1.2", "react-router": "^0.11.6", - "request": "^2.51.0", - "request-progress": "0.3.1", - "request-promise": "^0.3.3", + "request": "^2.53.0", + "request-progress": "^0.3.1", "retina.js": "^1.1.0", "rimraf": "^2.2.8", "underscore": "^1.7.0" diff --git a/src/Main.js b/src/Main.js index 0ea0c28750..87919ac609 100644 --- a/src/Main.js +++ b/src/Main.js @@ -9,7 +9,12 @@ var router = require('./router'); var boot2docker = require('./boot2docker'); var ContainerStore = require('./ContainerStore'); var SetupStore = require('./ContainerStore'); -var settingsjson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'settings.json'), 'utf8')); +var settingsjson; +try { + settingsjson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'settings.json'), 'utf8')); +} catch (err) { + settingsjson = {}; +} if (process.env.NODE_ENV === 'development') { var head = document.getElementsByTagName('head')[0]; diff --git a/src/NewContainer.react.js b/src/NewContainer.react.js index b8e132dfce..fa325242d7 100644 --- a/src/NewContainer.react.js +++ b/src/NewContainer.react.js @@ -194,7 +194,7 @@ var NewContainer = React.createClass({
{message}
-{message}
-{message}
-{message}
-{SetupStore.step().message}
There seem to be an unexpected error with Kitematic:
-{this.state.error}
+There seems to have been an unexpected error with Kitematic:
+{this.state.error.message}
+