2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-10 23:31:10 +00:00
nativefier/test/module/index-spec.js

79 lines
2.4 KiB
JavaScript
Raw Normal View History

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';
2016-01-24 17:31:11 +00:00
import _ from 'lodash';
import async from 'async';
let assert = chai.assert;
2016-01-24 17:31:11 +00:00
const PLATFORMS = ['darwin', 'linux', 'win32'];
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('Nativefier Module', function() {
2016-01-24 17:31:11 +00:00
this.timeout(30000);
it('Can build an app from a target url', function(done) {
2016-01-24 17:31:11 +00:00
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: null
};
async.each(PLATFORMS, (platform, callback) => {
let platformOptions = _.clone(options);
platformOptions.platform = platform;
nativefier(platformOptions, (error, appPath) => {
if (error) {
2016-01-24 17:31:11 +00:00
callback(error);
return;
}
2016-01-24 17:31:11 +00:00
checkApp(appPath, platformOptions, error => {
callback(error);
});
});
2016-01-24 17:31:11 +00:00
}, error => {
done(error);
});
});
});