Merge pull request #2 from QNimbus/activate-test-e2e

Change suggestion for e2e testing
This commit is contained in:
Rodrigo Ramírez Norambuena 2017-07-24 22:38:32 -04:00 committed by GitHub
commit dccfcc9663
17 changed files with 472 additions and 367 deletions

View File

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

View File

@ -17,7 +17,6 @@ const BrowserWindow = electron.BrowserWindow;
let mainWindow;
function createWindow() {
var electronOptionsDefaults = {
width: 800,
height: 600,
@ -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"
@ -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;
});
}

View File

@ -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;
});
});
return app.start().then(function() {
after(function() {
return helpers.stopApplication(app);
});
it("should open dev console when provided", function() {
return expect(app.browserWindow.isDevToolsOpened()).to.eventually.equal(true);
});
});

View File

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

View File

@ -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");
const path = require("path");
if (process.platform === "win32") {
electronPath += ".cmd";
}
var appPath = path.join(__dirname, "../../js/electron.js");
var app = new Application({
path: electronPath,
args: [appPath]
});
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);
});
};

View File

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

View File

@ -1,19 +1,32 @@
const globalSetup = require("../global-setup");
const serverBasicAuth = require("../../servers/basic-auth.js");
const app = globalSetup.app;
const chai = require("chai");
const expect = chai.expect;
const helpers = require("../global-setup");
const path = require("path");
const request = require("request");
const serverBasicAuth = require("../../servers/basic-auth.js");
describe("Calendar module", function () {
const expect = require("chai").expect;
this.timeout(20000);
const describe = global.describe;
const it = global.it;
const beforeEach = global.beforeEach;
const afterEach = global.afterEach;
beforeEach(function (done) {
app.start().then(function() { done(); } );
describe("Calendar module", function() {
helpers.setupTimeout(this);
var app = null;
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("Default configuration", function() {
@ -22,12 +35,11 @@ describe("Calendar module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/default.js";
});
it("Should return TestEvents", function () {
it("Should return TestEvents", function() {
return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000);
});
});
describe("Basic auth", function() {
before(function() {
serverBasicAuth.listen(8010);
@ -35,12 +47,15 @@ describe("Calendar module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/basic-auth.js";
});
it("Should return TestEvents", function () {
after(function(done) {
serverBasicAuth.close(done());
});
it("Should return TestEvents", function() {
return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000);
});
});
describe("Basic auth by default", function() {
before(function() {
serverBasicAuth.listen(8011);
@ -48,7 +63,11 @@ describe("Calendar module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/auth-default.js";
});
it("Should return TestEvents", function () {
after(function(done) {
serverBasicAuth.close(done());
});
it("Should return TestEvents", function() {
return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000);
});
});
@ -60,7 +79,11 @@ describe("Calendar module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/old-basic-auth.js";
});
it("Should return TestEvents", function () {
after(function(done) {
serverBasicAuth.close(done());
});
it("Should return TestEvents", function() {
return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000);
});
});
@ -72,10 +95,12 @@ describe("Calendar module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/fail-basic-auth.js";
});
it("Should return No upcoming events", function () {
after(function(done) {
serverBasicAuth.close(done());
});
it("Should return No upcoming events", function() {
return app.client.waitUntilTextExists(".calendar", "No upcoming events.", 10000);
});
});
});

View File

@ -1,8 +1,32 @@
const globalSetup = require("../global-setup");
const app = globalSetup.app;
const helpers = require("../global-setup");
const path = require("path");
const request = require("request");
describe("Clock set to spanish language module", 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("Clock set to spanish language module", function() {
helpers.setupTimeout(this);
var app = null;
beforeEach(function() {
return helpers
.startApplication({
args: ["js/electron.js"]
})
.then(function(startedApp) {
app = startedApp;
});
});
afterEach(function() {
return helpers.stopApplication(app);
});
describe("with default 24hr clock config", function() {
before(function() {
@ -10,24 +34,14 @@ describe("Clock set to spanish language module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/es/clock_24hr.js";
});
beforeEach(function (done) {
app.start().then(function() { done(); } );
});
afterEach(function (done) {
app.stop().then(function() { done(); });
});
it("shows date with correct format", function () {
it("shows date with correct format", function() {
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
return app.client.waitUntilWindowLoaded()
.getText(".clock .date").should.eventually.match(dateRegex);
return app.client.waitUntilWindowLoaded().getText(".clock .date").should.eventually.match(dateRegex);
});
it("shows time in 24hr format", function() {
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/
return app.client.waitUntilWindowLoaded()
.getText(".clock .time").should.eventually.match(timeRegex);
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
});
});
@ -37,24 +51,14 @@ describe("Clock set to spanish language module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/es/clock_12hr.js";
});
beforeEach(function (done) {
app.start().then(function() { done(); } );
});
afterEach(function (done) {
app.stop().then(function() { done(); });
});
it("shows date with correct format", function () {
it("shows date with correct format", function() {
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
return app.client.waitUntilWindowLoaded()
.getText(".clock .date").should.eventually.match(dateRegex);
return app.client.waitUntilWindowLoaded().getText(".clock .date").should.eventually.match(dateRegex);
});
it("shows time in 12hr format", function() {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
return app.client.waitUntilWindowLoaded()
.getText(".clock .time").should.eventually.match(timeRegex);
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
});
});
@ -64,18 +68,9 @@ describe("Clock set to spanish language module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/es/clock_showPeriodUpper.js";
});
beforeEach(function (done) {
app.start().then(function() { done(); } );
});
afterEach(function (done) {
app.stop().then(function() { done(); });
});
it("shows 12hr time with upper case AM/PM", function() {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
return app.client.waitUntilWindowLoaded()
.getText(".clock .time").should.eventually.match(timeRegex);
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
});
});
});

View File

@ -1,8 +1,32 @@
const globalSetup = require("../global-setup");
const app = globalSetup.app;
const helpers = require("../global-setup");
const path = require("path");
const request = require("request");
describe("Clock module", 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("Clock module", function() {
helpers.setupTimeout(this);
var app = null;
beforeEach(function() {
return helpers
.startApplication({
args: ["js/electron.js"]
})
.then(function(startedApp) {
app = startedApp;
});
});
afterEach(function() {
return helpers.stopApplication(app);
});
describe("with default 24hr clock config", function() {
before(function() {
@ -10,24 +34,14 @@ describe("Clock module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_24hr.js";
});
beforeEach(function (done) {
app.start().then(function() { done(); } );
});
afterEach(function (done) {
app.stop().then(function() { done(); });
});
it("shows date with correct format", function () {
it("shows date with correct format", function() {
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
return app.client.waitUntilWindowLoaded()
.getText(".clock .date").should.eventually.match(dateRegex);
return app.client.waitUntilWindowLoaded().getText(".clock .date").should.eventually.match(dateRegex);
});
it("shows time in 24hr format", function() {
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/
return app.client.waitUntilWindowLoaded()
.getText(".clock .time").should.eventually.match(timeRegex);
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
});
});
@ -37,24 +51,14 @@ describe("Clock module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_12hr.js";
});
beforeEach(function (done) {
app.start().then(function() { done(); } );
});
afterEach(function (done) {
app.stop().then(function() { done(); });
});
it("shows date with correct format", function () {
it("shows date with correct format", function() {
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
return app.client.waitUntilWindowLoaded()
.getText(".clock .date").should.eventually.match(dateRegex);
return app.client.waitUntilWindowLoaded().getText(".clock .date").should.eventually.match(dateRegex);
});
it("shows time in 12hr format", function() {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
return app.client.waitUntilWindowLoaded()
.getText(".clock .time").should.eventually.match(timeRegex);
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
});
});
@ -64,18 +68,9 @@ describe("Clock module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_showPeriodUpper.js";
});
beforeEach(function (done) {
app.start().then(function() { done(); } );
});
afterEach(function (done) {
app.stop().then(function() { done(); });
});
it("shows 12hr time with upper case AM/PM", function() {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
return app.client.waitUntilWindowLoaded()
.getText(".clock .time").should.eventually.match(timeRegex);
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
});
});
@ -85,18 +80,9 @@ describe("Clock module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_displaySeconds_false.js";
});
beforeEach(function (done) {
app.start().then(function() { done(); } );
});
afterEach(function (done) {
app.stop().then(function() { done(); });
});
it("shows 12hr time without seconds am/pm", function() {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[ap]m$/;
return app.client.waitUntilWindowLoaded()
.getText(".clock .time").should.eventually.match(timeRegex);
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
});
});
@ -106,29 +92,17 @@ describe("Clock module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_showWeek.js";
});
beforeEach(function (done) {
app.start().then(function() { done(); } );
});
afterEach(function (done) {
app.stop().then(function() { done(); });
});
it("shows week with correct format", function() {
const weekRegex = /^Week [0-9]{1,2}$/;
return app.client.waitUntilWindowLoaded()
.getText(".clock .week").should.eventually.match(weekRegex);
return app.client.waitUntilWindowLoaded().getText(".clock .week").should.eventually.match(weekRegex);
});
it("shows week with correct number of week of year", function() {
it("FIXME: if the day is a sunday this not match");
// const currentWeekNumber = require("current-week-number")();
// const weekToShow = "Week " + currentWeekNumber;
// return app.client.waitUntilWindowLoaded()
// .getText(".clock .week").should.eventually.equal(weekToShow);
it("FIXME: if the day is a sunday this not match");
// const currentWeekNumber = require("current-week-number")();
// const weekToShow = "Week " + currentWeekNumber;
// return app.client.waitUntilWindowLoaded()
// .getText(".clock .week").should.eventually.equal(weekToShow);
});
});
});

