Skip to content

Commit

Permalink
Merge pull request #2 from QNimbus/activate-test-e2e
Browse files Browse the repository at this point in the history
Change suggestion for e2e testing
  • Loading branch information
roramirez authored Jul 25, 2017
2 parents 07533f5 + 203e1cc commit dccfcc9
Show file tree
Hide file tree
Showing 17 changed files with 472 additions and 367 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ before_script:
- sleep 5
script:
- grunt
- npm run test
- npm run test:unit
- npm run test:e2e
cache:
directories:
- node_modules
7 changes: 3 additions & 4 deletions js/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const BrowserWindow = electron.BrowserWindow;
let mainWindow;

function createWindow() {

var electronOptionsDefaults = {
width: 800,
height: 600,
Expand Down Expand Up @@ -47,7 +46,7 @@ function createWindow() {

// and load the index.html of the app.
// If config.address is not defined or is an empty string (listening on all interfaces), connect to localhost
var address = config.address === void 0 | config.address === "" ? config.address = "localhost" : config.address;
var address = (config.address === void 0) | (config.address === "") ? (config.address = "localhost") : config.address;
mainWindow.loadURL(`http://${address}:${config.port}`);

// Open the DevTools if run with "npm start dev"
Expand Down Expand Up @@ -100,7 +99,7 @@ app.on("activate", function() {
// Start the core application if server is run on localhost
// This starts all node helpers and starts the webserver.
if (["localhost", "127.0.0.1", "::1", "::ffff:127.0.0.1", undefined].indexOf(config.address) > -1) {
core.start(function (c) {
core.start(function(c) {
config = c;
});
}
}
73 changes: 42 additions & 31 deletions tests/e2e/dev_console.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,65 @@
const Application = require("spectron").Application;
const helpers = require("./global-setup");
const path = require("path");
const chai = require("chai");
const expect = chai.expect;
const chaiAsPromised = require("chai-as-promised");
const request = require("request");

var electronPath = path.join(__dirname, "../../", "node_modules", ".bin", "electron");
const expect = require("chai").expect;

if (process.platform === "win32") {
electronPath += ".cmd";
}

var appPath = path.join(__dirname, "../../js/electron.js");

var app = new Application({
path: electronPath
});

global.before(function () {
chai.should();
chai.use(chaiAsPromised);
});

describe("Argument 'dev'", function () {
this.timeout(20000);
const describe = global.describe;
const it = global.it;
const beforeEach = global.beforeEach;
const afterEach = global.afterEach;

describe("Development console tests", function() {
// This tests fail and crash another tests
// Suspect problem with window focus
// FIXME
return false;

helpers.setupTimeout(this);

var app = null;

before(function() {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/env.js";
});

afterEach(function (done) {
app.stop().then(function() { done(); });
});
describe("Without 'dev' commandline argument", function() {
before(function() {
return helpers
.startApplication({
args: ["js/electron.js"]
})
.then(function(startedApp) {
app = startedApp;
});
});

it("should not open dev console when absent", function () {
app.args = [appPath];
after(function() {
return helpers.stopApplication(app);
});

return app.start().then(function() {
it("should not open dev console when absent", function() {
return expect(app.browserWindow.isDevToolsOpened()).to.eventually.equal(false);
});
});

it("should open dev console when provided", function () {
app.args = [appPath, "dev"];
describe("With 'dev' commandline argument", function() {
before(function() {
return helpers
.startApplication({
args: ["js/electron.js", "dev"]
})
.then(function(startedApp) {
app = startedApp;
});
});

after(function() {
return helpers.stopApplication(app);
});

return app.start().then(function() {
it("should open dev console when provided", function() {
return expect(app.browserWindow.isDevToolsOpened()).to.eventually.equal(true);
});
});
Expand Down
68 changes: 45 additions & 23 deletions tests/e2e/env_spec.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,69 @@
const globalSetup = require("./global-setup");
const app = globalSetup.app;
const helpers = require("./global-setup");
const path = require("path");
const request = require("request");
const chai = require("chai");
const expect = chai.expect;

describe("Electron app environment", function () {
this.timeout(20000);
const expect = require("chai").expect;

const describe = global.describe;
const it = global.it;
const beforeEach = global.beforeEach;
const afterEach = global.afterEach;

describe("Electron app environment", function() {
helpers.setupTimeout(this);

var app = null;

before(function() {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/env.js";
});

beforeEach(function (done) {
app.start().then(function() { done(); } );
beforeEach(function() {
return helpers
.startApplication({
args: ["js/electron.js"]
})
.then(function(startedApp) {
app = startedApp;
});
});

afterEach(function (done) {
app.stop().then(function() { done(); });
afterEach(function() {
return helpers.stopApplication(app);
});

it("is set to open new app window", function () {
return app.client.waitUntilWindowLoaded()
.getWindowCount().should.eventually.equal(1);
it("should open a browserwindow", function() {
return app.client
.waitUntilWindowLoaded()
.browserWindow.focus()
.getWindowCount()
.should.eventually.equal(1)
.browserWindow.isMinimized()
.should.eventually.be.false.browserWindow.isDevToolsOpened()
.should.eventually.be.false.browserWindow.isVisible()
.should.eventually.be.true.browserWindow.isFocused()
.should.eventually.be.true.browserWindow.getBounds()
.should.eventually.have.property("width")
.and.be.above(0)
.browserWindow.getBounds()
.should.eventually.have.property("height")
.and.be.above(0)
.browserWindow.getTitle()
.should.eventually.equal("Magic Mirror");
});

it("sets correct window title", function () {
return app.client.waitUntilWindowLoaded()
.getTitle().should.eventually.equal("Magic Mirror");
});

it("get request from http://localhost:8080 should return 200", function (done) {
request.get("http://localhost:8080", function (err, res, body) {
it("get request from http://localhost:8080 should return 200", function(done) {
request.get("http://localhost:8080", function(err, res, body) {
expect(res.statusCode).to.equal(200);
done();
});
});

it("get request from http://localhost:8080/nothing should return 404", function (done) {
request.get("http://localhost:8080/nothing", function (err, res, body) {
it("get request from http://localhost:8080/nothing should return 404", function(done) {
request.get("http://localhost:8080/nothing", function(err, res, body) {
expect(res.statusCode).to.equal(404);
done();
});
});

});
58 changes: 43 additions & 15 deletions tests/e2e/global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,54 @@
*/

const Application = require("spectron").Application;
const path = require("path");
const assert = require("assert");
const chai = require("chai");
const chaiAsPromised = require("chai-as-promised");

var electronPath = path.join(__dirname, "../../", "node_modules", ".bin", "electron");

if (process.platform === "win32") {
electronPath += ".cmd";
}

var appPath = path.join(__dirname, "../../js/electron.js");

var app = new Application({
path: electronPath,
args: [appPath]
});
const path = require("path");

global.before(function () {
global.before(function() {
chai.should();
chai.use(chaiAsPromised);
});

exports.app = app;
exports.getElectronPath = function() {
var electronPath = path.join(__dirname, "..", "..", "node_modules", ".bin", "electron");
if (process.platform === "win32") {
electronPath += ".cmd";
}
return electronPath;
};

// Set timeout - if this is run within Travis, increase timeout
exports.setupTimeout = function(test) {
if (process.env.CI) {
test.timeout(30000);
} else {
test.timeout(10000);
}
};

exports.startApplication = function(options) {
options.path = exports.getElectronPath();
if (process.env.CI) {
options.startTimeout = 30000;
}

var app = new Application(options);
return app.start().then(function() {
assert.equal(app.isRunning(), true);
chaiAsPromised.transferPromiseness = app.transferPromiseness;
return app;
});
};

exports.stopApplication = function(app) {
if (!app || !app.isRunning()) {
return;
}

return app.stop().then(function() {
assert.equal(app.isRunning(), false);
});
};
29 changes: 18 additions & 11 deletions tests/e2e/ipWhistlist_spec.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
const globalSetup = require("./global-setup");
const app = globalSetup.app;
const helpers = require("./global-setup");
const path = require("path");
const request = require("request");
const chai = require("chai");
const expect = chai.expect;

const expect = require("chai").expect;

const describe = global.describe;
const it = global.it;
const beforeEach = global.beforeEach;
const afterEach = global.afterEach;

describe("ipWhitelist directive configuration", function () {
helpers.setupTimeout(this);

this.timeout(20000);
var app = null;

beforeEach(function (done) {
app.start().then(function() { done(); } );
beforeEach(function () {
return helpers.startApplication({
args: ["js/electron.js"]
}).then(function (startedApp) { app = startedApp; })
});

afterEach(function (done) {
app.stop().then(function() { done(); });
afterEach(function () {
return helpers.stopApplication(app);
});

describe("Set ipWhitelist without access", function () {
before(function() {
before(function () {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/noIpWhiteList.js";
});
Expand All @@ -31,7 +38,7 @@ describe("ipWhitelist directive configuration", function () {
});

describe("Set ipWhitelist []", function () {
before(function() {
before(function () {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/empty_ipWhiteList.js";
});
Expand Down
Loading

0 comments on commit dccfcc9

Please sign in to comment.