diff --git a/gulpfile.js b/gulpfile.js index 161ab770..25e32eeb 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,6 @@ 'use strict'; const gulp = require('gulp'); +const mocha = require('gulp-mocha'); const electron = require('electron-connect').server.create({ verbose: true }); @@ -27,4 +28,8 @@ gulp.task('reload:renderer', done => { done(); }); -gulp.task('default', ['dev']); +gulp.task('test', () => { + return gulp.src('tests/index.js').pipe(mocha()); +}); + +gulp.task('default', ['dev', 'test']); diff --git a/package.json b/package.json index 621c281c..2d0cf5c5 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,8 @@ }, "main": "app/main/index.js", "scripts": { - "test": "xo", "start": "electron .", + "test": "gulp test && xo", "dev": "gulp dev", "build:osx": "electron-packager . --out=dist --app-version=$npm_package_version --prune --asar --icon=app/resources/Icon.icns --overwrite --platform=darwin --arch=x64", "build": "electron-packager . --out=dist --app-version=$npm_package_version --prune --asar --overwrite --all" @@ -26,12 +26,14 @@ "electron" ], "dependencies": { + "assert": "^1.4.1", "configstore": "^2.0.0", "dialogs": "1.1.14", "electron-context-menu": "0.4.0", "electron-debug": "^1.0.0", "electron-dl": "^0.2.0", "electron-localshortcut": "^0.6.1", + "gulp-mocha": "^3.0.1", "node-json-db": "^0.7.2", "request": "^2.74.0", "simple-spellchecker": "^0.9.0", @@ -43,6 +45,7 @@ "electron-connect": "^0.4.6", "electron-packager": "^7.0.0", "gulp": "^3.9.1", + "spectron": "^3.3.0", "xo": "*" }, "xo": { @@ -59,9 +62,13 @@ } } ], + "ignore": [ + "tests/*.js" + ], "envs": [ "node", - "browser" + "browser", + "mocha" ] } } diff --git a/tests/index.js b/tests/index.js new file mode 100644 index 00000000..e9d6d55d --- /dev/null +++ b/tests/index.js @@ -0,0 +1,28 @@ +/* eslint semi: ["error", "never"]*/ +const assert = require('assert') +const Application = require('spectron').Application + +describe('application launch', function () { + this.timeout(10000) + + beforeEach(function () { + this.app = new Application({ + path: __dirname + '/../node_modules/.bin/electron', + args: [__dirname + '/../app/main/index.js'] + }) + return this.app.start() + }) + + afterEach(function () { + if (this.app && this.app.isRunning()) { + return this.app.stop() + } + }) + + it('shows an initial window', function () { + return this.app.client.getWindowCount().then(function (count) { + assert.equal(count, 1) + }) + }) +}) +