From 763d27aa8d3234d85bb18c2153c7d60af988b0e1 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Thu, 6 Jul 2017 17:06:16 +0530 Subject: [PATCH] Refactored spectron tests --- tests/alwaysOnTop.test.js | 9 ++--- tests/bringToFront.test.js | 45 +++++++++++----------- tests/clipboard.test.js | 8 ++-- tests/notificationPosition.test.js | 8 ++-- tests/{utils => spectron}/spectronSetup.js | 8 +++- 5 files changed, 38 insertions(+), 40 deletions(-) rename tests/{utils => spectron}/spectronSetup.js (82%) diff --git a/tests/alwaysOnTop.test.js b/tests/alwaysOnTop.test.js index ba3870c8..f5b9246e 100644 --- a/tests/alwaysOnTop.test.js +++ b/tests/alwaysOnTop.test.js @@ -1,13 +1,12 @@ +const Application = require('./spectron/spectronSetup'); +let app = new Application({}); + describe('Tests for Always on top', () => { let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; - jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; - - let app; + jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); beforeAll((done) => { - const Application = require('./utils/spectronSetup'); - app = new Application({}); return app.startApplication().then((startedApp) => { app = startedApp; done(); diff --git a/tests/bringToFront.test.js b/tests/bringToFront.test.js index a33ab4ce..be33c7e0 100644 --- a/tests/bringToFront.test.js +++ b/tests/bringToFront.test.js @@ -1,18 +1,17 @@ +const Application = require('./spectron/spectronSetup'); +let app = new Application({}); + describe('Tests for Bring to front', () => { let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; - jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; - - let app; + jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); beforeAll((done) => { - const Application = require('./utils/spectronSetup'); - app = new Application({}); return app.startApplication().then((startedApp) => { app = startedApp; done(); - }).catch(() => { - expect(true).toBe(false); + }).catch((err) => { + expect(err).toBeNull(); }); }); @@ -33,11 +32,11 @@ describe('Tests for Bring to front', () => { return app.client.getWindowCount().then((count) => { expect(count === 1).toBeTruthy(); done(); - }).catch(() => { - expect(true).toBe(false); + }).catch((err) => { + expect(err).toBeNull(); }); - }).catch(() => { - expect(true).toBe(false); + }).catch((err) => { + expect(err).toBeNull(); }); }); @@ -45,19 +44,19 @@ describe('Tests for Bring to front', () => { return app.browserWindow.minimize().then(() => { return app.browserWindow.isMinimized().then((isMinimized) => { expect(isMinimized).toBeTruthy(); - }).catch(() => { - expect(true).toBe(false); + }).catch((err) => { + expect(err).toBeNull(); }); - }).catch(() => { - expect(true).toBe(false); + }).catch((err) => { + expect(err).toBeNull(); }); }); it('should not be focused', () => { return app.browserWindow.isFocused().then((isFocused) => { expect(isFocused).toBeFalsy(); - }).catch(() => { - expect(true).toBe(false); + }).catch((err) => { + expect(err).toBeNull(); }); }); @@ -65,19 +64,19 @@ describe('Tests for Bring to front', () => { return app.browserWindow.restore().then(async () => { return app.browserWindow.isMinimized().then((isMinimized) => { expect(isMinimized).toBeFalsy(); - }).catch(() => { - expect(true).toBe(false); + }).catch((err) => { + expect(err).toBeNull(); }); - }).catch(() => { - expect(true).toBe(false); + }).catch((err) => { + expect(err).toBeNull(); }); }); it('should be focused', () => { return app.browserWindow.isFocused().then((isFocused) => { expect(isFocused).toBeTruthy(); - }).catch(() => { - expect(true).toBe(false); + }).catch((err) => { + expect(err).toBeNull(); }); }); diff --git a/tests/clipboard.test.js b/tests/clipboard.test.js index ca74ac19..98200f89 100644 --- a/tests/clipboard.test.js +++ b/tests/clipboard.test.js @@ -1,15 +1,13 @@ +const Application = require('./spectron/spectronSetup'); const path = require('path'); +let app = new Application({}); describe('Tests for clipboard', () => { let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; - jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; - - let app; + jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); beforeAll((done) => { - const Application = require('./utils/spectronSetup'); - app = new Application({}); return app.startApplication().then((startedApp) => { app = startedApp; done(); diff --git a/tests/notificationPosition.test.js b/tests/notificationPosition.test.js index fb8a3065..b196700d 100644 --- a/tests/notificationPosition.test.js +++ b/tests/notificationPosition.test.js @@ -1,15 +1,13 @@ -const Application = require('./utils/spectronSetup'); +const Application = require('./spectron/spectronSetup'); const path = require('path'); +let app = new Application({}); describe('Tests for Notification position', () => { let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; - jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; - - let app; + jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); beforeAll((done) => { - app = new Application({}); return app.startApplication().then((startedApp) => { app = startedApp; done(); diff --git a/tests/utils/spectronSetup.js b/tests/spectron/spectronSetup.js similarity index 82% rename from tests/utils/spectronSetup.js rename to tests/spectron/spectronSetup.js index 78df2b46..4c6401b2 100644 --- a/tests/utils/spectronSetup.js +++ b/tests/spectron/spectronSetup.js @@ -7,7 +7,7 @@ class App { this.options = options; - if (!this.options.path){ + if (!this.options.path) { this.options.path = App.getAppPath(); this.options.args = [path.join(__dirname, '..', '..', 'js/main.js')]; } @@ -16,7 +16,7 @@ class App { } startApplication() { - return this.app.start().then((app) =>{ + return this.app.start().then((app) => { return app; }).catch((err) => { console.log(err); @@ -31,6 +31,10 @@ class App { return electronPath } + static getTimeOut() { + return 90000 + } + } module.exports = App; \ No newline at end of file