Add mocha basic test to check if nativefier.json is set properly

This commit is contained in:
Jia Hao 2016-01-25 01:10:28 +08:00
parent 0a90cb2ee7
commit cb07b13cad
3 changed files with 84 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import runSequence from 'run-sequence';
import path from 'path';
import childProcess from 'child_process';
import eslint from 'gulp-eslint';
import mocha from 'gulp-mocha';
const PATHS = setUpPaths();
@ -65,14 +66,21 @@ gulp.task('release', callback => {
return runSequence('test', 'build', 'publish', callback);
});
gulp.task('lint', function() {
gulp.task('lint', () => {
return gulp.src(['**/*.js', '!node_modules/**', '!app/node_modules/**', '!app/lib/**', '!lib/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('test', ['lint']);
gulp.task('test', ['build'], () => {
return gulp.src('test/**/*js', {read: false})
.pipe(mocha({compilers: 'js:babel-register'}));
});
gulp.task('ci', callback => {
return runSequence('test', 'lint', callback);
});
function setUpPaths() {
const paths = {

View File

@ -54,14 +54,18 @@
"babel-core": "^6.4.5",
"babel-loader": "^6.2.1",
"babel-preset-es2015": "^6.3.13",
"babel-register": "^6.4.3",
"chai": "^3.4.1",
"del": "^2.2.0",
"electron-prebuilt": "^0.36.5",
"eslint-config-google": "^0.3.0",
"gulp": "^3.9.0",
"gulp-babel": "^6.1.1",
"gulp-eslint": "^1.1.1",
"gulp-mocha": "^2.2.0",
"gulp-sourcemaps": "^1.6.0",
"run-sequence": "^1.1.5",
"tmp": "0.0.28",
"webpack-stream": "^3.1.0"
}
}

70
test/module/index-spec.js Normal file
View File

@ -0,0 +1,70 @@
import tmp from 'tmp';
import chai from 'chai';
import fs from 'fs';
import os from 'os';
import path from 'path';
import nativefier from './../../lib/index';
let assert = chai.assert;
function checkApp(appPath, inputOptions, callback) {
try {
let relPathToConfig;
switch (inputOptions.platform) {
case 'darwin':
relPathToConfig = path.join('google-test-app.app', 'Contents/Resources/app');
break;
case 'linux':
relPathToConfig = 'resources/app';
break;
case 'win32':
relPathToConfig = 'resources/app';
break;
default:
throw 'Unknown app platform';
}
const nativefierConfigPath = path.join(appPath, relPathToConfig, 'nativefier.json');
const nativefierConfig = JSON.parse(fs.readFileSync(nativefierConfigPath));
assert.strictEqual(inputOptions.targetUrl, nativefierConfig.targetUrl, 'Packaged app must have the same targetUrl as the input parameters');
assert.strictEqual(inputOptions.appName, nativefierConfig.name, 'Packaged app must have the same name as the input parameters');
callback();
} catch (exception) {
callback(exception);
}
}
describe('index module', function () {
this.timeout(20000);
it('Can build an app from a target url', function (done) {
try {
var tmpObj = tmp.dirSync({unsafeCleanup: true});
after(function() {
tmpObj.removeCallback();
});
const tmpPath = tmpObj.name;
const options = {
appName: 'google-test-app',
targetUrl: 'http://google.com',
outDir: tmpPath,
overwrite: true,
platform: 'win32'
};
nativefier(options, (error, appPath) => {
if (error) {
done(error);
return;
}
checkApp(appPath, options, error => {
done(error);
});
});
} catch (exception) {
done(exception);
}
});
});