From 18c913dd3312ecf95e03633561ec0a5fce640b61 Mon Sep 17 00:00:00 2001 From: Kylart Date: Wed, 3 Jul 2019 17:54:29 +0200 Subject: [PATCH] Structured tests properly, no big file --- .../downloader.spec.js} | 45 +------------------ test/app/index.js | 1 + test/container/index.js | 1 + test/container/window.spec.js | 17 +++++++ test/hooks.js | 26 +++++++++++ test/index.spec.js | 17 +++++++ 6 files changed, 64 insertions(+), 43 deletions(-) rename test/{electron.spec.js => app/downloader.spec.js} (60%) create mode 100644 test/app/index.js create mode 100644 test/container/index.js create mode 100644 test/container/window.spec.js create mode 100644 test/hooks.js create mode 100644 test/index.spec.js diff --git a/test/electron.spec.js b/test/app/downloader.spec.js similarity index 60% rename from test/electron.spec.js rename to test/app/downloader.spec.js index a2eb34f..4a2abf8 100644 --- a/test/electron.spec.js +++ b/test/app/downloader.spec.js @@ -1,31 +1,4 @@ -const { Application } = require('spectron') -const electron = require('electron') -const chai = require('chai') -const chaiAsPromised = require('chai-as-promised') - -chai.should() -chai.use(chaiAsPromised) - -describe('Launch app', function () { - this.timeout(10000) - - before(async function () { - this.app = new Application({ - path: electron, - args: ['dist/bundled/background.js'] - }) - - await this.app.start() - }) - - beforeEach(function () { - chaiAsPromised.transferPromiseness = this.app.transferPromiseness - }) - - after(async function () { - return this.app.stop() - }) - +module.exports = function () { describe('Downloader modal', function () { it('should open the downloader modal', function () { return this.app.client @@ -59,18 +32,4 @@ describe('Launch app', function () { // return this.app.client // }) }) - - it('should be visible', async function () { - return this.app.client - .getWindowCount() - .should.eventually.have.at.least(1) - .browserWindow.isMinimized() - .should.eventually.be.false.browserWindow.isVisible() - .should.eventually.be.true.browserWindow.getBounds() - .should.eventually.have.property('width') - .and.be.above(0) - .browserWindow.getBounds() - .should.eventually.have.property('height') - .and.be.above(0) - }) -}) +} diff --git a/test/app/index.js b/test/app/index.js new file mode 100644 index 0000000..6e24b52 --- /dev/null +++ b/test/app/index.js @@ -0,0 +1 @@ +require('./downloader.spec')() diff --git a/test/container/index.js b/test/container/index.js new file mode 100644 index 0000000..9234167 --- /dev/null +++ b/test/container/index.js @@ -0,0 +1 @@ +require('./window.spec')() diff --git a/test/container/window.spec.js b/test/container/window.spec.js new file mode 100644 index 0000000..7b7234b --- /dev/null +++ b/test/container/window.spec.js @@ -0,0 +1,17 @@ +module.exports = function () { + describe('General window behaviour', function () { + it('should be visible', async function () { + return this.app.client + .getWindowCount() + .should.eventually.have.at.least(1) + .browserWindow.isMinimized() + .should.eventually.be.false.browserWindow.isVisible() + .should.eventually.be.true.browserWindow.getBounds() + .should.eventually.have.property('width') + .and.be.above(0) + .browserWindow.getBounds() + .should.eventually.have.property('height') + .and.be.above(0) + }) + }) +} diff --git a/test/hooks.js b/test/hooks.js new file mode 100644 index 0000000..40b42e6 --- /dev/null +++ b/test/hooks.js @@ -0,0 +1,26 @@ +const { Application } = require('spectron') +const electron = require('electron') +const chai = require('chai') +const chaiAsPromised = require('chai-as-promised') + +chai.should() +chai.use(chaiAsPromised) + +module.exports = function () { + before(async function () { + this.app = new Application({ + path: electron, + args: ['dist/bundled/background.js'] + }) + + await this.app.start() + }) + + beforeEach(function () { + chaiAsPromised.transferPromiseness = this.app.transferPromiseness + }) + + after(async function () { + return this.app.stop() + }) +} diff --git a/test/index.spec.js b/test/index.spec.js new file mode 100644 index 0000000..4bf3c0a --- /dev/null +++ b/test/index.spec.js @@ -0,0 +1,17 @@ +/** + * We have to do it that way because we don't want to restart the app + * several times. Restarting would mean spamming the providers and + * might get us useless 429. + * + * Also, the end user will probably only start the app once. + * + * We'll make each app test so that it leaves the app in a neutral state, + * meaning that any action should be possible once any test is done. + */ + +describe('KawAnime main test routine', function () { + require('./hooks')() + + require('./container') + require('./app') +})