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..6ae51436 100644 --- a/circle.yml +++ b/circle.yml @@ -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]+)*/ 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/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(); + }); + }); + }); +});