diff --git a/.gitignore b/.gitignore index e69c187..7cf7690 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ node_modules -*.log .DS_Store Thumbs.db +*.log *.autogenerated # ignore everything in 'app' folder what had been generated from 'src' folder diff --git a/e2e/hello_world.e2e.js b/e2e/hello_world.e2e.js new file mode 100644 index 0000000..2a38b93 --- /dev/null +++ b/e2e/hello_world.e2e.js @@ -0,0 +1,14 @@ +import { expect } from 'chai'; +import testUtils from './utils'; + +describe('application launch', function () { + + beforeEach(testUtils.beforeEach); + afterEach(testUtils.afterEach); + + it('shows hello world text on screen after launch', function () { + return this.app.client.getText('#greet').then(function (text) { + expect(text).to.equal('Hello World!'); + }); + }); +}); diff --git a/e2e/utils.js b/e2e/utils.js new file mode 100644 index 0000000..877e033 --- /dev/null +++ b/e2e/utils.js @@ -0,0 +1,22 @@ +import electron from 'electron'; +import { Application } from 'spectron'; + +var beforeEach = function () { + this.app = new Application({ + path: electron, + args: ['app'], + waitTimeout: 10000, + }); + return this.app.start(); +}; + +var afterEach = function () { + if (this.app && this.app.isRunning()) { + return this.app.stop(); + } +}; + +export default { + beforeEach: beforeEach, + afterEach: afterEach, +}; diff --git a/gulpfile.js b/gulpfile.js index 063da1a..9ea1796 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,4 +1,5 @@ 'use strict'; -require('./tasks/build'); +require('./tasks/build_app'); +require('./tasks/build_tests'); require('./tasks/start'); diff --git a/package.json b/package.json index 5451c84..7f9260f 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,10 @@ "prerelease": "gulp build --env=production", "release": "build --x64 --publish never", "start": "gulp start", - "pretest": "gulp build --env=test", - "test": "electron-mocha app/app.js --renderer --require source-map-support/register" + "pretest": "gulp build-unit --env=test", + "test": "electron-mocha app/specs.js.autogenerated --renderer --require source-map-support/register", + "pree2e": "gulp build-e2e --env=test", + "e2e": "mocha app/e2e.js.autogenerated --require source-map-support/register" }, "devDependencies": { "chai": "^3.5.0", @@ -44,8 +46,10 @@ "gulp-plumber": "^1.1.0", "gulp-util": "^3.0.6", "gulp-watch": "^4.3.5", + "mocha": "^3.0.2", "rollup": "^0.34.7", "source-map-support": "^0.4.2", + "spectron": "^3.3.0", "yargs": "^4.2.0" } } diff --git a/src/background.js b/src/background.js index 50c1344..7990f47 100644 --- a/src/background.js +++ b/src/background.js @@ -40,7 +40,7 @@ app.on('ready', function () { mainWindow.loadURL('file://' + __dirname + '/app.html'); - if (env.name !== 'production') { + if (env.name === 'development') { mainWindow.openDevTools(); } }); diff --git a/tasks/build.js b/tasks/build_app.js similarity index 62% rename from tasks/build.js rename to tasks/build_app.js index fb2f763..8f1548b 100644 --- a/tasks/build.js +++ b/tasks/build_app.js @@ -1,43 +1,23 @@ 'use strict'; -var pathUtil = require('path'); var gulp = require('gulp'); var less = require('gulp-less'); var watch = require('gulp-watch'); var batch = require('gulp-batch'); var plumber = require('gulp-plumber'); var jetpack = require('fs-jetpack'); - var bundle = require('./bundle'); -var generateSpecsEntryFile = require('./generate_specs_entry_file'); var utils = require('./utils'); var projectDir = jetpack; -var srcDir = projectDir.cwd('./src'); -var destDir = projectDir.cwd('./app'); - -// ------------------------------------- -// Tasks -// ------------------------------------- - -var bundleApplication = function () { - return Promise.all([ - bundle(srcDir.path('background.js'), destDir.path('background.js')), - bundle(srcDir.path('app.js'), destDir.path('app.js')), - ]); -}; - -var bundleSpecs = function () { - return generateSpecsEntryFile().then(function (specEntryPointPath) { - return bundle(specEntryPointPath, destDir.path('app.js')); - }); -}; +var srcDir = jetpack.cwd('./src'); +var destDir = jetpack.cwd('./app'); gulp.task('bundle', function () { - if (utils.getEnvName() === 'test') { - return bundleSpecs(); - } - return bundleApplication(); + return Promise.all([ + bundle(srcDir.path('background.js'), destDir.path('background.js')), + bundle(srcDir.path('app.js'), destDir.path('app.js')), + ]); }); gulp.task('less', function () { diff --git a/tasks/build_tests.js b/tasks/build_tests.js new file mode 100644 index 0000000..351da45 --- /dev/null +++ b/tasks/build_tests.js @@ -0,0 +1,43 @@ +'use strict'; + +var gulp = require('gulp'); +var jetpack = require('fs-jetpack'); +var bundle = require('./bundle'); + +// Spec files are scattered through the whole project. Here we're searching +// for them and generate one entry file which will run all the tests. +var generateEntryFile = function (dir, destFileName, filePattern) { + var fileBanner = "// This file is generated automatically.\n" + + "// All modifications will be lost.\n"; + + return dir.findAsync('.', { matching: filePattern }) + .then(function (specPaths) { + var fileContent = specPaths.map(function (path) { + return 'import "./' + path.replace(/\\/g, '/') + '";'; + }).join('\n'); + return dir.writeAsync(destFileName, fileBanner + fileContent); + }) + .then(function () { + return dir.path(destFileName); + }); +}; + +gulp.task('build-unit', ['environment'], function () { + var srcDir = jetpack.cwd('src'); + var destDir = jetpack.cwd('app'); + + return generateEntryFile(srcDir, 'specs.js.autogenerated', '*.spec.js') + .then(function (entryFilePath) { + return bundle(entryFilePath, destDir.path('specs.js.autogenerated')); + }); +}); + +gulp.task('build-e2e', ['build'], function () { + var srcDir = jetpack.cwd('e2e'); + var destDir = jetpack.cwd('app'); + + return generateEntryFile(srcDir, 'e2e.js.autogenerated', '*.e2e.js') + .then(function (entryFilePath) { + return bundle(entryFilePath, destDir.path('e2e.js.autogenerated')); + }); +}); diff --git a/tasks/generate_specs_entry_file.js b/tasks/generate_specs_entry_file.js deleted file mode 100644 index 59bf40e..0000000 --- a/tasks/generate_specs_entry_file.js +++ /dev/null @@ -1,24 +0,0 @@ -// Spec files are scattered through the whole project. Here we're searching -// for them and generate one entry file which will run all the tests. - -'use strict'; - -var jetpack = require('fs-jetpack'); -var srcDir = jetpack.cwd('src'); - -var fileName = 'specs.js.autogenerated'; -var fileBanner = "// This file is generated automatically.\n" - + "// All your modifications to it will be lost (so don't do it).\n"; - -module.exports = function () { - return srcDir.findAsync('.', { matching: '*.spec.js' }) - .then(function (specPaths) { - var fileContent = specPaths.map(function (path) { - return 'import "./' + path.replace(/\\/g, '/') + '";'; - }).join('\n'); - return srcDir.writeAsync(fileName, fileBanner + fileContent); - }) - .then(function () { - return srcDir.path(fileName); - }); -};