From 96b51229885562ef9bdb84c53ca4776dbe6b7f0d Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Wed, 29 Mar 2017 00:14:42 +0900 Subject: [PATCH] Stop using chai-as-promised due to its license For #488 --- package.json | 1 - test/modules/environment.js | 7 +-- test/specs/app_test.js | 14 +++--- test/specs/browser/index_test.js | 34 +++++++-------- test/specs/browser/settings_test.js | 68 ++++++++++++++--------------- test/specs/security_test.js | 14 +++--- 6 files changed, 68 insertions(+), 70 deletions(-) diff --git a/package.json b/package.json index 21e59b24..3053d169 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "babel-plugin-transform-object-rest-spread": "^6.23.0", "babel-preset-react": "^6.23.0", "chai": "^3.5.0", - "chai-as-promised": "^6.0.0", "cross-env": "^3.1.4", "devtron": "^1.4.0", "electron": "1.6.1", diff --git a/test/modules/environment.js b/test/modules/environment.js index cd05b1ea..ffe8abc7 100644 --- a/test/modules/environment.js +++ b/test/modules/environment.js @@ -1,10 +1,7 @@ 'use strict'; const chai = require('chai'); -const chaiAsPromised = require('chai-as-promised'); - chai.should(); -chai.use(chaiAsPromised); const fs = require('fs'); const path = require('path'); @@ -42,12 +39,10 @@ module.exports = { }, getSpectronApp() { - const app = new Application({ + return new Application({ path: electronBinaryPath, args: [`${path.join(sourceRootDir, 'src')}`, `--data-dir=${userDataDir}`, '--disable-dev-mode'] }); - chaiAsPromised.transferPromiseness = app.transferPromiseness; - return app; }, addClientCommands(client) { diff --git a/test/specs/app_test.js b/test/specs/app_test.js index bd547d15..2efa9a8d 100644 --- a/test/specs/app_test.js +++ b/test/specs/app_test.js @@ -26,9 +26,9 @@ describe('application', function desc() { return this.app.start().then(() => { return this.app.client. waitUntilWindowLoaded(). - getWindowCount().should.eventually.equal(1). - browserWindow.isDevToolsOpened().should.eventually.be.false. - browserWindow.isVisible().should.eventually.be.true; + getWindowCount().then((count) => count.should.equal(1)). + browserWindow.isDevToolsOpened().then((opened) => opened.should.be.false). + browserWindow.isVisible().then((visible) => visible.should.be.true); }); }); @@ -68,8 +68,8 @@ describe('application', function desc() { return this.app.start().then(() => { return this.app.client. waitUntilWindowLoaded(). - getUrl().should.eventually.match(/\/settings.html$/). - isExisting('#newServerModal').should.eventually.equal(true); + getUrl().then((url) => url.should.match(/\/settings.html$/)). + isExisting('#newServerModal').then((existing) => existing.should.equal(true)); }); }); @@ -80,7 +80,7 @@ describe('application', function desc() { return this.app.start().then(() => { return this.app.client. waitUntilWindowLoaded(). - getUrl().should.eventually.match(/\/index.html$/); + getUrl().then((url) => url.should.match(/\/index.html$/)); }); }); @@ -92,7 +92,7 @@ describe('application', function desc() { return this.app.start().then(() => { return this.app.client. waitUntilWindowLoaded(). - getUrl().should.eventually.match(/\/index.html$/); + getUrl().then((url) => url.should.match(/\/index.html$/)); }).then(() => { var str = fs.readFileSync(env.configFilePath, 'utf8'); var config = JSON.parse(str); diff --git a/test/specs/browser/index_test.js b/test/specs/browser/index_test.js index c5905d68..789cd041 100644 --- a/test/specs/browser/index_test.js +++ b/test/specs/browser/index_test.js @@ -55,31 +55,31 @@ describe('browser/index.html', function desc() { })); return this.app.restart().then(() => { return this.app.client.waitUntilWindowLoaded(). - isExisting('#tabBar').should.eventually.be.false; + isExisting('#tabBar').then((existing) => existing.should.be.false); }); }); it('should set src of webview from config file', () => { return this.app.client.waitUntilWindowLoaded(). - getAttribute('#mattermostView0', 'src').should.eventually.equal(config.teams[0].url). - getAttribute('#mattermostView1', 'src').should.eventually.equal(config.teams[1].url). - isExisting('#mattermostView2').should.eventually.be.false; + getAttribute('#mattermostView0', 'src').then((src) => src.should.equal(config.teams[0].url)). + getAttribute('#mattermostView1', 'src').then((src) => src.should.equal(config.teams[1].url)). + isExisting('#mattermostView2').then((existing) => existing.should.be.false); }); it('should set name of tab from config file', () => { return this.app.client.waitUntilWindowLoaded(). - getText('#teamTabItem0').should.eventually.equal(config.teams[0].name). - getText('#teamTabItem1').should.eventually.equal(config.teams[1].name); + getText('#teamTabItem0').then((text) => text.should.equal(config.teams[0].name)). + getText('#teamTabItem1').then((text) => text.should.equal(config.teams[1].name)); }); it('should show only the selected team', () => { return this.app.client.waitUntilWindowLoaded(). - isVisible('#mattermostView0').should.eventually.be.true. - isVisible('#mattermostView1').should.eventually.be.false. + isVisible('#mattermostView0').then((visible) => visible.should.be.true). + isVisible('#mattermostView1').then((visible) => visible.should.be.false). click('#teamTabItem1'). pause(1000). - isVisible('#mattermostView1').should.eventually.be.true. - isVisible('#mattermostView0').should.eventually.be.false; + isVisible('#mattermostView1').then((visible) => visible.should.be.true). + isVisible('#mattermostView0').then((visible) => visible.should.be.false); }); it('should show error when using incorrect URL', () => { @@ -108,8 +108,8 @@ describe('browser/index.html', function desc() { return this.app.restart().then(() => { return this.app.client.waitUntilWindowLoaded().pause(1500); }).then(() => { - return this.app.browserWindow.getTitle().should.eventually.equal('Mattermost Desktop testing html'); - }); + return this.app.browserWindow.getTitle(); + }).then((title) => title.should.equal('Mattermost Desktop testing html')); }); it('should update window title when the activated tab\'s title is updated', () => { @@ -132,13 +132,13 @@ describe('browser/index.html', function desc() { document.title = 'Title 0'; }). windowByIndex(0). - browserWindow.getTitle().should.eventually.equal('Title 0'). + browserWindow.getTitle().then((title) => title.should.equal('Title 0')). windowByIndex(2). execute(() => { document.title = 'Title 1'; }). windowByIndex(0). - browserWindow.getTitle().should.eventually.equal('Title 0'); + browserWindow.getTitle().then((title) => title.should.equal('Title 0')); }); }); @@ -166,9 +166,9 @@ describe('browser/index.html', function desc() { document.title = 'Title 1'; }). windowByIndex(0). - browserWindow.getTitle().should.eventually.equal('Title 0'). + browserWindow.getTitle().then((title) => title.should.equal('Title 0')). click('#teamTabItem1'). - browserWindow.getTitle().should.eventually.equal('Title 1'); + browserWindow.getTitle().then((title) => title.should.equal('Title 1')); }); }); @@ -177,6 +177,6 @@ describe('browser/index.html', function desc() { return this.app.client.waitUntilWindowLoaded(). click('#tabBarAddNewTeam'). pause(500). - isExisting('#newServerModal').should.eventually.be.true; + isExisting('#newServerModal').then((existing) => existing.should.be.true); }); }); diff --git a/test/specs/browser/settings_test.js b/test/specs/browser/settings_test.js index 971c83b1..10278373 100644 --- a/test/specs/browser/settings_test.js +++ b/test/specs/browser/settings_test.js @@ -37,7 +37,7 @@ describe('browser/settings.html', function desc() { loadSettingsPage(). click('#btnClose'). pause(1000). - getUrl().should.eventually.match(/\/index.html(\?.+)?$/); + getUrl().then((url) => url.should.match(/\/index.html(\?.+)?$/)); }); it('should show NewServerModal after all servers are removed', () => { @@ -53,7 +53,7 @@ describe('browser/settings.html', function desc() { waitForVisible(modalTitleSelector). element('.modal-dialog').click('.btn=Remove'). pause(500). - isExisting('#newServerModal').should.eventually.equal(true); + isExisting('#newServerModal').then((existing) => existing.should.be.true); }); describe('Server list', () => { @@ -64,17 +64,17 @@ describe('browser/settings.html', function desc() { click('h4=example_1'). pause(100). waitUntilWindowLoaded(). - getUrl().should.eventually.match(/\/index.html(\?.+)?$/). - isVisible('#mattermostView0').should.eventually.be.true. - isVisible('#mattermostView1').should.eventually.be.false. + getUrl().then((url) => url.should.match(/\/index.html(\?.+)?$/)). + isVisible('#mattermostView0').then((visible) => visible.should.be.true). + isVisible('#mattermostView1').then((visible) => visible.should.be.false). loadSettingsPage(). click('h4=example_2'). pause(100). waitUntilWindowLoaded(). - getUrl().should.eventually.match(/\/index.html(\?.+)?$/). - isVisible('#mattermostView0').should.eventually.be.false. - isVisible('#mattermostView1').should.eventually.be.true; + getUrl().then((url) => url.should.match(/\/index.html(\?.+)?$/)). + isVisible('#mattermostView0').then((visible) => visible.should.be.false). + isVisible('#mattermostView1').then((visible) => visible.should.be.true); }); }); @@ -85,7 +85,7 @@ describe('browser/settings.html', function desc() { env.addClientCommands(this.app.client); return this.app.client. loadSettingsPage(). - isExisting('#inputHideMenuBar').should.eventually.equal(expected); + isExisting('#inputHideMenuBar').then((existing) => existing.should.equal(expected)); }); [true, false].forEach((v) => { @@ -106,14 +106,14 @@ describe('browser/settings.html', function desc() { const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); savedConfig.hideMenuBar.should.equal(v); }). - browserWindow.isMenuBarAutoHide().should.eventually.equal(v).then(() => { // confirm actual behavior + browserWindow.isMenuBarAutoHide().then((autoHide) => autoHide.should.equal(v)).then(() => { // confirm actual behavior return this.app.restart(); }).then(() => { env.addClientCommands(this.app.client); return this.app.client. // confirm actual behavior - browserWindow.isMenuBarAutoHide().should.eventually.equal(v). + browserWindow.isMenuBarAutoHide().then((autoHide) => autoHide.should.equal(v)). loadSettingsPage(). - isSelected('#inputHideMenuBar').should.eventually.equal(v); + isSelected('#inputHideMenuBar').then((autoHide) => autoHide.should.equal(v)); }); }); }); @@ -125,7 +125,7 @@ describe('browser/settings.html', function desc() { env.addClientCommands(this.app.client); return this.app.client. loadSettingsPage(). - isExisting('#inputAutoStart').should.eventually.equal(expected); + isExisting('#inputAutoStart').then((existing) => existing.should.equal(expected)); }); }); @@ -135,7 +135,7 @@ describe('browser/settings.html', function desc() { env.addClientCommands(this.app.client); return this.app.client. loadSettingsPage(). - isExisting('#inputShowTrayIcon').should.eventually.equal(expected); + isExisting('#inputShowTrayIcon').then((existing) => existing.should.equal(expected)); }); describe('Save tray icon theme on linux', () => { @@ -167,7 +167,7 @@ describe('browser/settings.html', function desc() { env.addClientCommands(this.app.client); return this.app.client. loadSettingsPage(). - isExisting('#inputMinimizeToTray').should.eventually.equal(expected); + isExisting('#inputMinimizeToTray').then((existing) => existing.should.equal(expected)); }); }); @@ -177,7 +177,7 @@ describe('browser/settings.html', function desc() { env.addClientCommands(this.app.client); return this.app.client. loadSettingsPage(). - isExisting('#inputToggleWindowOnTrayIconClick').should.eventually.equal(expected); + isExisting('#inputToggleWindowOnTrayIconClick').then((existing) => existing.should.equal(expected)); }); }); @@ -187,7 +187,7 @@ describe('browser/settings.html', function desc() { env.addClientCommands(this.app.client); return this.app.client. loadSettingsPage(). - isExisting('#inputflashWindow').should.eventually.equal(expected); + isExisting('#inputflashWindow').then((existing) => existing.should.equal(expected)); }); }); @@ -197,7 +197,7 @@ describe('browser/settings.html', function desc() { env.addClientCommands(this.app.client); return this.app.client. loadSettingsPage(). - isExisting('#inputShowUnreadBadge').should.eventually.equal(expected); + isExisting('#inputShowUnreadBadge').then((existing) => existing.should.equal(expected)); }); }); }); @@ -209,8 +209,8 @@ describe('browser/settings.html', function desc() { env.addClientCommands(this.app.client); return this.app.client. loadSettingsPage(). - isExisting(modalTitleSelector).should.eventually.false. - isVisible(modalTitleSelector).should.eventually.false. + isExisting(modalTitleSelector).then((existing) => existing.should.be.false). + isVisible(modalTitleSelector).then((visible) => visible.should.be.false). click('=Remove'). waitForVisible(modalTitleSelector); }); @@ -219,7 +219,7 @@ describe('browser/settings.html', function desc() { this.app.client. element('.modal-dialog').click('.btn=Remove'). pause(500). - isExisting(modalTitleSelector).should.eventually.false. + isExisting(modalTitleSelector).then((existing) => existing.should.be.false). click('#btnClose'). pause(500).then(() => { const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); @@ -232,7 +232,7 @@ describe('browser/settings.html', function desc() { this.app.client. element('.modal-dialog').click('.btn=Cancel'). pause(500). - isExisting(modalTitleSelector).should.eventually.false. + isExisting(modalTitleSelector).then((existing) => existing.should.be.false). click('#btnClose'). pause(500).then(() => { const savedConfig = JSON.parse(fs.readFileSync(env.configFilePath, 'utf8')); @@ -245,14 +245,14 @@ describe('browser/settings.html', function desc() { return this.app.client. click('.modal-dialog button.close'). pause(500). - isExisting(modalTitleSelector).should.eventually.false; + isExisting(modalTitleSelector).then((existing) => existing.should.be.false); }); it('should disappear on click background', () => { return this.app.client. click('body'). pause(500). - isExisting(modalTitleSelector).should.eventually.false; + isExisting(modalTitleSelector).then((existing) => existing.should.be.false); }); }); @@ -265,28 +265,28 @@ describe('browser/settings.html', function desc() { }); it('should open the new server modal', () => { - return this.app.client.isExisting('#newServerModal').should.eventually.equal(true); + return this.app.client.isExisting('#newServerModal').then((existing) => existing.should.be.true); }); it('should close the window after clicking cancel', () => { return this.app.client. click('#cancelNewServerModal'). pause(1000). // Animation - isExisting('#newServerModal').should.eventually.equal(false); + isExisting('#newServerModal').then((existing) => existing.should.be.false); }); it('should not be valid if no team name has been set', () => { return this.app.client. click('#saveNewServerModal'). pause(500). - isExisting('.has-error #teamNameInput').should.eventually.equal(true); + isExisting('.has-error #teamNameInput').then((existing) => existing.should.be.true); }); it('should not be valid if no server address has been set', () => { return this.app.client. click('#saveNewServerModal'). pause(500). - isExisting('.has-error #teamUrlInput').should.eventually.equal(true); + isExisting('.has-error #teamUrlInput').then((existing) => existing.should.be.true); }); describe('Valid server name', () => { @@ -298,12 +298,12 @@ describe('browser/settings.html', function desc() { it('should not be marked invalid', () => { return this.app.client. - isExisting('.has-error #teamNameInput').should.eventually.equal(false); + isExisting('.has-error #teamNameInput').then((existing) => existing.should.be.false); }); it('should not be possible to click save', () => { return this.app.client. - getAttribute('#saveNewServerModal', 'disabled').should.eventually.equal('true'); + getAttribute('#saveNewServerModal', 'disabled').then((disabled) => disabled.should.equal('true')); }); }); @@ -316,12 +316,12 @@ describe('browser/settings.html', function desc() { it('should be valid', () => { return this.app.client. - isExisting('.has-error #teamUrlInput').should.eventually.equal(false); + isExisting('.has-error #teamUrlInput').then((existing) => existing.should.be.false); }); it('should not be possible to click save', () => { return this.app.client. - getAttribute('#saveNewServerModal', 'disabled').should.eventually.equal('true'); + getAttribute('#saveNewServerModal', 'disabled').then((disabled) => disabled.should.equal('true')); }); }); @@ -330,7 +330,7 @@ describe('browser/settings.html', function desc() { setValue('#teamUrlInput', 'superInvalid url'). click('#saveNewServerModal'). pause(500). - isExisting('.has-error #teamUrlInput').should.eventually.equal(true); + isExisting('.has-error #teamUrlInput').then((existing) => existing.should.be.true); }); describe('Valid Team Settings', () => { @@ -342,7 +342,7 @@ describe('browser/settings.html', function desc() { it('should be possible to click add', () => { return this.app.client. - getAttribute('#saveNewServerModal', 'disabled').should.eventually.equal(null); + getAttribute('#saveNewServerModal', 'disabled').then((disabled) => (disabled === null).should.be.true); }); it('should add the team to the config file', (done) => { diff --git a/test/specs/security_test.js b/test/specs/security_test.js index a61c8a87..5ab70724 100644 --- a/test/specs/security_test.js +++ b/test/specs/security_test.js @@ -54,8 +54,8 @@ describe('application', function desc() { // webview is handled as a window by chromedriver. return this.app.client. - windowByIndex(1).isNodeEnabled().should.eventually.be.false. - windowByIndex(2).isNodeEnabled().should.eventually.be.false. + windowByIndex(1).isNodeEnabled().then((enabled) => enabled.should.be.false). + windowByIndex(2).isNodeEnabled().then((enabled) => enabled.should.be.false). windowByIndex(0). getAttribute('webview', 'nodeintegration').then((nodeintegration) => { // nodeintegration is an array of string @@ -78,7 +78,7 @@ describe('application', function desc() { return handles.value.length === 4; }); }, 5000, 'expected a new window'). - windowByIndex(3).isNodeEnabled().should.eventually.be.false; + windowByIndex(3).isNodeEnabled().then((enabled) => enabled.should.be.false); }); it('should NOT be able to call eval() in any window', () => { @@ -88,7 +88,9 @@ describe('application', function desc() { windowByIndex(index). execute(() => { return eval('1 + 1'); - }).should.eventually.be.rejected; + }).then((result) => { + throw new Error(`Promise was unexpectedly fulfilled (result: ${result})`); + }, (error) => (error !== null).should.be.true); }; const tryEvalInSettingsPage = () => { return this.app.client. @@ -96,7 +98,9 @@ describe('application', function desc() { loadSettingsPage(). execute(() => { return eval('1 + 1'); - }).should.eventually.be.rejected; + }).then((result) => { + throw new Error(`Promise was unexpectedly fulfilled (result: ${result})`); + }, (error) => (error !== null).should.be.true); }; return Promise.all([ tryEval(0),