View File

@ -1,77 +1,81 @@
const globalSetup = require("../global-setup");
const app = globalSetup.app;
const chai = require("chai");
const expect = chai.expect;
const helpers = require("../global-setup");
const path = require("path");
const request = require("request");
describe("Compliments module", 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;
beforeEach(function (done) {
app.start().then(function() { done(); } );
describe("Compliments module", function() {
helpers.setupTimeout(this);
var app = null;
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("parts of days", function() {
before(function() {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_parts_day.js";
});
it("if Morning compliments for that part of day", function () {
it("if Morning compliments for that part of day", function() {
var hour = new Date().getHours();
if (hour >= 3 && hour < 12) {
// if morning check
return app.client.waitUntilWindowLoaded()
.getText(".compliments").then(function (text) {
expect(text).to.be.oneOf(["Hi", "Good Morning", "Morning test"]);
})
return app.client.waitUntilWindowLoaded().getText(".compliments").then(function(text) {
expect(text).to.be.oneOf(["Hi", "Good Morning", "Morning test"]);
});
}
});
it("if Afternoon show Compliments for that part of day", function () {
it("if Afternoon show Compliments for that part of day", function() {
var hour = new Date().getHours();
if (hour >= 12 && hour < 17) {
// if morning check
return app.client.waitUntilWindowLoaded()
.getText(".compliments").then(function (text) {
expect(text).to.be.oneOf(["Hello", "Good Afternoon", "Afternoon test"]);
})
return app.client.waitUntilWindowLoaded().getText(".compliments").then(function(text) {
expect(text).to.be.oneOf(["Hello", "Good Afternoon", "Afternoon test"]);
});
}
});
it("if Evening show Compliments for that part of day", function () {
it("if Evening show Compliments for that part of day", function() {
var hour = new Date().getHours();
if (!(hour >= 3 && hour < 12) && !(hour >= 12 && hour < 17)) {
// if evening check
return app.client.waitUntilWindowLoaded()
.getText(".compliments").then(function (text) {
expect(text).to.be.oneOf(["Hello There", "Good Evening", "Evening test"]);
})
return app.client.waitUntilWindowLoaded().getText(".compliments").then(function(text) {
expect(text).to.be.oneOf(["Hello There", "Good Evening", "Evening test"]);
});
}
});
});
describe("Feature anytime in compliments module", function() {
describe("Set anytime and empty compliments for morning, evening and afternoon ", function() {
before(function() {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_anytime.js";
});
it("Show anytime because if configure empty parts of day compliments and set anytime compliments", function () {
return app.client.waitUntilWindowLoaded()
.getText(".compliments").then(function (text) {
expect(text).to.be.oneOf(["Anytime here"]);
})
it("Show anytime because if configure empty parts of day compliments and set anytime compliments", function() {
return app.client.waitUntilWindowLoaded().getText(".compliments").then(function(text) {
expect(text).to.be.oneOf(["Anytime here"]);
});
});
});
@ -81,15 +85,11 @@ describe("Compliments module", function () {
process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_only_anytime.js";
});
it("Show anytime compliments", function () {
return app.client.waitUntilWindowLoaded()
.getText(".compliments").then(function (text) {
expect(text).to.be.oneOf(["Anytime here"]);
})
it("Show anytime compliments", function() {
return app.client.waitUntilWindowLoaded().getText(".compliments").then(function(text) {
expect(text).to.be.oneOf(["Anytime here"]);
});
});
});
});
});

View File

@ -1,24 +1,39 @@
const globalSetup = require("../global-setup");
const app = globalSetup.app;
const helpers = require("../global-setup");
const path = require("path");
const request = require("request");
describe("Test helloworld module", 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("Test helloworld module", function() {
helpers.setupTimeout(this);
var app = null;
beforeEach(function() {
return helpers
.startApplication({
args: ["js/electron.js"]
})
.then(function(startedApp) {
app = startedApp;
});
});
before(function() {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/modules/helloworld/helloworld.js";
});
beforeEach(function (done) {
app.start().then(function() { done(); } );
afterEach(function() {
return helpers.stopApplication(app);
});
afterEach(function (done) {
app.stop().then(function() { done(); });
});
it("Test message helloworld module", function () {
return app.client.waitUntilWindowLoaded()
.getText(".helloworld").should.eventually.equal("Test HelloWorld Module");
it("Test message helloworld module", function() {
return app.client.waitUntilWindowLoaded().getText(".helloworld").should.eventually.equal("Test HelloWorld Module");
});
});

View File

@ -1,27 +1,39 @@
const globalSetup = require("../global-setup");
const app = globalSetup.app;
const chai = require("chai");
const expect = chai.expect;
const helpers = require("../global-setup");
const path = require("path");
const request = require("request");
describe("Newsfeed module", function () {
const expect = require("chai").expect;
this.timeout(20000);
const describe = global.describe;
const it = global.it;
const beforeEach = global.beforeEach;
const afterEach = global.afterEach;
beforeEach(function (done) {
app.start().then(function() { done(); } );
describe("Newsfeed module", function() {
helpers.setupTimeout(this);
var app = null;
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("Default configuration", function() {
before(function() {
process.env.MM_CONFIG_FILE = "tests/configs/modules/newsfeed/default.js";
});
it("show title newsfeed", function () {
it("show title newsfeed", function() {
return app.client.waitUntilTextExists(".newsfeed .small", "Rodrigo Ramirez Blog", 10000).should.be.fulfilled;
});
});

View File

@ -1,24 +1,32 @@
const globalSetup = require("./global-setup");
const app = globalSetup.app;
const chai = require("chai");
const expect = chai.expect;
const helpers = require("./global-setup");
const path = require("path");
const request = require("request");
const expect = require("chai").expect;
const describe = global.describe;
const it = global.it;
const beforeEach = global.beforeEach;
const afterEach = global.afterEach;
describe("Position of modules", function () {
this.timeout(20000);
helpers.setupTimeout(this);
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("Using helloworld", function () {
describe("Using helloworld", function() {
before(function() {
before(function () {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/modules/positions.js";
});
@ -32,7 +40,7 @@ describe("Position of modules", function () {
for (idx in positions) {
position = positions[idx];
className = position.replace("_", ".");
it("show text in " + position , function () {
it("show text in " + position, function () {
return app.client.waitUntilWindowLoaded()
.getText("." + className).should.eventually.equal("Text in " + position);
});

View File

@ -1,27 +1,35 @@
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("port 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 port 8090", function () {
before(function() {
before(function () {
// Set config sample for use in this test
process.env.MM_CONFIG_FILE = "tests/configs/port_8090.js";
});
it("should return 200", function (done) {
request.get("http://localhost:8090", function (err, res, body) {
expect(res.statusCode).to.equal(200);
@ -31,15 +39,16 @@ describe("port directive configuration", function () {
});
describe("Set port 8100 on enviroment variable MM_PORT", function () {
before(function() {
before(function () {
process.env.MM_PORT = 8100;
// Set config sample for use in this test
process.env.MM_CONFIG_FILE = "tests/configs/port_8090.js";
});
after(function(){
after(function () {
delete process.env.MM_PORT;
});
it("should return 200", function (done) {
request.get("http://localhost:8100", function (err, res, body) {
expect(res.statusCode).to.equal(200);

View File

@ -1,34 +1,38 @@
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("Vendors", function () {
helpers.setupTimeout(this);
this.timeout(20000);
var app = null;
// FIXME: This test fail in Travis
return true;
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("Get list vendors", function () {
before(function() {
before(function () {
process.env.MM_CONFIG_FILE = "tests/configs/env.js";
});
var vendors = require(__dirname + "/../../vendor/vendor.js");
Object.keys(vendors).forEach(vendor => {
it(`should return 200 HTTP code for vendor "${vendor}"`, function() {
it(`should return 200 HTTP code for vendor "${vendor}"`, function () {
urlVendor = "http://localhost:8080/vendor/" + vendors[vendor];
request.get(urlVendor, function (err, res, body) {
expect(res.statusCode).to.equal(200);

View File

@ -1,44 +1,34 @@
const Application = require("spectron").Application;
const helpers = require("./global-setup");
const path = require("path");
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]
});
global.before(function () {
chai.should();
chai.use(chaiAsPromised);
});
const request = require("request");
const expect = require("chai").expect;
const describe = global.describe;
const it = global.it;
const beforeEach = global.beforeEach;
const afterEach = global.afterEach;
describe("Check configuration without modules", function () {
this.timeout(20000);
helpers.setupTimeout(this);
before(function() {
var app = null;
beforeEach(function () {
return helpers.startApplication({
args: ["js/electron.js"]
}).then(function (startedApp) { app = startedApp; })
});
afterEach(function () {
return helpers.stopApplication(app);
});
before(function () {
// Set config sample for use in test
process.env.MM_CONFIG_FILE = "tests/configs/without_modules.js";
});
beforeEach(function (done) {
app.start().then(function() { done(); } );
});
afterEach(function (done) {
app.stop().then(function() { done(); });
});
it("Show the message MagicMirror title", function () {
return app.client.waitUntilWindowLoaded()
.getText("#module_1_helloworld .module-content").should.eventually.equal("Magic Mirror2")

View File

@ -1,16 +1,21 @@
var http = require("http");
var path = require("path");
var auth = require("http-auth");
var express = require("express")
var express = require("express");
var app = express();
var basic = auth.basic({
realm: "MagicMirror Area restricted."
}, (username, password, callback) => {
callback(username === "MagicMirror" && password === "CallMeADog");
});
var server;
this.server = express();
this.server.use(auth.connect(basic));
var basic = auth.basic(
{
realm: "MagicMirror Area restricted."
},
(username, password, callback) => {
callback(username === "MagicMirror" && password === "CallMeADog");
}
);
app.use(auth.connect(basic));
// Set directories availables
var directories = ["/tests/configs"];
@ -18,13 +23,13 @@ var directory;
rootPath = path.resolve(__dirname + "/../../");
for (i in directories) {
directory = directories[i];
this.server.use(directory, express.static(path.resolve(rootPath + directory)));
app.use(directory, express.static(path.resolve(rootPath + directory)));
}
exports.listen = function () {
this.server.listen.apply(this.server, arguments);
exports.listen = function() {
server = app.listen.apply(app, arguments);
};
exports.close = function (callback) {
this.server.close(callback);
exports.close = function(callback) {
server.close(callback);
};