From 3773d402014893d62b5663d5dda7c9a6382d85a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Sun, 19 Feb 2017 21:06:38 -0300 Subject: [PATCH] Refactoring some e2e tests. Now is use a global-setup instead of repeat repeat code to setup tests enviroment. --- tests/e2e/env_spec.js | 24 ++----------------- tests/e2e/global-setup.js | 34 +++++++++++++++++++++++++++ tests/e2e/modules/clock_es_spec.js | 24 ++----------------- tests/e2e/modules/clock_spec.js | 24 ++----------------- tests/e2e/modules/compliments_spec.js | 23 ++---------------- tests/e2e/modules/helloworld_spec.js | 24 ++----------------- 6 files changed, 44 insertions(+), 109 deletions(-) create mode 100644 tests/e2e/global-setup.js diff --git a/tests/e2e/env_spec.js b/tests/e2e/env_spec.js index 4a6bbaef..99a7f657 100644 --- a/tests/e2e/env_spec.js +++ b/tests/e2e/env_spec.js @@ -1,25 +1,5 @@ -const Application = require("spectron").Application; -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 globalSetup = require("./global-setup"); +const app = globalSetup.app; describe("Electron app environment", function () { this.timeout(20000); diff --git a/tests/e2e/global-setup.js b/tests/e2e/global-setup.js new file mode 100644 index 00000000..7b94ec40 --- /dev/null +++ b/tests/e2e/global-setup.js @@ -0,0 +1,34 @@ +/* + * Magic Mirror + * + * Global Setup Test Suite + * + * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com + * MIT Licensed. + * +*/ + +const Application = require("spectron").Application; +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); +}); + +exports.app = app; diff --git a/tests/e2e/modules/clock_es_spec.js b/tests/e2e/modules/clock_es_spec.js index 4b44d9e7..f90263cf 100644 --- a/tests/e2e/modules/clock_es_spec.js +++ b/tests/e2e/modules/clock_es_spec.js @@ -1,25 +1,5 @@ -const Application = require("spectron").Application; -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 globalSetup = require("../global-setup"); +const app = globalSetup.app; describe("Clock set to spanish language module", function () { this.timeout(20000); diff --git a/tests/e2e/modules/clock_spec.js b/tests/e2e/modules/clock_spec.js index e2f5cd27..8c6d9ff6 100644 --- a/tests/e2e/modules/clock_spec.js +++ b/tests/e2e/modules/clock_spec.js @@ -1,25 +1,5 @@ -const Application = require("spectron").Application; -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 globalSetup = require("../global-setup"); +const app = globalSetup.app; describe("Clock module", function () { this.timeout(20000); diff --git a/tests/e2e/modules/compliments_spec.js b/tests/e2e/modules/compliments_spec.js index 794ed400..c09a9068 100644 --- a/tests/e2e/modules/compliments_spec.js +++ b/tests/e2e/modules/compliments_spec.js @@ -1,26 +1,7 @@ -const Application = require("spectron").Application; -const path = require("path"); +const globalSetup = require("../global-setup"); +const app = globalSetup.app; const chai = require("chai"); const expect = chai.expect; -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); -}); describe("Compliments module", function () { this.timeout(20000); diff --git a/tests/e2e/modules/helloworld_spec.js b/tests/e2e/modules/helloworld_spec.js index d567edad..f956effb 100644 --- a/tests/e2e/modules/helloworld_spec.js +++ b/tests/e2e/modules/helloworld_spec.js @@ -1,25 +1,5 @@ -const Application = require("spectron").Application; -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 globalSetup = require("../global-setup"); +const app = globalSetup.app; describe("Test helloworld module", function () { this.timeout(20000);