2016-01-24 17:10:28 +00:00
|
|
|
import tmp from 'tmp';
|
|
|
|
import chai from 'chai';
|
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
import nativefier from './../../lib/index';
|
2016-01-24 17:31:11 +00:00
|
|
|
import async from 'async';
|
2016-01-28 14:39:13 +00:00
|
|
|
tmp.setGracefulCleanup();
|
2016-01-24 17:10:28 +00:00
|
|
|
|
|
|
|
let assert = chai.assert;
|
|
|
|
|
2016-01-24 17:31:11 +00:00
|
|
|
const PLATFORMS = ['darwin', 'linux', 'win32'];
|
|
|
|
|
2016-01-24 17:10:28 +00:00
|
|
|
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');
|
2016-01-27 02:24:24 +00:00
|
|
|
// app name is not consistent for linux
|
2016-01-28 03:47:40 +00:00
|
|
|
// assert.strictEqual(inputOptions.appName, nativefierConfig.name, 'Packaged app must have the same name as the input parameters');
|
2016-01-24 17:10:28 +00:00
|
|
|
callback();
|
|
|
|
} catch (exception) {
|
|
|
|
callback(exception);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-24 17:14:25 +00:00
|
|
|
describe('Nativefier Module', function() {
|
2016-01-24 17:31:11 +00:00
|
|
|
this.timeout(30000);
|
2016-01-24 17:14:25 +00:00
|
|
|
it('Can build an app from a target url', function(done) {
|
2016-01-28 14:39:13 +00:00
|
|
|
async.eachSeries(PLATFORMS, (platform, callback) => {
|
2016-01-24 17:10:28 +00:00
|
|
|
|
2016-01-28 14:39:13 +00:00
|
|
|
const tmpObj = tmp.dirSync({unsafeCleanup: true});
|
2016-01-24 17:31:11 +00:00
|
|
|
|
2016-01-28 14:39:13 +00:00
|
|
|
const tmpPath = tmpObj.name;
|
|
|
|
const options = {
|
|
|
|
appName: 'google-test-app',
|
|
|
|
targetUrl: 'http://google.com',
|
|
|
|
outDir: tmpPath,
|
|
|
|
overwrite: true,
|
|
|
|
platform: null
|
|
|
|
};
|
2016-01-24 17:31:11 +00:00
|
|
|
|
2016-01-28 14:39:13 +00:00
|
|
|
options.platform = platform;
|
|
|
|
nativefier(options, (error, appPath) => {
|
2016-01-24 17:10:28 +00:00
|
|
|
if (error) {
|
2016-01-24 17:31:11 +00:00
|
|
|
callback(error);
|
2016-01-24 17:10:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-28 14:39:13 +00:00
|
|
|
checkApp(appPath, options, error => {
|
2016-01-24 17:31:11 +00:00
|
|
|
callback(error);
|
2016-01-24 17:10:28 +00:00
|
|
|
});
|
|
|
|
});
|
2016-01-24 17:31:11 +00:00
|
|
|
}, error => {
|
|
|
|
done(error);
|
|
|
|
});
|
2016-01-24 17:10:28 +00:00
|
|
|
});
|
|
|
|
});
|
2016-01-28 14:39:13 +00:00
|
|
|
|