From 0d8d8f042692b249f046a1d488ca58782656373d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Sat, 28 Jan 2017 23:23:32 -0300 Subject: [PATCH 1/5] Add tests configs directory as express route. --- js/server.js | 1 + 1 file changed, 1 insertion(+) 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); From 52b8dbcbb11d891c84c81df3c7d92c5f30331740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Sat, 28 Jan 2017 23:25:43 -0300 Subject: [PATCH 2/5] separate test type. Create directory for End-to-end testing. --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9d94a012..927cd2bc 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", From d474d518cae0882dffbb32638605a038d2a8c0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Mon, 30 Jan 2017 12:24:49 -0300 Subject: [PATCH 3/5] test e2e module helloworld --- CHANGELOG.md | 1 + package.json | 1 + tests/confs/helloworld.js | 32 +++++++++++++++++++++++++ tests/e2e/modules/helloworld.js | 42 +++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 tests/confs/helloworld.js create mode 100644 tests/e2e/modules/helloworld.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aa0ec6b..9c6b1a48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ 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 ### Fixed - Update .gitignore to not ignore default modules folder. diff --git a/package.json b/package.json index 927cd2bc..92202936 100644 --- a/package.json +++ b/package.json @@ -37,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/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/modules/helloworld.js b/tests/e2e/modules/helloworld.js new file mode 100644 index 00000000..960917c3 --- /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'); + }); +}); From c75ee042a8cd58013cd7d739c85ddffee04144be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Mon, 30 Jan 2017 12:29:32 -0300 Subject: [PATCH 4/5] add e2e test enviroment --- CHANGELOG.md | 1 + tests/confs/env.js | 25 +++++++++++++++++++++++ tests/e2e/env.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 tests/confs/env.js create mode 100644 tests/e2e/env.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c6b1a48..17da5a9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - 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/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/e2e/env.js b/tests/e2e/env.js new file mode 100644 index 00000000..0046ddec --- /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'); + }); + +}); From e2dc5ef4f2c14ac22ad69162a27206f71a119f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Mon, 30 Jan 2017 12:42:04 -0300 Subject: [PATCH 5/5] fix eslint change single quote by double quote --- tests/e2e/env.js | 24 ++++++++++++------------ tests/e2e/modules/helloworld.js | 22 +++++++++++----------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/e2e/env.js b/tests/e2e/env.js index 0046ddec..41386499 100644 --- a/tests/e2e/env.js +++ b/tests/e2e/env.js @@ -1,18 +1,18 @@ const Application = require("spectron").Application; -const path = require('path'); -const chai = require('chai'); -const chaiAsPromised = require('chai-as-promised'); +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'; +process.env.MM_CONFIG_FILE = "tests/confs/env.js"; -var electronPath = path.join(__dirname, '../../', 'node_modules', '.bin', 'electron'); +var electronPath = path.join(__dirname, "../../", "node_modules", ".bin", "electron"); -if (process.platform === 'win32') { - electronPath += '.cmd'; +if (process.platform === "win32") { + electronPath += ".cmd"; } -var appPath = path.join(__dirname, '../../js/electron.js'); +var appPath = path.join(__dirname, "../../js/electron.js"); var app = new Application({ path: electronPath, @@ -24,7 +24,7 @@ global.before(function () { chai.use(chaiAsPromised); }); -describe('Test enviroment app electron', function () { +describe("Test enviroment app electron", function () { this.timeout(10000); beforeEach(function (done) { @@ -36,14 +36,14 @@ describe('Test enviroment app electron', function () { }); - it('open a window app and test if is open', function () { + 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 () { + it("tests the title", function () { return app.client.waitUntilWindowLoaded() - .getTitle().should.eventually.equal('Magic Mirror'); + .getTitle().should.eventually.equal("Magic Mirror"); }); }); diff --git a/tests/e2e/modules/helloworld.js b/tests/e2e/modules/helloworld.js index 960917c3..ebf8a8d1 100644 --- a/tests/e2e/modules/helloworld.js +++ b/tests/e2e/modules/helloworld.js @@ -1,18 +1,18 @@ const Application = require("spectron").Application; -const path = require('path'); -const chai = require('chai'); -const chaiAsPromised = require('chai-as-promised'); +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'; +process.env.MM_CONFIG_FILE = "tests/confs/helloworld.js"; -var electronPath = path.join(__dirname, '../../../', 'node_modules', '.bin', 'electron'); +var electronPath = path.join(__dirname, "../../../", "node_modules", ".bin", "electron"); -if (process.platform === 'win32') { - electronPath += '.cmd'; +if (process.platform === "win32") { + electronPath += ".cmd"; } -var appPath = path.join(__dirname, '../../../js/electron.js'); +var appPath = path.join(__dirname, "../../../js/electron.js"); var app = new Application({ path: electronPath, @@ -24,7 +24,7 @@ global.before(function () { chai.use(chaiAsPromised); }); -describe('Test helloworld module', function () { +describe("Test helloworld module", function () { this.timeout(10000); beforeEach(function (done) { @@ -35,8 +35,8 @@ describe('Test helloworld module', function () { app.stop().then(function() { done(); }); }); - it('Test message helloworld module', function () { + it("Test message helloworld module", function () { return app.client.waitUntilWindowLoaded() - .getText('.helloworld').should.eventually.equal('Test HelloWorld Module'); + .getText(".helloworld").should.eventually.equal("Test HelloWorld Module"); }); });