diff --git a/Makefile b/Makefile index 266f0720..cb460f26 100644 --- a/Makefile +++ b/Makefile @@ -175,10 +175,10 @@ MOCHA_OPTIONS=--recursive --reporter spec --require ts-node/register # See https://github.com/electron/spectron/issues/127 ETCHER_SPECTRON_ENTRYPOINT ?= $(shell node -e 'console.log(require("electron"))') test-spectron: - ETCHER_SPECTRON_ENTRYPOINT="$(ETCHER_SPECTRON_ENTRYPOINT)" mocha $(MOCHA_OPTIONS) tests/spectron + ETCHER_SPECTRON_ENTRYPOINT="$(ETCHER_SPECTRON_ENTRYPOINT)" mocha $(MOCHA_OPTIONS) tests/spectron/runner.spec.ts test-gui: - electron-mocha $(MOCHA_OPTIONS) --full-trace --no-sandbox --renderer tests/gui/**/*.js tests/gui/**/*.ts + electron-mocha $(MOCHA_OPTIONS) --full-trace --no-sandbox --renderer tests/gui/**/*.ts test-sdk: electron-mocha $(MOCHA_OPTIONS) --full-trace --no-sandbox tests/shared/**/*.ts diff --git a/tests/spectron/runner.spec.js b/tests/spectron/runner.spec.js deleted file mode 100644 index dd9a15c5..00000000 --- a/tests/spectron/runner.spec.js +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2017 balena.io - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -'use strict' - -const Bluebird = require('bluebird') -const spectron = require('spectron') -const m = require('mochainon') -// eslint-disable-next-line node/no-missing-require -const EXIT_CODES = require('../../lib/shared/exit-codes') -const entrypoint = process.env.ETCHER_SPECTRON_ENTRYPOINT - -if (!entrypoint) { - console.error('You need to properly configure ETCHER_SPECTRON_ENTRYPOINT') - process.exit(EXIT_CODES.GENERAL_ERROR) -} - -describe('Spectron', function () { - // Mainly for CI jobs - this.timeout(40000) - - let app = null - - before('app:start', function () { - app = new spectron.Application({ - path: entrypoint, - args: [ '--no-sandbox', '.' ] - }) - - return app.start() - }) - - after('app:stop', function () { - if (app && app.isRunning()) { - return app.stop() - } - - return Bluebird.resolve() - }) - - after('app:deref', function () { - app = null - }) - - describe('Browser Window', function () { - it('should open a browser window', function () { - return app.browserWindow.isVisible().then((isVisible) => { - m.chai.expect(isVisible).to.be.true - }) - }) - - it('should set a proper title', function () { - return app.client.getTitle().then((title) => { - m.chai.expect(title).to.equal('Etcher') - }) - }) - }) -}) diff --git a/tests/spectron/runner.spec.ts b/tests/spectron/runner.spec.ts new file mode 100644 index 00000000..ce93392f --- /dev/null +++ b/tests/spectron/runner.spec.ts @@ -0,0 +1,62 @@ +/* + * Copyright 2017 balena.io + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { expect } from 'chai'; +import { Application } from 'spectron'; + +import * as EXIT_CODES from '../../lib/shared/exit-codes'; + +const entrypoint = process.env.ETCHER_SPECTRON_ENTRYPOINT; + +if (!entrypoint) { + console.error('You need to properly configure ETCHER_SPECTRON_ENTRYPOINT'); + process.exit(EXIT_CODES.GENERAL_ERROR); +} + +describe('Spectron', function() { + // Mainly for CI jobs + this.timeout(40000); + + let app: Application; + + before('app:start', function() { + app = new Application({ + path: entrypoint, + args: ['--no-sandbox', '.'], + }); + + return app.start(); + }); + + after('app:stop', function() { + if (app && app.isRunning()) { + return app.stop(); + } + + return Promise.resolve(); + }); + + describe('Browser Window', function() { + it('should open a browser window', async function() { + return expect(await app.browserWindow.isVisible()).to.be.true; + }); + + it('should set a proper title', async function() { + // @ts-ignore (SpectronClient.getTitle exists) + return expect(await app.client.getTitle()).to.equal('Etcher'); + }); + }); +});