mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-06-13 09:32:20 +00:00
Add mocha basic test to check if nativefier.json is set properly
This commit is contained in:
parent
0a90cb2ee7
commit
cb07b13cad
|
@ -7,6 +7,7 @@ import runSequence from 'run-sequence';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import childProcess from 'child_process';
|
import childProcess from 'child_process';
|
||||||
import eslint from 'gulp-eslint';
|
import eslint from 'gulp-eslint';
|
||||||
|
import mocha from 'gulp-mocha';
|
||||||
|
|
||||||
const PATHS = setUpPaths();
|
const PATHS = setUpPaths();
|
||||||
|
|
||||||
|
@ -65,14 +66,21 @@ gulp.task('release', callback => {
|
||||||
return runSequence('test', 'build', 'publish', 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/**'])
|
return gulp.src(['**/*.js', '!node_modules/**', '!app/node_modules/**', '!app/lib/**', '!lib/**'])
|
||||||
.pipe(eslint())
|
.pipe(eslint())
|
||||||
.pipe(eslint.format())
|
.pipe(eslint.format())
|
||||||
.pipe(eslint.failAfterError());
|
.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() {
|
function setUpPaths() {
|
||||||
const paths = {
|
const paths = {
|
||||||
|
|
|
@ -54,14 +54,18 @@
|
||||||
"babel-core": "^6.4.5",
|
"babel-core": "^6.4.5",
|
||||||
"babel-loader": "^6.2.1",
|
"babel-loader": "^6.2.1",
|
||||||
"babel-preset-es2015": "^6.3.13",
|
"babel-preset-es2015": "^6.3.13",
|
||||||
|
"babel-register": "^6.4.3",
|
||||||
|
"chai": "^3.4.1",
|
||||||
"del": "^2.2.0",
|
"del": "^2.2.0",
|
||||||
"electron-prebuilt": "^0.36.5",
|
"electron-prebuilt": "^0.36.5",
|
||||||
"eslint-config-google": "^0.3.0",
|
"eslint-config-google": "^0.3.0",
|
||||||
"gulp": "^3.9.0",
|
"gulp": "^3.9.0",
|
||||||
"gulp-babel": "^6.1.1",
|
"gulp-babel": "^6.1.1",
|
||||||
"gulp-eslint": "^1.1.1",
|
"gulp-eslint": "^1.1.1",
|
||||||
|
"gulp-mocha": "^2.2.0",
|
||||||
"gulp-sourcemaps": "^1.6.0",
|
"gulp-sourcemaps": "^1.6.0",
|
||||||
"run-sequence": "^1.1.5",
|
"run-sequence": "^1.1.5",
|
||||||
|
"tmp": "0.0.28",
|
||||||
"webpack-stream": "^3.1.0"
|
"webpack-stream": "^3.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
70
test/module/index-spec.js
Normal file
70
test/module/index-spec.js
Normal 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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user