Add tests for app launching

This commit is contained in:
Yuya Ochiai 2015-12-12 21:20:18 +09:00
parent 49392a984b
commit 2a84f46b90
4 changed files with 91 additions and 6 deletions

3
.gitignore vendored
View file

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

View file

@ -12,10 +12,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]+)*/

View file

@ -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"
}
}

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