diff --git a/.travis.yml b/.travis.yml index 5c2933fa..45903817 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,7 @@ addons: before_install: - mkdir -p /tmp/git-lfs && curl -L https://github.com/github/git-lfs/releases/download/v1.2.1/git-lfs-$([ "$TRAVIS_OS_NAME" == "linux" ] && echo "linux" || echo "darwin")-amd64-1.2.1.tar.gz | tar -xz -C /tmp/git-lfs --strip-components 1 && /tmp/git-lfs/git-lfs pull + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start; sleep 3; fi install: - nvm install 6 diff --git a/app/plugins.js b/app/plugins.js index 7cc2c538..9c06e247 100644 --- a/app/plugins.js +++ b/app/plugins.js @@ -190,8 +190,19 @@ function alert (message) { function toDependencies (plugins) { const obj = {}; plugins.plugins.forEach((plugin) => { - const pieces = plugin.split('#'); - obj[pieces[0]] = null == pieces[1] ? 'latest' : pieces[1]; + const regex = /.(@|#)/; + const match = regex.exec(plugin); + + if (match) { + const index = match.index + 1; + const pieces = []; + + pieces[0] = plugin.substring(0, index); + pieces[1] = plugin.substring(index + 1, plugin.length); + obj[pieces[0]] = pieces[1]; + } else { + obj[plugin] = 'latest'; + } }); return obj; } @@ -321,3 +332,5 @@ exports.getDecoratedConfig = function () { exports.getDecoratedBrowserOptions = function (defaults) { return decorateObject(defaults, 'decorateBrowserOptions'); }; + +exports._toDependencies = toDependencies; diff --git a/package.json b/package.json index a4b4f6b7..47ba4bbb 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,10 @@ "dependencies": { "aphrodite-simple": "0.4.1", "color": "0.11.3", + "electron-mocha": "^3.0.0", "hterm-umdjs": "1.1.3", "json-loader": "0.5.4", + "mocha": "^3.0.0", "mousetrap": "1.6.0", "ms": "0.7.1", "object-values": "1.0.0", @@ -27,7 +29,8 @@ "redux": "3.5.2", "redux-thunk": "2.1.0", "reselect": "2.5.3", - "seamless-immutable": "6.1.1" + "seamless-immutable": "6.1.1", + "should": "^10.0.0" }, "devDependencies": { "babel-cli": "^6.11.4", @@ -73,6 +76,9 @@ "ecmaFeatures": { "jsx": true } + }, + "env": { + "mocha": true } }, "babel": { @@ -96,7 +102,7 @@ "dev": "webpack --watch", "lint": "eslint .", "build": "NODE_ENV=production webpack", - "test": "npm run lint", + "test": "npm run lint && electron-mocha test/*", "start": "electron app", "prepublish": "npm test", "prepush": "npm test", diff --git a/test/app/plugins.js b/test/app/plugins.js new file mode 100644 index 00000000..1798b132 --- /dev/null +++ b/test/app/plugins.js @@ -0,0 +1,22 @@ +require('../setup'); + +const {_toDependencies} = require('../../app/plugins'); + +describe('plugins', function () { + describe('#toDependencies()', function () { + it('should convert dependencies form hyperterm\'s format to npm\'s', function () { + const plugins = ['project1', 'project2#1.0.0', 'project3@beta', + '@org1/project4#1.0.0', '@org2/project5@alpha', + '@org3/project6']; + + _toDependencies({plugins: plugins}).should.be.eql({ + 'project1': 'latest', + 'project2': '1.0.0', + 'project3': 'beta', + '@org1/project4': '1.0.0', + '@org2/project5': 'alpha', + '@org3/project6': 'latest' + }); + }); + }); +}); diff --git a/test/setup.js b/test/setup.js new file mode 100644 index 00000000..4041736a --- /dev/null +++ b/test/setup.js @@ -0,0 +1,5 @@ +require('should'); + +const config = require('../app/config'); + +config.init();