From 55e75cf5e55472100176166039a9b5baed8903d4 Mon Sep 17 00:00:00 2001 From: Keerthi Niranjan Date: Tue, 13 Mar 2018 15:50:32 +0530 Subject: [PATCH] ELECTRON-357 (#321) - Skipping npm rebuild every time and only running it once. - Changed the time-out to 60000ms - Moved the require to global - Added done fail in all the catch functions - Removed unwanted require --- package.json | 4 +- tests/Search.test.js | 42 +++++----- tests/SearchUtils.test.js | 4 +- tests/activityDetection.test.js | 15 ++-- tests/spectron/alwaysOnTop.spectron.js | 61 +++++++------- tests/spectron/bringToFront.spectron.js | 34 ++++---- tests/spectron/clipboard.spectron.js | 11 +-- tests/spectron/close.spectron.js | 23 +++--- tests/spectron/full-screen.spectron.js | 53 ++++++------ tests/spectron/getVersionInfo.spectron.js | 13 ++- tests/spectron/minimize-on-close.spectron.js | 60 ++++++-------- .../spectron/notificationPosition.spectron.js | 80 +++++++++++-------- tests/spectron/spectronSetup.js | 2 +- tests/spectron/spellChecker.spectron.js | 28 +++---- tests/spectron/zoom-in-zoom-out.spectron.js | 53 ++++++------ 15 files changed, 223 insertions(+), 260 deletions(-) diff --git a/package.json b/package.json index afa708e7..6afcfb95 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "prebuild": "npm run rebuild && npm run browserify-preload", "browserify-preload": "browserify -o js/preload/_preloadMain.js -x electron --insert-global-vars=__filename,__dirname js/preload/preloadMain.js --exclude electron-spellchecker", "rebuild": "electron-rebuild -f", - "test": "npm run lint && jest --verbose --testPathPattern test && npm run rebuild", - "spectron-test": "jest --config tests/spectron/jest_spectron.json --runInBand && npm run rebuild", + "test": "npm run lint && npm rebuild --build-from-source && jest --verbose --testPathPattern test && npm run rebuild", + "spectron-test": "npm rebuild --build-from-source && jest --config tests/spectron/jest_spectron.json --runInBand && npm run rebuild", "lint": "eslint --ext .js js/", "rename-exe": "cd dist/win-unpacked && ren Symphony.exe Symphony-Electron.exe" }, diff --git a/tests/Search.test.js b/tests/Search.test.js index aba368c7..f8947e82 100644 --- a/tests/Search.test.js +++ b/tests/Search.test.js @@ -1,4 +1,3 @@ -const childProcess = require('child_process'); const path = require('path'); const fs = require('fs'); const { isWindowsOS } = require('../js/utils/misc.js'); @@ -37,32 +36,29 @@ describe('Tests for Search', function() { let tempBatchPath; let currentDate = new Date().getTime(); - jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; + jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; beforeAll(function (done) { - childProcess.exec(`npm rebuild --target=${process.version} --build-from-source`, function(err) { + userId = 12345678910112; + key = 'jjjehdnctsjyieoalskcjdhsnahsadndfnusdfsdfsd='; - userId = 12345678910112; - key = 'jjjehdnctsjyieoalskcjdhsnahsadndfnusdfsdfsd='; + executionPath = path.join(__dirname, 'library'); + if (isWindowsOS) { + executionPath = path.join(__dirname, '..', 'library'); + } + userConfigDir = path.join(__dirname, '..'); - executionPath = path.join(__dirname, 'library'); - if (isWindowsOS) { - executionPath = path.join(__dirname, '..', 'library'); - } - userConfigDir = path.join(__dirname, '..'); + searchConfig = require('../js/search/searchConfig.js'); + const { Search } = require('../js/search/search.js'); + SearchApi = new Search(userId, key); - searchConfig = require('../js/search/searchConfig.js'); - const { Search } = require('../js/search/search.js'); - SearchApi = new Search(userId, key); - - realTimeIndexPath = path.join(userConfigDir, 'data', 'temp_realtime_index'); - tempBatchPath = path.join(userConfigDir, 'data', 'temp_batch_indexes'); - dataFolderPath = path.join(userConfigDir, 'data'); - if (fs.existsSync(dataFolderPath)) { - deleteIndexFolders(dataFolderPath) - } - done(); - }); + realTimeIndexPath = path.join(userConfigDir, 'data', 'temp_realtime_index'); + tempBatchPath = path.join(userConfigDir, 'data', 'temp_batch_indexes'); + dataFolderPath = path.join(userConfigDir, 'data'); + if (fs.existsSync(dataFolderPath)) { + deleteIndexFolders(dataFolderPath) + } + done(); }); afterAll(function (done) { @@ -527,4 +523,4 @@ describe('Tests for Search', function() { }); }); }); -}); \ No newline at end of file +}); diff --git a/tests/SearchUtils.test.js b/tests/SearchUtils.test.js index eac2964b..ec24d3f1 100644 --- a/tests/SearchUtils.test.js +++ b/tests/SearchUtils.test.js @@ -29,7 +29,7 @@ function mockedGetPath(type) { describe('Tests for Search Utils', function() { - jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; + jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; beforeAll(function (done) { executionPath = path.join(__dirname, 'library'); @@ -167,4 +167,4 @@ describe('Tests for Search Utils', function() { }); }); -}); \ No newline at end of file +}); diff --git a/tests/activityDetection.test.js b/tests/activityDetection.test.js index fd6ee93b..c4b0c16e 100644 --- a/tests/activityDetection.test.js +++ b/tests/activityDetection.test.js @@ -1,19 +1,14 @@ const electron = require('./__mocks__/electron'); -const childProcess = require('child_process'); - -let activityDetection; +const activityDetection = require('../js/activityDetection'); describe('Tests for Activity Detection', function() { const originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; - jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; + jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000; beforeAll(function(done) { - childProcess.exec(`npm rebuild --target=${process.version} --build-from-source`, function(err) { - activityDetection = require('../js/activityDetection'); - activityDetection.setActivityWindow(900000, electron.ipcRenderer); - done(); - }); + activityDetection.setActivityWindow(900000, electron.ipcRenderer); + done(); }); beforeEach(function() { @@ -64,4 +59,4 @@ describe('Tests for Activity Detection', function() { }); -}); \ No newline at end of file +}); diff --git a/tests/spectron/alwaysOnTop.spectron.js b/tests/spectron/alwaysOnTop.spectron.js index 18c717ca..6c884752 100644 --- a/tests/spectron/alwaysOnTop.spectron.js +++ b/tests/spectron/alwaysOnTop.spectron.js @@ -1,10 +1,8 @@ const Application = require('./spectronSetup'); const {isMac} = require('../../js/utils/misc.js'); -const childProcess = require('child_process'); -const constants = require('./spectronConstants'); +const robot = require('robotjs'); let app = new Application({}); -let robot; let configPath; let mIsAlwaysOnTop; @@ -14,23 +12,16 @@ describe('Tests for Always on top', () => { jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); beforeAll((done) => { - childProcess.exec(`npm rebuild robotjs --target=${process.version} --build-from-source`, function () { - robot = require('robotjs'); - return app.startApplication().then((startedApp) => { - app = startedApp; - getConfigPath().then((config) => { - configPath = config; - done(); - }).catch((err) => { - console.error(`Unable to get user config path error: ${err}`); - expect(err).toBeNull(); - done(); - }); - }).catch((err) => { - console.error(`Unable to start application error: ${err}`); - expect(err).toBeNull(); + return app.startApplication().then((startedApp) => { + app = startedApp; + getConfigPath().then((config) => { + configPath = config; done(); + }).catch((err) => { + done.fail(new Error(`Unable to start application error: ${err}`)); }); + }).catch((err) => { + done.fail(new Error(`Unable to start application error: ${err}`)); }); }); @@ -57,8 +48,7 @@ describe('Tests for Always on top', () => { done(); }).catch((err) => { jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; - expect(err).toBeNull(); - done(); + done.fail(new Error(`alwaysOnTop failed in afterAll with error: ${err}`)); }); } }); @@ -70,23 +60,25 @@ describe('Tests for Always on top', () => { done(); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`alwaysOnTop failed in waitUntilWindowLoaded with error: ${err}`)); }); }); - it('should check window count', () => { + it('should check window count', (done) => { return app.client.getWindowCount().then((count) => { expect(count === 1).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`alwaysOnTop failed in getWindowCount with error: ${err}`)); }); }); - it('should check browser window visibility', () => { + it('should check browser window visibility', (done) => { return app.browserWindow.isVisible().then((isVisible) => { expect(isVisible).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`alwaysOnTop failed in isVisible with error: ${err}`)); }); }); @@ -116,25 +108,28 @@ describe('Tests for Always on top', () => { }); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`alwaysOnTop failed in setAlwaysOnTop with error: ${err}`)); }); } else { done(); } }); - it('should check is always on top', () => { + it('should check is always on top', (done) => { return Application.readConfig(configPath).then((userData) => { return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => { mIsAlwaysOnTop = isAlwaysOnTop; if (userData.alwaysOnTop) { expect(isAlwaysOnTop).toBeTruthy(); + done(); } else { expect(isAlwaysOnTop).toBeFalsy(); + done(); } + done(); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`alwaysOnTop failed in readConfig with error: ${err}`)); }); }); @@ -169,23 +164,25 @@ describe('Tests for Always on top', () => { done(); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`alwaysOnTop failed in getBounds with error: ${err}`)); }); } }); - it('should check is always on top to be true', () => { + it('should check is always on top to be true', (done) => { if (!mIsAlwaysOnTop) { return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => { expect(isAlwaysOnTop).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`alwaysOnTop failed in isAlwaysOnTop with error: ${err}`)); }); } else { return app.browserWindow.isAlwaysOnTop().then((isAlwaysOnTop) => { expect(isAlwaysOnTop).toBeFalsy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`alwaysOnTop failed in isAlwaysOnTop with error: ${err}`)); }); } }); diff --git a/tests/spectron/bringToFront.spectron.js b/tests/spectron/bringToFront.spectron.js index 609d48c4..4f686555 100644 --- a/tests/spectron/bringToFront.spectron.js +++ b/tests/spectron/bringToFront.spectron.js @@ -13,9 +13,7 @@ describe('Tests for Bring to front', () => { app = startedApp; done(); }).catch((err) => { - console.error(`Unable to start application error: ${err}`); - expect(err).toBeNull(); - done(); + done.fail(new Error(`Unable to start application error: ${err}`)); }); }); @@ -36,51 +34,55 @@ describe('Tests for Bring to front', () => { expect(count === 1).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`bringToFront failed in getWindowCount with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`bringToFront failed in waitUntilWindowLoaded with error: ${err}`)); }); }); - it('should minimize the app', () => { + it('should minimize the app', (done) => { return app.browserWindow.minimize().then(() => { return app.browserWindow.isMinimized().then((isMinimized) => { expect(isMinimized).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`bringToFront failed in isMinimized with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`bringToFront failed in minimize with error: ${err}`)); }); }); - it('should not be focused', () => { + it('should not be focused', (done) => { return app.browserWindow.isFocused().then((isFocused) => { expect(isFocused).toBeFalsy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`bringToFront failed in isFocused with error: ${err}`)); }); }); - it('should maximize browser window', () => { + it('should maximize browser window', (done) => { return app.browserWindow.restore().then(() => { return app.browserWindow.isMinimized().then((isMinimized) => { expect(isMinimized).toBeFalsy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`bringToFront failed in isMinimized with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`bringToFront failed in restore with error: ${err}`)); }); }); - it('should be focused', () => { + it('should be focused', (done) => { return app.browserWindow.isFocused().then((isFocused) => { expect(isFocused).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`bringToFront failed in isFocused with error: ${err}`)); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spectron/clipboard.spectron.js b/tests/spectron/clipboard.spectron.js index 5458c136..67327fcb 100644 --- a/tests/spectron/clipboard.spectron.js +++ b/tests/spectron/clipboard.spectron.js @@ -1,6 +1,5 @@ const Application = require('./spectronSetup'); const path = require('path'); -const constants = require('./spectronConstants'); let app = new Application({}); @@ -14,9 +13,7 @@ describe('Tests for clipboard', () => { app = startedApp; done(); }).catch((err) => { - console.error(`Unable to start application error: ${err}`); - expect(err).toBeNull(); - done(); + done.fail(new Error(`Unable to start application error: ${err}`)); }); }); @@ -37,10 +34,10 @@ describe('Tests for clipboard', () => { expect(count === 1).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeFalsy(); + done.fail(new Error(`clipboard failed in getWindowCount with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeFalsy(); + done.fail(new Error(`clipboard failed in waitUntilWindowLoaded with error: ${err}`)); }); }); @@ -75,4 +72,4 @@ describe('Tests for clipboard', () => { }); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spectron/close.spectron.js b/tests/spectron/close.spectron.js index 67107b06..ca49ee58 100644 --- a/tests/spectron/close.spectron.js +++ b/tests/spectron/close.spectron.js @@ -1,21 +1,18 @@ const Application = require('./spectronSetup'); -const constants = require('./spectronConstants'); let app = new Application({}); describe('Tests for Close', () => { let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; - jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; + jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); beforeAll((done) => { return app.startApplication().then((startedApp) => { app = startedApp; done(); }).catch((err) => { - console.error(`Unable to start application error: ${err}`); - expect(err).toBeNull(); - done(); + done.fail(new Error(`Unable to start application error: ${err}`)); }); }); @@ -38,26 +35,28 @@ describe('Tests for Close', () => { expect(count === 1).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`close failed in getWindowCount with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`close failed in waitUntilWindowLoaded with error: ${err}`)); }); }); - it('should check window count', () => { + it('should check window count', (done) => { return app.client.getWindowCount().then((count) => { expect(count === 1).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`close failed in getWindowCount with error: ${err}`)); }); }); - it('should check browser window visibility', () => { + it('should check browser window visibility', (done) => { return app.browserWindow.isVisible().then((isVisible) => { expect(isVisible).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`close failed in isVisible with error: ${err}`)); }); }); @@ -69,4 +68,4 @@ describe('Tests for Close', () => { expect(app.isRunning()).toBe(false); }); -}); \ No newline at end of file +}); diff --git a/tests/spectron/full-screen.spectron.js b/tests/spectron/full-screen.spectron.js index ec75db6e..4694cd70 100644 --- a/tests/spectron/full-screen.spectron.js +++ b/tests/spectron/full-screen.spectron.js @@ -1,35 +1,26 @@ -const childProcess = require('child_process'); const Application = require('./spectronSetup'); const { isMac } = require('../../js/utils/misc'); -const constants = require('./spectronConstants'); +const robot = require('robotjs'); -let robot; let configPath; let app = new Application({}); describe('Tests for Full screen', () => { let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; - jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; + jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); beforeAll((done) => { - childProcess.exec(`npm rebuild robotjs --target=${process.version} --build-from-source`, function () { - robot = require('robotjs'); - return app.startApplication().then((startedApp) => { - app = startedApp; - getConfigPath().then((config) => { - configPath = config; - done(); - }).catch((err) => { - console.error(`Unable to get user config path error: ${err}`); - expect(err).toBeNull(); - done(); - }); - }).catch((err) => { - console.error(`Unable to start application error: ${err}`); - expect(err).toBeNull(); + return app.startApplication().then((startedApp) => { + app = startedApp; + getConfigPath().then((config) => { + configPath = config; done(); + }).catch((err) => { + done.fail(new Error(`full-screen failed in getConfigPath with error: ${err}`)); }); + }).catch((err) => { + done.fail(new Error(`Unable to start application error: ${err}`)); }); }); @@ -73,26 +64,28 @@ describe('Tests for Full screen', () => { expect(count === 1).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`full-screen failed in getWindowCount with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`full-screen failed in waitUntilWindowLoaded with error: ${err}`)); }); }); - it('should check window count', () => { + it('should check window count', (done) => { return app.client.getWindowCount().then((count) => { expect(count === 1).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`full-screen failed in getWindowCount with error: ${err}`)); }); }); - it('should check browser window visibility', () => { + it('should check browser window visibility', (done) => { return app.browserWindow.isVisible().then((isVisible) => { expect(isVisible).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`full-screen failed in getWindowCount with error: ${err}`)); }); }); @@ -105,7 +98,7 @@ describe('Tests for Full screen', () => { }); }); - it('should set the app full screen and check whether it is in full screen', () => { + it('should set the app full screen and check whether it is in full screen', (done) => { if (isMac) { robot.setMouseDelay(100); robot.moveMouseSmooth(205, 10); @@ -121,8 +114,9 @@ describe('Tests for Full screen', () => { return app.browserWindow.isFullScreen().then((fullscreen) => { expect(fullscreen).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`full-screen failed in isFullScreen with error: ${err}`)); }) } else { return app.browserWindow.getBounds().then((bounds) => { @@ -136,10 +130,11 @@ describe('Tests for Full screen', () => { return app.browserWindow.isFullScreen().then((fullscreen) => { expect(fullscreen).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`full-screen failed in isFullScreen with error: ${err}`)); }) }); } }); -}); \ No newline at end of file +}); diff --git a/tests/spectron/getVersionInfo.spectron.js b/tests/spectron/getVersionInfo.spectron.js index 351659b0..40e8c075 100644 --- a/tests/spectron/getVersionInfo.spectron.js +++ b/tests/spectron/getVersionInfo.spectron.js @@ -1,6 +1,7 @@ const Application = require('./spectronSetup'); const path = require('path'); const { buildNumber } = require('../../package'); +const electronVersion = require('../../package').devDependencies.electron; const bluebird = require('bluebird'); let app = new Application({}); @@ -15,9 +16,7 @@ describe('Tests for getVersionInfo API', () => { app = startedApp; done(); }).catch((err) => { - console.error(`Unable to start application error: ${err}`); - expect(err).toBeNull(); - done(); + done.fail(new Error(`Unable to start application error: ${err}`)); }); }); @@ -38,10 +37,10 @@ describe('Tests for getVersionInfo API', () => { expect(count === 1).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`getVersionInfo failed in getWindowCount with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`getVersionInfo failed in waitUntilWindowLoaded with error: ${err}`)); }); }); @@ -63,9 +62,9 @@ describe('Tests for getVersionInfo API', () => { }).then((values) => { expect(values[ 0 ]).toBe('1.0.0'); expect(values[ 1 ]).toBe('Electron'); - expect(values[ 2 ]).toBe('1.8.3'); + expect(values[ 2 ]).toBe(electronVersion); expect(values[ 3 ]).toBe(buildNumber); done(); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spectron/minimize-on-close.spectron.js b/tests/spectron/minimize-on-close.spectron.js index fb955388..49fd6d05 100644 --- a/tests/spectron/minimize-on-close.spectron.js +++ b/tests/spectron/minimize-on-close.spectron.js @@ -1,35 +1,26 @@ -const childProcess = require('child_process'); const Application = require('./spectronSetup'); const { isMac } = require('../../js/utils/misc'); -const constants = require('./spectronConstants'); +const robot = require('robotjs'); -let robot; let configPath; let app = new Application({}); describe('Tests for Minimize on Close', () => { let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; - jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; + jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); beforeAll((done) => { - childProcess.exec(`npm rebuild robotjs --target=${process.version} --build-from-source`, function () { - robot = require('robotjs'); - return app.startApplication().then((startedApp) => { - app = startedApp; - getConfigPath().then((config) => { - configPath = config; - done(); - }).catch((err) => { - console.error(`Unable to get user config path error: ${err}`); - expect(err).toBeNull(); - done(); - }); - }).catch((err) => { - console.error(`Unable to start application error: ${err}`); - expect(err).toBeNull(); + return app.startApplication().then((startedApp) => { + app = startedApp; + getConfigPath().then((config) => { + configPath = config; done(); + }).catch((err) => { + done.fail(new Error(`Unable to start application error: ${err}`)); }); + }).catch((err) => { + done.fail(new Error(`Unable to start application error: ${err}`)); }); }); @@ -73,26 +64,28 @@ describe('Tests for Minimize on Close', () => { expect(count === 1).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`minimize-on-close failed in getWindowCount with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`minimize-on-close failed in waitUntilWindowLoaded with error: ${err}`)); }); }); - it('should check window count', () => { + it('should check window count', (done) => { return app.client.getWindowCount().then((count) => { expect(count === 1).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`minimize-on-close failed in getWindowCount with error: ${err}`)); }); }); - it('should check browser window visibility', () => { + it('should check browser window visibility', (done) => { return app.browserWindow.isVisible().then((isVisible) => { expect(isVisible).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`minimize-on-close failed in isVisible with error: ${err}`)); }); }); @@ -117,8 +110,7 @@ describe('Tests for Minimize on Close', () => { expect(minimized).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeNull(); - done(); + done.fail(new Error(`minimize-on-close failed in isMinimized with error: ${err}`)); }); } else { @@ -141,8 +133,7 @@ describe('Tests for Minimize on Close', () => { expect(minimized).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeNull(); - done(); + done.fail(new Error(`minimize-on-close failed in isMinimized with error: ${err}`)); }); } } else { @@ -167,8 +158,7 @@ describe('Tests for Minimize on Close', () => { expect(minimized).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeNull(); - done(); + done.fail(new Error(`minimize-on-close failed in isMinimized with error: ${err}`)); }); }); } else { @@ -185,16 +175,14 @@ describe('Tests for Minimize on Close', () => { expect(minimized).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeNull(); - done(); + done.fail(new Error(`minimize-on-close failed in isMinimized with error: ${err}`)); }); }); } } }).catch((err) => { - expect(err).toBeNull(); - done(); + done.fail(new Error(`minimize-on-close failed in readConfig with error: ${err}`)); }) }); -}); \ No newline at end of file +}); diff --git a/tests/spectron/notificationPosition.spectron.js b/tests/spectron/notificationPosition.spectron.js index d20582ce..71579225 100644 --- a/tests/spectron/notificationPosition.spectron.js +++ b/tests/spectron/notificationPosition.spectron.js @@ -1,7 +1,6 @@ const Application = require('./spectronSetup'); const path = require('path'); const { isMac } = require('../../js/utils/misc'); -const constants = require('./spectronConstants'); let app = new Application({}); @@ -15,9 +14,7 @@ describe('Tests for Notification position', () => { app = startedApp; done(); }).catch((err) => { - console.error(`Unable to start application error: ${err}`); - expect(err).toBeNull(); - done(); + done.fail(new Error(`Unable to start application error: ${err}`)); }); }); @@ -38,10 +35,10 @@ describe('Tests for Notification position', () => { expect(count === 1).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in getWindowCount with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in waitUntilWindowLoaded with error: ${err}`)); }); }); @@ -49,15 +46,16 @@ describe('Tests for Notification position', () => { return app.client.url('file:///' + path.join(__dirname, '..', '..', 'demo/index.html')); }); - it('should load demo html', () => { + it('should load demo html', (done) => { return app.client.waitUntilWindowLoaded().then(() => { return app.client.getTitle().then((title) => { expect(title === '').toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in getTitle with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in waitUntilWindowLoaded with error: ${err}`)); }); }); @@ -72,32 +70,35 @@ describe('Tests for Notification position', () => { .windowByIndex(1) }); - it('should check notification position', () => { + it('should check notification position', (done) => { return app.browserWindow.getBounds().then((bounds) => { expect(bounds.x === 0).toBeTruthy(); if (isMac) { expect(bounds.y > 0).toBeTruthy(); + done(); } else { expect(bounds.y === 0).toBeTruthy(); + done(); } }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in getBounds with error: ${err}`)); }); }); - it('should change the window', () => { + it('should change the window', (done) => { return app.client.windowByIndex(0).then(() => { return app.browserWindow.getTitle().then((title) => { expect(title === 'Symphony | Secure Seamless Communication').toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in getTitle with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in windowByIndex with error: ${err}`)); }); }); - it('should change notification position to lower-right', () => { + it('should change notification position to lower-right', (done) => { return app.client .click('#open-config-win') .windowByIndex(2) @@ -108,36 +109,39 @@ describe('Tests for Notification position', () => { .windowByIndex(1).then(() => { return app.browserWindow.getTitle().then((title) => { expect(title === 'Electron').toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in getTitle with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in windowByIndex with error: ${err}`)); }); }); - it('should check notification position and equal to lower-right', () => { + it('should check notification position and equal to lower-right', (done) => { return app.browserWindow.getBounds().then((bounds) => { expect(bounds.x > 0).toBeTruthy(); expect(bounds.y > 0).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in getBounds with error: ${err}`)); }); }); - it('should change the window', () => { + it('should change the window', (done) => { return app.client.windowByIndex(0).then(() => { return app.browserWindow.getTitle().then((title) => { expect(title === 'Symphony | Secure Seamless Communication').toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in getTitle with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in windowByIndex with error: ${err}`)); }); }); - it('should change notification position to upper-right', () => { + it('should change notification position to upper-right', (done) => { return app.client .click('#open-config-win') .windowByIndex(2) @@ -148,57 +152,63 @@ describe('Tests for Notification position', () => { .windowByIndex(1).then(() => { return app.browserWindow.getTitle().then((title) => { expect(title === 'Electron').toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in getTitle with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in windowByIndex with error: ${err}`)); }); }); - it('should check notification position and equal to upper-right', () => { + it('should check notification position and equal to upper-right', (done) => { return app.browserWindow.getBounds().then((bounds) => { expect(bounds.x > 0).toBeTruthy(); if (isMac) { expect(bounds.y > 0).toBeTruthy(); + done(); } else { expect(bounds.y === 0).toBeTruthy(); + done(); } }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in getBounds with error: ${err}`)); }); }); - it('should change the window to main', () => { + it('should change the window to main', (done) => { return app.client.windowByIndex(0).then(() => { return app.browserWindow.getTitle().then((title) => { expect(title === 'Symphony | Secure Seamless Communication').toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in getTitle with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in windowByIndex with error: ${err}`)); }); }); - it('should open notification and close', () => { + it('should open notification and close', (done) => { return app.client .windowByIndex(0) .click('#notf') .getWindowCount().then((count) => { expect(count === 3).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in getWindowCount with error: ${err}`)); }) .windowByIndex(1).then(() => { return app.browserWindow.getTitle().then((title) => { expect(title === 'Electron').toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in getTitle with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`notificationPosition failed in windowByIndex with error: ${err}`)); }); }); -}); \ No newline at end of file +}); diff --git a/tests/spectron/spectronSetup.js b/tests/spectron/spectronSetup.js index 69daa235..ee0582e8 100644 --- a/tests/spectron/spectronSetup.js +++ b/tests/spectron/spectronSetup.js @@ -113,4 +113,4 @@ class App { } -module.exports = App; \ No newline at end of file +module.exports = App; diff --git a/tests/spectron/spellChecker.spectron.js b/tests/spectron/spellChecker.spectron.js index 766cfeb2..6750a939 100644 --- a/tests/spectron/spellChecker.spectron.js +++ b/tests/spectron/spellChecker.spectron.js @@ -1,11 +1,8 @@ const Application = require('./spectronSetup'); const path = require('path'); const {isMac} = require('../../js/utils/misc.js'); -const childProcess = require('child_process'); -const constants = require('./spectronConstants'); - +const robot = require('robotjs'); let app = new Application({}); -let robot; describe('Tests for spellChecker', () => { @@ -13,16 +10,11 @@ describe('Tests for spellChecker', () => { jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); beforeAll((done) => { - childProcess.exec(`npm rebuild robotjs --target=${process.version} --build-from-source`, () => { - robot = require('robotjs'); - app.startApplication().then((startedApp) => { - app = startedApp; - done(); - }).catch((err) => { - console.error(`Unable to start application error: ${err}`); - expect(err).toBeNull(); - done(); - }); + app.startApplication().then((startedApp) => { + app = startedApp; + done(); + }).catch((err) => { + done.fail(new Error(`Unable to start application error: ${err}`)); }); }); @@ -43,12 +35,10 @@ describe('Tests for spellChecker', () => { expect(count === 1).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeFalsy(); - done(); + done.fail(new Error(`spellChecker failed in getWindowCount with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeFalsy(); - done(); + done.fail(new Error(`spellChecker failed in waitUntilWindowLoaded with error: ${err}`)); }); }); @@ -122,4 +112,4 @@ describe('Tests for spellChecker', () => { }); }); -}); \ No newline at end of file +}); diff --git a/tests/spectron/zoom-in-zoom-out.spectron.js b/tests/spectron/zoom-in-zoom-out.spectron.js index 3ddf3467..f2efb3c0 100644 --- a/tests/spectron/zoom-in-zoom-out.spectron.js +++ b/tests/spectron/zoom-in-zoom-out.spectron.js @@ -1,9 +1,7 @@ -const childProcess = require('child_process'); const Application = require('./spectronSetup'); const { isMac } = require('../../js/utils/misc'); -const constants = require('./spectronConstants'); +const robot = require('robotjs'); -let robot; let configPath; let app = new Application({}); @@ -11,26 +9,19 @@ let app = new Application({}); describe('Tests for Zoom in and Zoom out', () => { let originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; - jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000; + jasmine.DEFAULT_TIMEOUT_INTERVAL = Application.getTimeOut(); beforeAll((done) => { - childProcess.exec(`npm rebuild robotjs --target=${process.version} --build-from-source`, function () { - robot = require('robotjs'); - return app.startApplication().then((startedApp) => { - app = startedApp; - getConfigPath().then((config) => { - configPath = config; - done(); - }).catch((err) => { - console.error(`Unable to get user config path error: ${err}`); - expect(err).toBeNull(); - done(); - }); - }).catch((err) => { - console.error(`Unable to start application error: ${err}`); - expect(err).toBeNull(); + return app.startApplication().then((startedApp) => { + app = startedApp; + getConfigPath().then((config) => { + configPath = config; done(); + }).catch((err) => { + done.fail(new Error(`Unable to start application error: ${err}`)); }); + }).catch((err) => { + done.fail(new Error(`Unable to start application error: ${err}`)); }); }); @@ -74,26 +65,28 @@ describe('Tests for Zoom in and Zoom out', () => { expect(count === 1).toBeTruthy(); done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`zoom-in-zoom-out failed in getWindowCount with error: ${err}`)); }); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`zoom-in-zoom-out failed in waitUntilWindowLoaded with error: ${err}`)); }); }); - it('should check window count', () => { + it('should check window count', (done) => { return app.client.getWindowCount().then((count) => { expect(count === 1).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`zoom-in-zoom-out failed in waitUntilWindowLoaded with error: ${err}`)); }); }); - it('should check browser window visibility', () => { + it('should check browser window visibility', (done) => { return app.browserWindow.isVisible().then((isVisible) => { expect(isVisible).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`zoom-in-zoom-out failed in isVisible with error: ${err}`)); }); }); @@ -106,7 +99,7 @@ describe('Tests for Zoom in and Zoom out', () => { }); }); - it('should zoom in the app and check whether it is zoomed in', () => { + it('should zoom in the app and check whether it is zoomed in', (done) => { robot.setKeyboardDelay(500); if (isMac) { @@ -122,8 +115,9 @@ describe('Tests for Zoom in and Zoom out', () => { return app.electron.webFrame.getZoomFactor().then((zoomFactor) => { expect(zoomFactor > 1).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`zoom-in-zoom-out failed in getZoomFactor with error: ${err}`)); }) } else { return app.browserWindow.getBounds().then((bounds) => { @@ -146,8 +140,9 @@ describe('Tests for Zoom in and Zoom out', () => { return app.electron.webFrame.getZoomFactor().then((zoomFactor) => { expect(zoomFactor > 1).toBeTruthy(); + done(); }).catch((err) => { - expect(err).toBeNull(); + done.fail(new Error(`zoom-in-zoom-out failed in getBounds with error: ${err}`)); }) }); } @@ -200,4 +195,4 @@ describe('Tests for Zoom in and Zoom out', () => { }); } }); -}); \ No newline at end of file +});