diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aa0ec6b..17da5a9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Icelandic Translation. - Add use a script to prevent when is run by SSH session set DISPLAY enviroment. - Enable ability to set configuration file by the enviroment variable called MM_CONFIG_FILE. +- Add test e2e helloworld +- Add test e2e enviroment ### Fixed - Update .gitignore to not ignore default modules folder. diff --git a/js/server.js b/js/server.js index 5c775f69..e7050021 100644 --- a/js/server.js +++ b/js/server.js @@ -37,6 +37,7 @@ var Server = function(config, callback) { app.use("/modules", express.static(path.resolve(global.root_path + "/modules"))); app.use("/vendor", express.static(path.resolve(global.root_path + "/vendor"))); app.use("/translations", express.static(path.resolve(global.root_path + "/translations"))); + app.use("/tests/confs", express.static(path.resolve(global.root_path + "/tests/confs"))); app.get("/version", function(req,res) { res.send(global.version); diff --git a/package.json b/package.json index 9d94a012..92202936 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "start": "sh run-start.sh", "postinstall": "sh installers/postinstall/postinstall.sh", - "test": "./node_modules/mocha/bin/mocha tests --recursive" + "test": "./node_modules/mocha/bin/mocha $(find tests -path '*js*' ! -ipath '*e2e*')", + "test:e2e": "./node_modules/mocha/bin/mocha tests/e2e --recursive" }, "repository": { "type": "git", @@ -36,6 +37,7 @@ "grunt-stylelint": "latest", "grunt-yamllint": "latest", "mocha": "^3.2.0", + "spectron": "^3.4.1", "stylelint-config-standard": "latest", "time-grunt": "latest" }, diff --git a/tests/confs/env.js b/tests/confs/env.js new file mode 100644 index 00000000..252934d7 --- /dev/null +++ b/tests/confs/env.js @@ -0,0 +1,25 @@ +/* Magic Mirror Test config sample enviroment + * + * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com + * MIT Licensed. + */ + +var config = { + port: 8080, + ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], + + language: "en", + timeFormat: 24, + units: "metric", + electronOptions: { + webPreferences: { + nodeIntegration: true, + }, + }, + + modules: [ + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") {module.exports = config;} diff --git a/tests/confs/helloworld.js b/tests/confs/helloworld.js new file mode 100644 index 00000000..6b617cf2 --- /dev/null +++ b/tests/confs/helloworld.js @@ -0,0 +1,32 @@ +/* Magic Mirror Test config sample module hello world + * + * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com + * MIT Licensed. + */ + +var config = { + port: 8080, + ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], + + language: "en", + timeFormat: 24, + units: "metric", + electronOptions: { + webPreferences: { + nodeIntegration: true, + }, + }, + + modules: [ + { + module: "helloworld", + position: "bottom_bar", + config: { + text: "Test HelloWorld Module" + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") {module.exports = config;} diff --git a/tests/e2e/env.js b/tests/e2e/env.js new file mode 100644 index 00000000..41386499 --- /dev/null +++ b/tests/e2e/env.js @@ -0,0 +1,49 @@ +const Application = require("spectron").Application; +const path = require("path"); +const chai = require("chai"); +const chaiAsPromised = require("chai-as-promised"); + +// Set config sample for use in test +process.env.MM_CONFIG_FILE = "tests/confs/env.js"; + +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); +}); + +describe("Test enviroment app electron", function () { + this.timeout(10000); + + beforeEach(function (done) { + app.start().then(function() { done(); } ); + }); + + afterEach(function (done) { + app.stop().then(function() { done(); }); + }); + + + it("open a window app and test if is open", function () { + return app.client.waitUntilWindowLoaded() + .getWindowCount().should.eventually.equal(1); + }); + + it("tests the title", function () { + return app.client.waitUntilWindowLoaded() + .getTitle().should.eventually.equal("Magic Mirror"); + }); + +}); diff --git a/tests/e2e/modules/helloworld.js b/tests/e2e/modules/helloworld.js new file mode 100644 index 00000000..ebf8a8d1 --- /dev/null +++ b/tests/e2e/modules/helloworld.js @@ -0,0 +1,42 @@ +const Application = require("spectron").Application; +const path = require("path"); +const chai = require("chai"); +const chaiAsPromised = require("chai-as-promised"); + +// Set config sample for use in test +process.env.MM_CONFIG_FILE = "tests/confs/helloworld.js"; + +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); +}); + +describe("Test helloworld module", function () { + this.timeout(10000); + + beforeEach(function (done) { + app.start().then(function() { done(); } ); + }); + + 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"); + }); +});