diff --git a/.gitignore b/.gitignore index 976c75a5..f74010b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ node_modules/ release/ +npm-debug.log + +test_config.json diff --git a/circle.yml b/circle.yml index 0336547c..e3f1f86f 100644 --- a/circle.yml +++ b/circle.yml @@ -1,3 +1,7 @@ +machine: + node: + version: 4.2.2 + dependencies: post: - sudo service docker start @@ -12,10 +16,6 @@ dependencies: - tar zcvf $CIRCLE_ARTIFACTS/electron-mattermost-linux-ia32.tar.gz -C release electron-mattermost-linux-ia32 - tar zcvf $CIRCLE_ARTIFACTS/electron-mattermost-linux-x64.tar.gz -C release electron-mattermost-linux-x64 -test: - override: - - exit 0 - deployment: release: tag: /v[0-9]+(\.[0-9]+)*/ diff --git a/docker/Dockerfile b/docker/Dockerfile index a9efe86c..3c63dbb8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,7 +1,7 @@ FROM suchja/wine:latest MAINTAINER Yuya Ochiai -ENV NODE_VERSION=v4.2.3 +ENV NODE_VERSION=v4.2.2 ENV PATH=$HOME/.nodebrew/current/bin:$PATH USER root diff --git a/package.json b/package.json index 4bd07949..c14f51fc 100644 --- a/package.json +++ b/package.json @@ -7,13 +7,18 @@ "license": "MIT", "scripts": { "postinstall": "cd src && npm install", - "start": "electron src" + "start": "electron src", + "test": "mocha" }, "devDependencies": { + "chromedriver": "^2.20.0", "electron-connect": "^0.3.3", "electron-packager": "^5.1.0", "electron-prebuilt": "^0.35.1", "gulp": "^3.9.0", - "gulp-jsbeautifier": "^1.0.1" + "gulp-jsbeautifier": "^1.0.1", + "mocha": "^2.3.4", + "should": "^8.0.1", + "webdriverio": "^3.3.0" } } diff --git a/src/index.js b/src/index.js index f7d904f8..e74dba8c 100644 --- a/src/index.js +++ b/src/index.js @@ -12,8 +12,9 @@ var contextMenu = require('./menus/context'); var webView = document.getElementById('mainWebview'); try { - var configFile = electron.remote.app.getPath('userData') + '/config.json'; - var config = require(configFile); + var configFile = remote.getGlobal('config-file'); + var str = fs.readFileSync(configFile); + var config = JSON.parse(str); if (config.url) { webView.setAttribute('src', config.url); } diff --git a/src/main.js b/src/main.js index 55e70bf7..bce6eb52 100644 --- a/src/main.js +++ b/src/main.js @@ -10,14 +10,23 @@ const fs = require('fs'); var appMenu = require('./menus/app'); +var argv = require('yargs').argv; + var client = null; -if (process.argv.indexOf('--livereload') > 0) { +if (argv.livereload) { client = require('electron-connect').client.create(); client.on('stop', function() { app.quit(); }); } +if (argv['config-file']) { + global['config-file'] = argv['config-file']; +} +else { + global['config-file'] = app.getPath('userData') + '/config.json' +} + // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. var mainWindow = null; diff --git a/src/package.json b/src/package.json index 0cf73a5d..7d355904 100644 --- a/src/package.json +++ b/src/package.json @@ -9,6 +9,7 @@ "electron-connect": "^0.3.3" }, "dependencies": { - "os-locale": "^1.4.0" + "os-locale": "^1.4.0", + "yargs": "^3.31.0" } } diff --git a/src/settings.html b/src/settings.html index 85931cd7..865bee27 100644 --- a/src/settings.html +++ b/src/settings.html @@ -19,7 +19,7 @@ var fs = require('fs'); var saveSettings = function() { - var configFile = remote.app.getPath('userData') + '/config.json'; + var configFile = remote.getGlobal('config-file'); var urlInput = document.getElementById('url'); var config = { url: urlInput.value diff --git a/test/test.js b/test/test.js new file mode 100644 index 00000000..34002c53 --- /dev/null +++ b/test/test.js @@ -0,0 +1,81 @@ +const webdriverio = require('webdriverio'); +const should = require('should'); +const path = require('path'); +const fs = require('fs'); + +const exe_extension = (process.platform === 'win32') ? ".exe" : ""; +const source_root_dir = path.join(__dirname, '..'); +const electron_binary_path = path.join(source_root_dir, 'node_modules/electron-prebuilt/dist/electron' + exe_extension); +const config_file_path = path.join(source_root_dir, 'test_config.json'); +const mattermost_url = 'http://example.com/team'; + +var chromedriver = require('child_process').spawn('node_modules/chromedriver/lib/chromedriver/chromedriver', ['--url-base=wd/hub', '--port=9515']); + +var options = { + host: "localhost", // Use localhost as chrome driver server + port: 9515, // "9515" is the port opened by chrome driver. + desiredCapabilities: { + browserName: 'chrome', + chromeOptions: { + binary: electron_binary_path, // Path to your Electron binary. + args: ['app=' + path.join(source_root_dir, 'src'), '--config-file=' + config_file_path] // Optional, perhaps 'app=' + /path/to/your/app/ + } + } +}; + +describe('electron-mattermost', function() { + before(function(done) { + fs.unlink(config_file_path, function(err) { + done(); + }); + }); + + it('should show settings.html when there is no config file', function(done) { + var client = webdriverio.remote(options); + client + .init() + .getUrl().then(function(url) { + var p = path.parse(url); + p.base.should.equal('settings.html'); + }) + .end().then(function() { + done(); + }); + }); + + it('should show index.html when there is config file', function(done) { + fs.writeFileSync(config_file_path, JSON.stringify({ + url: mattermost_url + })); + var client = webdriverio.remote(options); + client + .init() + .getUrl().then(function(url) { + var p = path.parse(url); + p.base.should.equal('index.html'); + }) + .end().then(function() { + done(); + }); + }); + + describe('index.html', function() { + before(function() { + fs.writeFileSync(config_file_path, JSON.stringify({ + url: mattermost_url + })); + }); + + it('should set src of #mainWebview from config file', function(done) { + var client = webdriverio.remote(options); + client + .init() + .getAttribute('#mainWebview', 'src').then(function(attribute) { + attribute.should.equal(mattermost_url); + }) + .end().then(function() { + done(); + }); + }); + }); +});