2016-01-24 17:10:28 +00:00
|
|
|
import tmp from 'tmp';
|
|
|
|
import chai from 'chai';
|
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
2016-01-24 17:31:11 +00:00
|
|
|
import async from 'async';
|
2016-01-24 17:10:28 +00:00
|
|
|
|
2016-01-29 05:39:31 +00:00
|
|
|
import nativefier from './../../lib/index';
|
2016-01-24 17:10:28 +00:00
|
|
|
|
2017-04-29 16:40:45 +00:00
|
|
|
const PLATFORMS = ['darwin', 'linux'];
|
2016-01-29 05:39:31 +00:00
|
|
|
tmp.setGracefulCleanup();
|
2017-11-14 13:05:01 +00:00
|
|
|
const { assert } = chai;
|
2016-01-24 17:31:11 +00:00
|
|
|
|
2016-01-24 17:10:28 +00:00
|
|
|
function checkApp(appPath, inputOptions, callback) {
|
2017-04-29 14:52:12 +00:00
|
|
|
try {
|
|
|
|
let relPathToConfig;
|
2016-01-24 17:10:28 +00:00
|
|
|
|
2017-04-29 14:52:12 +00:00
|
|
|
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 new Error('Unknown app platform');
|
|
|
|
}
|
2016-01-24 17:10:28 +00:00
|
|
|
|
2017-04-29 14:52:12 +00:00
|
|
|
const nativefierConfigPath = path.join(appPath, relPathToConfig, 'nativefier.json');
|
|
|
|
const nativefierConfig = JSON.parse(fs.readFileSync(nativefierConfigPath));
|
2016-01-24 17:10:28 +00:00
|
|
|
|
2017-04-29 14:52:12 +00:00
|
|
|
assert.strictEqual(inputOptions.targetUrl, nativefierConfig.targetUrl, 'Packaged app must have the same targetUrl as the input parameters');
|
2017-11-14 13:05:01 +00:00
|
|
|
// app name is not consistent for linux
|
|
|
|
// assert.strictEqual(inputOptions.appName, nativefierConfig.name,
|
|
|
|
// 'Packaged app must have the same name as the input parameters');
|
2017-04-29 14:52:12 +00:00
|
|
|
callback();
|
|
|
|
} catch (exception) {
|
|
|
|
callback(exception);
|
|
|
|
}
|
2016-01-24 17:10:28 +00:00
|
|
|
}
|
|
|
|
|
2017-11-14 13:05:01 +00:00
|
|
|
describe('Nativefier Module', function testNativefierModule() {
|
2017-04-29 14:52:12 +00:00
|
|
|
this.timeout(240000);
|
|
|
|
it('Can build an app from a target url', (done) => {
|
|
|
|
async.eachSeries(PLATFORMS, (platform, callback) => {
|
|
|
|
const tmpObj = tmp.dirSync({ unsafeCleanup: true });
|
2016-01-24 17:10:28 +00:00
|
|
|
|
2017-04-29 14:52:12 +00:00
|
|
|
const tmpPath = tmpObj.name;
|
|
|
|
const options = {
|
|
|
|
name: 'google-test-app',
|
|
|
|
targetUrl: 'http://google.com',
|
|
|
|
out: tmpPath,
|
|
|
|
overwrite: true,
|
|
|
|
platform: null,
|
|
|
|
};
|
2016-01-24 17:31:11 +00:00
|
|
|
|
2017-04-29 14:52:12 +00:00
|
|
|
options.platform = platform;
|
|
|
|
nativefier(options, (error, appPath) => {
|
|
|
|
if (error) {
|
|
|
|
callback(error);
|
|
|
|
return;
|
|
|
|
}
|
2016-01-24 17:10:28 +00:00
|
|
|
|
2017-11-14 13:05:01 +00:00
|
|
|
checkApp(appPath, options, (err) => {
|
|
|
|
callback(err);
|
2016-01-24 17:31:11 +00:00
|
|
|
});
|
2017-04-29 14:52:12 +00:00
|
|
|
});
|
|
|
|
}, (error) => {
|
|
|
|
done(error);
|
2016-01-24 17:10:28 +00:00
|
|
|
});
|
2017-04-29 14:52:12 +00:00
|
|
|
});
|
2016-01-24 17:10:28 +00:00
|
|
|
});
|
2016-01-28 14:39:13 +00:00
|
|
|
|