Skip to content

Commit

Permalink
Rearrange test directory
Browse files Browse the repository at this point in the history
  • Loading branch information
yuya-oc committed May 2, 2016
1 parent 447c845 commit 47486d8
Show file tree
Hide file tree
Showing 7 changed files with 313 additions and 240 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"start": "electron dist",
"watch": "gulp watch",
"serve": "gulp watch",
"test": "gulp build && mocha && gulp prettify:verify",
"test": "gulp build && mocha --recursive test/specs && gulp prettify:verify",
"package": "gulp package",
"package:windows": "gulp package:windows",
"package:osx": "gulp package:osx",
Expand Down
236 changes: 0 additions & 236 deletions test/browser_test.js

This file was deleted.

41 changes: 41 additions & 0 deletions test/modules/environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const path = require('path');
const webdriverio = require('webdriverio');

const source_root_dir = path.join(__dirname, '../..');
const electron_binary_path = (function() {
if (process.platform === 'darwin') {
return path.join(source_root_dir, 'node_modules/electron-prebuilt/dist/Electron.app/Contents/MacOS/Electron');
}
else {
const exe_extension = (process.platform === 'win32') ? '.exe' : '';
return 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 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, 'dist'), '--config-file=' + config_file_path] // Optional, perhaps 'app=' + /path/to/your/app/
}
}
};

module.exports = {
sourceRootDir: source_root_dir,
configFilePath: config_file_path,
mattermostURL: mattermost_url,
spawnChromeDriver: function() {
return require('child_process').spawn('node_modules/chromedriver/lib/chromedriver/chromedriver', ['--url-base=wd/hub', '--port=9515']);
},
getWebDriverIoClient: function() {
return webdriverio.remote(options);
}
}
75 changes: 75 additions & 0 deletions test/specs/app_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict';

const should = require('should');
const path = require('path');
const fs = require('fs');

const env = require('../modules/environment');

describe('application', function() {
this.timeout(10000);

var chromedriver;
var client;
before(function(done) {
chromedriver = env.spawnChromeDriver();
client = env.getWebDriverIoClient();

fs.unlink(env.configFilePath, function(err) {
// waiting for chromedriver
setTimeout(done, 1000);
});
});

afterEach(function() {
return client.end();
});

after(function() {
chromedriver.kill();
});

it('should show settings.html when there is no config file', function() {
return client
.init()
.pause(1000)
.getUrl().then(function(url) {
var p = path.parse(url);
p.base.should.equal('settings.html');
})
.end();
});

it('should show index.html when there is config file', function() {
fs.writeFileSync(env.configFilePath, JSON.stringify({
url: env.mattermostURL
}));
return client
.init()
.pause(1000)
.getUrl().then(function(url) {
var p = path.parse(url);
p.base.should.equal('index.html');
})
.end();
});

it('should upgrade v0 config file', function() {
const settings = require('../../src/common/settings');
fs.writeFileSync(env.configFilePath, JSON.stringify({
url: env.mattermostURL
}));
return client
.init()
.pause(1000)
.getUrl().then(function(url) {
var p = path.parse(url);
p.base.should.equal('index.html');
})
.end().then(function() {
var str = fs.readFileSync(env.configFilePath, 'utf8');
var config = JSON.parse(str);
config.version.should.equal(settings.version);
});
});
});
Loading

0 comments on commit 47486d8

Please sign in to comment.