Merge branch 'e2e-test'

This commit is contained in:
Yuya Ochiai
2015-12-13 19:17:28 +09:00
9 changed files with 112 additions and 12 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,5 @@
node_modules/ node_modules/
release/ release/
npm-debug.log
test_config.json

View File

@@ -1,3 +1,7 @@
machine:
node:
version: 4.2.2
dependencies: dependencies:
post: post:
- sudo service docker start - 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-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 - tar zcvf $CIRCLE_ARTIFACTS/electron-mattermost-linux-x64.tar.gz -C release electron-mattermost-linux-x64
test:
override:
- exit 0
deployment: deployment:
release: release:
tag: /v[0-9]+(\.[0-9]+)*/ tag: /v[0-9]+(\.[0-9]+)*/

View File

@@ -1,7 +1,7 @@
FROM suchja/wine:latest FROM suchja/wine:latest
MAINTAINER Yuya Ochiai <yuya0321@gmail.com> MAINTAINER Yuya Ochiai <yuya0321@gmail.com>
ENV NODE_VERSION=v4.2.3 ENV NODE_VERSION=v4.2.2
ENV PATH=$HOME/.nodebrew/current/bin:$PATH ENV PATH=$HOME/.nodebrew/current/bin:$PATH
USER root USER root

View File

@@ -7,13 +7,18 @@
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"postinstall": "cd src && npm install", "postinstall": "cd src && npm install",
"start": "electron src" "start": "electron src",
"test": "mocha"
}, },
"devDependencies": { "devDependencies": {
"chromedriver": "^2.20.0",
"electron-connect": "^0.3.3", "electron-connect": "^0.3.3",
"electron-packager": "^5.1.0", "electron-packager": "^5.1.0",
"electron-prebuilt": "^0.35.1", "electron-prebuilt": "^0.35.1",
"gulp": "^3.9.0", "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"
} }
} }

View File

@@ -12,8 +12,9 @@ var contextMenu = require('./menus/context');
var webView = document.getElementById('mainWebview'); var webView = document.getElementById('mainWebview');
try { try {
var configFile = electron.remote.app.getPath('userData') + '/config.json'; var configFile = remote.getGlobal('config-file');
var config = require(configFile); var str = fs.readFileSync(configFile);
var config = JSON.parse(str);
if (config.url) { if (config.url) {
webView.setAttribute('src', config.url); webView.setAttribute('src', config.url);
} }

View File

@@ -10,14 +10,23 @@ const fs = require('fs');
var appMenu = require('./menus/app'); var appMenu = require('./menus/app');
var argv = require('yargs').argv;
var client = null; var client = null;
if (process.argv.indexOf('--livereload') > 0) { if (argv.livereload) {
client = require('electron-connect').client.create(); client = require('electron-connect').client.create();
client.on('stop', function() { client.on('stop', function() {
app.quit(); 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 // 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. // be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null; var mainWindow = null;

View File

@@ -9,6 +9,7 @@
"electron-connect": "^0.3.3" "electron-connect": "^0.3.3"
}, },
"dependencies": { "dependencies": {
"os-locale": "^1.4.0" "os-locale": "^1.4.0",
"yargs": "^3.31.0"
} }
} }

View File

@@ -19,7 +19,7 @@
var fs = require('fs'); var fs = require('fs');
var saveSettings = function() { var saveSettings = function() {
var configFile = remote.app.getPath('userData') + '/config.json'; var configFile = remote.getGlobal('config-file');
var urlInput = document.getElementById('url'); var urlInput = document.getElementById('url');
var config = { var config = {
url: urlInput.value url: urlInput.value

81
test/test.js Normal file
View File

@@ -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();
});
});
});
});