Browse Source

Adds test dependencies and refactors test structure.

pull/527/head
Michael Weimann 8 years ago
parent
commit
a358aa5ecf
  1. 28
      electron/test.js
  2. 13
      package.json
  3. 38
      test/helpers/RamboxTestHelper.js
  4. 24
      test/tests/app/example.spec.js

28
electron/test.js

@ -1,28 +0,0 @@
// A simple test to verify a visible window is opened with a title
var Application = require('spectron').Application
var assert = require('assert')
var app = new Application({
path: 'dist/Rambox-linux-x64/Rambox'
})
app.start().then(function () {
// Check if the window is visible
return app.browserWindow.isVisible()
}).then(function (isVisible) {
// Verify the window is visible
assert.equal(isVisible, true)
}).then(function () {
// Get the window's title
return app.client.getTitle()
}).then(function (title) {
// Verify the window's title
assert.equal(title, 'Ramboxx')
}).then(function () {
// Stop the application
return app.stop()
}).catch(function (error) {
// Log any failures
console.error('Test failed', error.message)
return app.stop()
})

13
package.json

@ -3,7 +3,7 @@
"scripts": {
"start": "electron electron/main.js",
"start:debug": "electron electron/main.js --enable-logging",
"test": "node electron/test.js",
"test": "./node_modules/.bin/mocha test/tests/**/*.spec.js",
"sencha:clean": "rm -rf ./build/production",
"sencha:compile": "sencha app build && cp app/package.json build/production/Rambox/ && npm --prefix ./build/production/Rambox/ install ./build/production/Rambox/",
"sencha:compile:build": "sencha app build && cp app/package.json build/production/Rambox/ && cp -R build/production/Rambox/* ../rambox-build",
@ -88,10 +88,13 @@
"app": "build/production/Rambox/"
},
"devDependencies": {
"asar": "^0.12.1",
"electron-builder": "6.5.2",
"electron": "1.4.7",
"electron-squirrel-startup": "^1.0.0"
"asar": "^0.12.1",
"chai": "3.5.0",
"electron": "1.4.7",
"electron-builder": "6.5.2",
"electron-squirrel-startup": "^1.0.0",
"mocha": "3.2.0",
"spectron": "3.4.0"
},
"dependencies": {
"auto-launch": "4.0.0",

38
test/helpers/RamboxTestHelper.js

@ -0,0 +1,38 @@
var Application = require('spectron').Application;
var electron = require('electron-prebuilt');
/**
* The RamboxTestHelper contains common stuff for tests.
*/
module.exports = function() {
var self = this;
/**
* Makes the Rambox Application available.
*
* @type {Application}
*/
self.app = null;
/**
* Starts Rambox from '/electron/main.js/'.
*/
beforeEach(function() {
self.app = new Application({
path: electron,
args: [__dirname + '/../../electron/main.js']
});
return self.app.start();
});
/**
* Stops Rambox.
*/
afterEach(function() {
if (self.app && self.app.isRunning()) {
return self.app.stop()
}
});
};

24
test/tests/app/example.spec.js

@ -0,0 +1,24 @@
/**
* This is an example test.
*/
var chai = require('chai');
var expect = chai.expect;
var RamboxTestHelper = require('../../helpers/RamboxTestHelper');
describe('Rambox window', function() {
/**
* The Rambox test helper does common stuff.
*
* @type {module.exports}
*/
var ramboxTestHelper = new RamboxTestHelper();
it('should have "Rambox" in the title', function () {
return ramboxTestHelper.app.client.browserWindow.getTitle().then(function(title) {
expect(title).to.contain('Rambox');
return Promise.resolve();
});
})
});
Loading…
Cancel
Save