Commit 0377dba2 authored by Jakub Szwacz's avatar Jakub Szwacz

Unit tests refactored and added e2e tests environment

parent 1d4322a9
node_modules
*.log
.DS_Store
Thumbs.db
*.log
*.autogenerated
# ignore everything in 'app' folder what had been generated from 'src' folder
......
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!');
});
});
});
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,
};
'use strict';
require('./tasks/build');
require('./tasks/build_app');
require('./tasks/build_tests');
require('./tasks/start');
......@@ -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"
}
}
......@@ -40,7 +40,7 @@ app.on('ready', function () {
mainWindow.loadURL('file://' + __dirname + '/app.html');
if (env.name !== 'production') {
if (env.name === 'development') {
mainWindow.openDevTools();
}
});
......
'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 () {
......
'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'));
});
});
// 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);
});
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment