2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-12-23 18:48:55 +00:00
nativefier/e2e/index.test.js

84 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-05-24 06:34:18 +00:00
import tmp from 'tmp';
import fs from 'fs';
import path from 'path';
import async from 'async';
2018-05-24 07:12:22 +00:00
import nativefier from '../src';
2018-05-24 06:34:18 +00:00
const PLATFORMS = ['darwin', 'linux'];
tmp.setGracefulCleanup();
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 new Error('Unknown app platform');
}
const nativefierConfigPath = path.join(
appPath,
relPathToConfig,
'nativefier.json',
);
const nativefierConfig = JSON.parse(fs.readFileSync(nativefierConfigPath));
expect(inputOptions.targetUrl).toBe(nativefierConfig.targetUrl);
// app name is not consistent for linux
// 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', () => {
jest.setTimeout(240000);
test('Can build an app from a target url', (done) => {
async.eachSeries(
PLATFORMS,
(platform, callback) => {
const tmpObj = tmp.dirSync({ unsafeCleanup: true });
const tmpPath = tmpObj.name;
const options = {
name: 'google-test-app',
targetUrl: 'http://google.com',
out: tmpPath,
overwrite: true,
platform: null,
};
options.platform = platform;
nativefier(options, (error, appPath) => {
if (error) {
callback(error);
return;
}
checkApp(appPath, options, (err) => {
callback(err);
});
});
},
(error) => {
done(error);
},
);
});
});