Upgrade dependencies and default to latest Electron 1.7.9 (PR #483)

* Update deps except eslint
* Update eslint and lint:fix (WIP, needs manual fixing for remaining 44 problems)
* Manually fix remaining eslint errors
* Document deprecation of `version-string` as of electron-packager 9.0.0
* Upgrade to Electron 1.7.9 (chrome-58, node-7.9.0, v8-5.8)
* npm: Disable generation of package-lock.json and gitignore it
  --Trying this, package-lock is a pain in PRs. May not be a good idea
  (obviously we lose deps pinning), will revert if necessary.--
* npm tasks: add dev-up-win for Windows developers,
  and e2e for end-to-end tests. Update docs.
* Move normalizeUrl test to a jest unit test, makes no sense to be in the mocha e2e tests
* Switch from babel-preset-es2015 to babel-preset-env,
  with target.node=4.0. Seem like it's today's most convenient
  way to support the latest ES and let babel transpile to what
  makes sense for our currently minimal node version
This commit is contained in:
Ronan Jouchet 2017-11-14 08:05:01 -05:00 committed by GitHub
parent 78bedc62ac
commit 6fb3b92eb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 190 additions and 290 deletions

View File

@ -7,5 +7,7 @@ plugins:
rules:
# TODO: Remove this when we have shifted away from the async package
no-shadow: 'warn'
# Remove no-console when we have moved to a proper logging lib with logging levels
no-console: 'off'
# Gulpfiles and tests use dev dependencies
import/no-extraneous-dependencies: ['error', { devDependencies: ['gulpfile.babel.js', 'gulp/**/**.js', 'test/**/**.js']}]

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
.DS_Store
# Node.js
package-lock.json
# ignore compiled lib files
lib/*

1
.npmrc Normal file
View File

@ -0,0 +1 @@
package-lock=false

1
app/.npmrc Normal file
View File

@ -0,0 +1 @@
package-lock=false

113
app/package-lock.json generated
View File

@ -1,113 +0,0 @@
{
"name": "nativefier-placeholder",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"electron-dl": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/electron-dl/-/electron-dl-1.8.0.tgz",
"integrity": "sha1-VmUtpVqv2kpwB09jE/33+UHsdSo=",
"requires": {
"pupa": "1.0.0",
"unused-filename": "0.1.0"
},
"dependencies": {
"pupa": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/pupa/-/pupa-1.0.0.tgz",
"integrity": "sha1-mpVopa9+ZXuEYqbp1TKHQ1YM7/Y="
},
"unused-filename": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/unused-filename/-/unused-filename-0.1.0.tgz",
"integrity": "sha1-5fM7yeSmP4f2TTwR0xl53vXS5/s=",
"requires": {
"modify-filename": "1.1.0",
"path-exists": "3.0.0"
},
"dependencies": {
"modify-filename": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/modify-filename/-/modify-filename-1.1.0.tgz",
"integrity": "sha1-mi3sg4Bvuy2XXyK+7IWcoms5OqE="
},
"path-exists": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz",
"integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU="
}
}
}
}
},
"electron-window-state": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/electron-window-state/-/electron-window-state-4.1.1.tgz",
"integrity": "sha1-azT9wxs4UU3+yLfI97XUrdtnYy0=",
"requires": {
"deep-equal": "1.0.1",
"jsonfile": "2.4.0",
"mkdirp": "0.5.1"
},
"dependencies": {
"deep-equal": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz",
"integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU="
},
"jsonfile": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz",
"integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=",
"requires": {
"graceful-fs": "4.1.11"
},
"dependencies": {
"graceful-fs": {
"version": "4.1.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
"integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=",
"optional": true
}
}
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"requires": {
"minimist": "0.0.8"
},
"dependencies": {
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
}
}
}
}
},
"source-map-support": {
"version": "0.4.14",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.14.tgz",
"integrity": "sha1-nURjdyWYuGJxtPUj9sH04Cp9au8=",
"requires": {
"source-map": "0.5.6"
},
"dependencies": {
"source-map": {
"version": "0.5.6",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz",
"integrity": "sha1-dc449SvwczxafwwRjYEzSiu19BI="
}
}
},
"wurl": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/wurl/-/wurl-2.1.0.tgz",
"integrity": "sha1-ciS9DmYuUTUiHSWdjWAUHC0T0xA="
}
}
}

View File

@ -4,10 +4,10 @@
"description": "Placeholder for the nativefier cli to override with a target url",
"main": "lib/main.js",
"dependencies": {
"electron-dl": "^1.1.0",
"electron-window-state": "^4.1.0",
"source-map-support": "^0.4.0",
"wurl": "^2.1.0"
"electron-dl": "^1.10.0",
"electron-window-state": "^4.1.1",
"source-map-support": "^0.5.0",
"wurl": "^2.5.2"
},
"devDependencies": {},
"scripts": {

View File

@ -6,7 +6,9 @@ import helpers from './../../helpers/helpers';
import createMenu from './../menu/menu';
import initContextMenu from './../contextMenu/contextMenu';
const { isOSX, linkIsInternal, getCssToInject, shouldInjectCss } = helpers;
const {
isOSX, linkIsInternal, getCssToInject, shouldInjectCss,
} = helpers;
const ZOOM_INTERVAL = 0.1;
@ -125,7 +127,7 @@ function createMainWindow(inpOptions, onAppQuit, setDockBadge) {
if (response !== 0) {
return;
}
const session = mainWindow.webContents.session;
const { session } = mainWindow.webContents;
session.clearStorageData(() => {
session.clearCache(() => {
mainWindow.loadURL(options.targetUrl);

View File

@ -13,23 +13,25 @@ import { Menu, shell, clipboard } from 'electron';
* @param clearAppData
* @param disableDevTools
*/
function createMenu({ nativefierVersion,
appQuit,
zoomIn,
zoomOut,
zoomReset,
zoomBuildTimeValue,
goBack,
goForward,
getCurrentUrl,
clearAppData,
disableDevTools }) {
function createMenu({
nativefierVersion,
appQuit,
zoomIn,
zoomOut,
zoomReset,
zoomBuildTimeValue,
goBack,
goForward,
getCurrentUrl,
clearAppData,
disableDevTools,
}) {
if (Menu.getApplicationMenu()) {
return;
}
const zoomResetLabel = (zoomBuildTimeValue === 1.0) ?
'Reset Zoom' :
`Reset Zoom (to ${zoomBuildTimeValue * 100}%, set at build time)`;
'Reset Zoom' :
`Reset Zoom (to ${zoomBuildTimeValue * 100}%, set at build time)`;
const template = [
{
@ -221,8 +223,8 @@ function createMenu({ nativefierVersion,
];
if (disableDevTools) {
// remove last item (dev tools) from menu > view
const submenu = template[1].submenu;
// remove last item (dev tools) from menu > view
const { submenu } = template[1];
submenu.splice(submenu.length - 1, 1);
}
@ -272,7 +274,7 @@ function createMenu({ nativefierVersion,
label: 'Bring All to Front',
role: 'front',
},
);
);
}
const menu = Menu.buildFromTemplate(template);

View File

@ -1,6 +1,8 @@
import path from 'path';
const { app, Tray, Menu, ipcMain } = require('electron');
const {
app, Tray, Menu, ipcMain,
} = require('electron');
/**
*

View File

@ -72,7 +72,7 @@ app.on('window-all-closed', () => {
app.on('activate', (event, hasVisibleWindows) => {
if (isOSX()) {
// this is called when the dock is clicked
// this is called when the dock is clicked
if (!hasVisibleWindows) {
mainWindow.show();
}
@ -108,7 +108,7 @@ app.on('ready', () => {
});
app.on('login', (event, webContents, request, authInfo, callback) => {
// for http authentication
// for http authentication
event.preventDefault();
if (appArgs.basicAuthUsername !== null && appArgs.basicAuthPassword !== null) {

View File

@ -498,7 +498,7 @@ nativefier(options, function(error, appPath) {
#### [version-string]
*Object* (**deprecated** and will be removed in a future major version (of `electron-packager`), please use the
*Object* (**deprecated** as removed in `electron-packager` 9.0.0, please use the
[`win32metadata`](#win32metadata) parameter instead)
#### [win32metadata]

View File

@ -2,41 +2,39 @@
## Environment Setup
First clone the project
First, clone the project
```bash
git clone https://github.com/jiahaog/nativefier.git
cd nativefier
```
Install dependencies
Install dependencies and build:
```bash
# OSX and Linux
# macOS and Linux
npm run dev-up
# Windows
npm install
cd app
npm install
npm run dev-up-win
```
Don't forget to compile source files:
If dependencies are installed and you just want to re-build,
```bash
npm run build
```
You can set up symlinks so that you can run `nativefier` for your local changes
You can set up a symbolic link so that running `nativefier` invokes your development version including your changes:
```bash
npm link
```
After doing so, you can then run Nativefier with your test parameters
After doing so (and not forgetting to build with `npm run build`), you can run Nativefier with your test parameters:
```bash
nativefier <...>
nativefier <--your-awesome-new-flag>
```
Or you can automatically watch the files for changes with:
@ -48,5 +46,12 @@ npm run watch
## Tests
```bash
# To run all tests (unit, end-to-end),
npm test
# To run only unit tests,
npm run jest
# To run only end-to-end tests,
npm run e2e
```

View File

@ -5,5 +5,5 @@ import PATHS from './../helpers/src-paths';
const webpackConfig = require('./../../webpack.config.js');
gulp.task('build-app', ['build-static'], () => gulp.src(PATHS.APP_MAIN_JS)
.pipe(webpack(webpackConfig))
.pipe(gulp.dest(PATHS.APP_DEST)));
.pipe(webpack(webpackConfig))
.pipe(gulp.dest(PATHS.APP_DEST)));

View File

@ -5,7 +5,7 @@ import helpers from './../helpers/gulp-helpers';
const { buildES6 } = helpers;
gulp.task('build-static-not-js', () => gulp.src([PATHS.APP_STATIC_ALL, '!**/*.js'])
.pipe(gulp.dest(PATHS.APP_STATIC_DEST)));
.pipe(gulp.dest(PATHS.APP_STATIC_DEST)));
gulp.task('build-static-js', done => buildES6(PATHS.APP_STATIC_JS, PATHS.APP_STATIC_DEST, done));

View File

@ -15,11 +15,11 @@ function shellExec(cmd, silent, callback) {
function buildES6(src, dest, callback) {
return gulp.src(src)
.pipe(sourcemaps.init())
.pipe(babel())
.on('error', callback)
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(dest));
.pipe(sourcemaps.init())
.pipe(babel())
.on('error', callback)
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(dest));
}
export default {

View File

@ -2,15 +2,15 @@ import gulp from 'gulp';
import PATHS from './helpers/src-paths';
gulp.task('watch', ['build'], () => {
const handleError = function (error) {
const handleError = function watch(error) {
console.error(error);
};
gulp.watch(PATHS.APP_ALL, ['build-app'])
.on('error', handleError);
.on('error', handleError);
gulp.watch(PATHS.CLI_SRC_JS, ['build-cli'])
.on('error', handleError);
.on('error', handleError);
gulp.watch(PATHS.TEST_SRC_JS, ['build-tests'])
.on('error', handleError);
.on('error', handleError);
});

View File

@ -12,8 +12,10 @@
"main": "lib/index.js",
"scripts": {
"dev-up": "npm install && (cd ./app && npm install) && npm run build",
"dev-up-win": "npm install & cd app & npm install & cd .. & npm run build",
"test": "jest && gulp test",
"jest": "jest",
"e2e": "gulp test",
"tdd": "gulp tdd",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
@ -39,54 +41,61 @@
},
"homepage": "https://github.com/jiahaog/nativefier#readme",
"dependencies": {
"async": "^2.3.0",
"axios": "^0.16.1",
"babel-polyfill": "^6.7.2",
"cheerio": "^0.22.0",
"commander": "^2.9.0",
"electron-packager": "^8.6.0",
"async": "^2.6.0",
"axios": "^0.17.1",
"babel-polyfill": "^6.26.0",
"cheerio": "^1.0.0-rc.2",
"commander": "^2.11.0",
"electron-packager": "^9.1.0",
"gitcloud": "^0.1.0",
"hasbin": "^1.2.0",
"lodash": "^4.0.0",
"loglevel": "^1.4.0",
"hasbin": "^1.2.3",
"lodash": "^4.17.4",
"loglevel": "^1.5.1",
"ncp": "^2.0.0",
"page-icon": "^0.3.0",
"progress": "^2.0.0",
"sanitize-filename": "^1.5.3",
"shelljs": "^0.7.0",
"source-map-support": "^0.4.0",
"tmp": "0.0.31",
"validator": "^7.0.0"
"sanitize-filename": "^1.6.1",
"shelljs": "^0.7.8",
"source-map-support": "^0.5.0",
"tmp": "0.0.33",
"validator": "^9.1.1"
},
"devDependencies": {
"babel-core": "^6.4.5",
"babel-jest": "^19.0.0",
"babel-loader": "^6.2.1",
"babel-preset-es2015": "^6.6.0",
"babel-register": "^6.6.0",
"chai": "^3.4.1",
"del": "^2.2.0",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.1.3",
"eslint-plugin-import": "^2.2.0",
"gulp": "^3.9.0",
"gulp-babel": "^6.1.1",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^4.3.0",
"gulp-sourcemaps": "^2.6.0",
"babel-core": "^6.26.0",
"babel-jest": "^21.2.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"del": "^3.0.0",
"eslint": "^4.11.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.8.0",
"gulp": "^3.9.1",
"gulp-babel": "^7.0.0",
"gulp-istanbul": "^1.1.2",
"gulp-mocha": "^4.3.1",
"gulp-sourcemaps": "^2.6.1",
"isparta": "^4.0.0",
"jest": "^20.0.3",
"regenerator-runtime": "^0.10.5",
"jest": "^21.2.1",
"regenerator-runtime": "^0.11.0",
"require-dir": "^0.3.2",
"run-sequence": "^1.1.5",
"webpack-stream": "^3.1.0"
"run-sequence": "^2.2.0",
"webpack-stream": "^4.0.0"
},
"engines": {
"node": ">= 4.0"
},
"babel": {
"presets": [
"es2015"
[
"env",
{
"targets": {
"node": "4.0.0"
}
}
]
]
},
"jest": {

View File

@ -60,7 +60,7 @@ function maybeCopyScripts(srcs, dest) {
}
const promises = srcs.map(src => new Promise((resolve, reject) => {
if (!fs.existsSync(src)) {
reject('Error copying injection files: file not found');
reject(new Error('Error copying injection files: file not found'));
return;
}
@ -76,7 +76,7 @@ function maybeCopyScripts(srcs, dest) {
copy(src, path.join(dest, 'inject', destFileName), (error) => {
if (error) {
reject(`Error Copying injection files: ${error}`);
reject(new Error(`Error Copying injection files: ${error}`));
return;
}
resolve();
@ -95,7 +95,7 @@ function maybeCopyScripts(srcs, dest) {
}
function normalizeAppName(appName, url) {
// use a simple 3 byte random string to prevent collision
// use a simple 3 byte random string to prevent collision
const hash = crypto.createHash('md5');
hash.update(url);
const postFixHash = hash.digest('hex').substring(0, 6);
@ -130,8 +130,8 @@ function buildApp(src, dest, options, callback) {
fs.writeFileSync(path.join(dest, '/nativefier.json'), JSON.stringify(appArgs));
maybeCopyScripts(options.inject, dest)
.catch((error) => {
console.warn(error);
.catch((err) => {
console.warn(err);
})
.then(() => {
changeAppPackageJsonName(dest, appArgs.name, appArgs.targetUrl);

View File

@ -13,7 +13,7 @@ import PackagerConsole from './../helpers/packagerConsole';
import buildApp from './buildApp';
const copy = ncp.ncp;
const isWindows = helpers.isWindows;
const { isWindows } = helpers;
/**
* Checks the app path array to determine if the packaging was completed successfully
@ -153,7 +153,6 @@ function buildMain(inpOptions, callback) {
const options = Object.assign({}, inpOptions);
// pre process app
const tmpObj = tmp.dirSync({ unsafeCleanup: true });
const tmpPath = tmpObj.name;
@ -163,37 +162,37 @@ function buildMain(inpOptions, callback) {
const progress = new DishonestProgress(5);
async.waterfall([
(callback) => {
(cb) => {
progress.tick('inferring');
optionsFactory(options)
.then((result) => {
callback(null, result);
cb(null, result);
}).catch((error) => {
callback(error);
cb(error);
});
},
(options, callback) => {
(opts, cb) => {
progress.tick('copying');
buildApp(options.dir, tmpPath, options, (error) => {
buildApp(opts.dir, tmpPath, opts, (error) => {
if (error) {
callback(error);
cb(error);
return;
}
// Change the reference file for the Electron app to be the temporary path
const newOptions = Object.assign({}, options, { dir: tmpPath });
callback(null, newOptions);
const newOptions = Object.assign({}, opts, { dir: tmpPath });
cb(null, newOptions);
});
},
(options, callback) => {
(opts, cb) => {
progress.tick('icons');
iconBuild(options, (error, optionsWithIcon) => {
callback(null, optionsWithIcon);
iconBuild(opts, (error, optionsWithIcon) => {
cb(null, optionsWithIcon);
});
},
(options, callback) => {
(opts, cb) => {
progress.tick('packaging');
// maybe skip passing icon parameter to electron packager
let packageOptions = maybeNoIconOption(options);
let packageOptions = maybeNoIconOption(opts);
// maybe skip passing other parameters to electron packager
packageOptions = maybeNoAppCopyrightOption(packageOptions);
packageOptions = maybeNoAppVersionOption(packageOptions);
@ -208,20 +207,20 @@ function buildMain(inpOptions, callback) {
packagerConsole.restore();
// pass options which still contains the icon to waterfall
callback(error, options, appPathArray);
cb(error, opts, appPathArray);
});
},
(options, appPathArray, callback) => {
(opts, appPathArray, cb) => {
progress.tick('finalizing');
// somehow appPathArray is a 1 element array
const appPath = getAppPath(appPathArray);
if (!appPath) {
callback();
cb();
return;
}
maybeCopyIcons(options, appPath, (error) => {
callback(error, appPath);
maybeCopyIcons(opts, appPath, (error) => {
cb(error, appPath);
});
},
], (error, appPath) => {

View File

@ -1,5 +1,5 @@
import path from 'path';
export const DEFAULT_APP_NAME = 'APP';
export const ELECTRON_VERSION = '1.6.6';
export const ELECTRON_VERSION = '1.7.9';
export const PLACEHOLDER_APP_DIR = path.join(__dirname, './../', 'app');

View File

@ -3,7 +3,7 @@ import path from 'path';
import tmp from 'tmp';
import helpers from './helpers';
const isOSX = helpers.isOSX;
const { isOSX } = helpers;
tmp.setGracefulCleanup();
const PNG_TO_ICNS_BIN_PATH = path.join(__dirname, '../..', 'bin/convertToIcns');

View File

@ -12,10 +12,9 @@ function isWindows() {
}
function downloadFile(fileUrl) {
return axios.get(
fileUrl, {
responseType: 'arraybuffer',
})
return axios.get(fileUrl, {
responseType: 'arraybuffer',
})
.then((response) => {
if (!response.data) {
return null;

View File

@ -23,12 +23,13 @@ const SCRIPT_PATHS = {
function iconShellHelper(shellScriptPath, icoSrc, dest) {
return new Promise((resolve, reject) => {
if (isWindows()) {
reject('OSX or Linux is required');
reject(new Error('OSX or Linux is required'));
return;
}
shell.exec(`${shellScriptPath} ${icoSrc} ${dest}`, { silent: true }, (exitCode, stdOut, stdError) => {
if (exitCode) {
// eslint-disable-next-line prefer-promise-reject-errors
reject({
stdOut,
stdError,
@ -66,7 +67,7 @@ function convertToIco(icoSrc) {
function convertToIcns(icoSrc) {
if (!isOSX()) {
return new Promise((resolve, reject) => reject('OSX is required to convert to a .icns icon'));
return new Promise((resolve, reject) => reject(new Error('OSX is required to convert to a .icns icon')));
}
return iconShellHelper(SCRIPT_PATHS.convertToIcns, icoSrc, `${getTmpDirPath()}/icon.icns`);
}

View File

@ -1,6 +1,5 @@
// TODO: remove this file and use quiet mode of new version of electron packager
class PackagerConsole {
constructor() {
this.logs = [];
}

View File

@ -3,7 +3,7 @@ import _ from 'lodash';
import log from 'loglevel';
const ELECTRON_VERSIONS_URL = 'https://atom.io/download/atom-shell/index.json';
const DEFAULT_CHROME_VERSION = '56.0.2924.87';
const DEFAULT_CHROME_VERSION = '58.0.3029.110';
function getChromeVersionForElectronVersion(electronVersion, url = ELECTRON_VERSIONS_URL) {
return axios.get(url, { timeout: 5000 })
@ -12,9 +12,11 @@ function getChromeVersionForElectronVersion(electronVersion, url = ELECTRON_VERS
throw new Error(`Bad request: Status code ${response.status}`);
}
const data = response.data;
const electronVersionToChromeVersion = _.zipObject(data.map(d => d.version),
data.map(d => d.chrome));
const { data } = response;
const electronVersionToChromeVersion = _.zipObject(
data.map(d => d.version),
data.map(d => d.chrome),
);
if (!(electronVersion in electronVersionToChromeVersion)) {
throw new Error(`Electron version '${electronVersion}' not found in retrieved version list!`);

View File

@ -29,7 +29,7 @@ describe('when the icon parameter is not passed', () => {
describe('when inferIcon resolves with an error', () => {
test('it should handle the error', () => {
inferIcon.mockImplementationOnce(() => Promise.reject('some error'));
inferIcon.mockImplementationOnce(() => Promise.reject(new Error('some error')));
const params = { targetUrl: 'some url', platform: 'mac' };
return icon(params).then((result) => {

View File

@ -75,7 +75,7 @@ describe('handling inferTitle results', () => {
describe('when inferTitle resolves with an error', () => {
test('it should return the default app name', () => {
inferTitle.mockImplementationOnce(() => Promise.reject('some error'));
inferTitle.mockImplementationOnce(() => Promise.reject(new Error('some error')));
return name(params).then((result) => {
expect(result).toBe(DEFAULT_APP_NAME);

View File

@ -0,0 +1,13 @@
import normalizeUrl from './normalizeUrl';
test("a proper URL shouldn't be mangled", () => {
expect(normalizeUrl('http://www.google.com')).toEqual('http://www.google.com');
});
test('missing protocol should default to http', () => {
expect(normalizeUrl('www.google.com')).toEqual('http://www.google.com');
});
test("a proper URL shouldn't be mangled", () => {
expect(() => { normalizeUrl('http://ssddfoo bar'); }).toThrow('Your Url: "http://ssddfoo bar" is invalid!');
});

View File

@ -7,7 +7,7 @@ import os from 'os';
import path from 'path';
import convertToIcns from './../../lib/helpers/convertToIcns';
const assert = chai.assert;
const { assert } = chai;
// Prerequisite for test: to use OSX with sips, iconutil and imagemagick convert

View File

@ -8,7 +8,7 @@ import nativefier from './../../lib/index';
const PLATFORMS = ['darwin', 'linux'];
tmp.setGracefulCleanup();
const assert = chai.assert;
const { assert } = chai;
function checkApp(appPath, inputOptions, callback) {
try {
@ -32,16 +32,16 @@ function checkApp(appPath, inputOptions, callback) {
const nativefierConfig = JSON.parse(fs.readFileSync(nativefierConfigPath));
assert.strictEqual(inputOptions.targetUrl, nativefierConfig.targetUrl, 'Packaged app must have the same targetUrl as the input parameters');
// app name is not consistent for linux
// assert.strictEqual(inputOptions.appName, nativefierConfig.name,
// 'Packaged app must have the same name as the input parameters');
// 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', function () {
describe('Nativefier Module', function testNativefierModule() {
this.timeout(240000);
it('Can build an app from a target url', (done) => {
async.eachSeries(PLATFORMS, (platform, callback) => {
@ -63,8 +63,8 @@ describe('Nativefier Module', function () {
return;
}
checkApp(appPath, options, (error) => {
callback(error);
checkApp(appPath, options, (err) => {
callback(err);
});
});
}, (error) => {

View File

@ -2,7 +2,7 @@ import chai from 'chai';
import _ from 'lodash';
import inferUserAgent from './../../lib/infer/inferUserAgent';
const assert = chai.assert;
const { assert } = chai;
const TEST_RESULT = {
darwin: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36',
@ -12,36 +12,36 @@ const TEST_RESULT = {
function testPlatform(platform) {
return inferUserAgent('0.37.1', platform)
.then((userAgent) => {
assert.equal(userAgent, TEST_RESULT[platform], 'Correct user agent should be inferred');
});
.then((userAgent) => {
assert.equal(userAgent, TEST_RESULT[platform], 'Correct user agent should be inferred');
});
}
describe('Infer User Agent', function () {
describe('Infer User Agent', function testInferUserAgent() {
this.timeout(15000);
it('Can infer userAgent for all platforms', (done) => {
const testPromises = _.keys(TEST_RESULT).map(platform => testPlatform(platform));
Promise
.all(testPromises)
.then(() => {
done();
})
.catch((error) => {
done(error);
});
.all(testPromises)
.then(() => {
done();
})
.catch((error) => {
done(error);
});
});
it('Connection error will still get a user agent', (done) => {
const TIMEOUT_URL = 'http://www.google.com:81/';
inferUserAgent('1.6.7', 'darwin', TIMEOUT_URL)
.then((userAgent) => {
assert.equal(
userAgent,
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'Expect default user agent on connection error',
);
done();
})
.catch(done);
.then((userAgent) => {
assert.equal(
userAgent,
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
'Expect default user agent on connection error',
);
done();
})
.catch(done);
});
});

View File

@ -1,25 +0,0 @@
import chai from 'chai';
import normalizeUrl from '../../../src/options/normalizeUrl';
const assert = chai.assert;
const expect = chai.expect;
describe('Normalize URL', () => {
describe('given a valid URL without a protocol', () => {
it('should allow the url', () => {
assert.equal(normalizeUrl('http://www.google.com'), 'http://www.google.com');
});
});
describe('given a valid URL without a protocol', () => {
it('should allow the url and prepend the HTTP protocol', () => {
assert.equal(normalizeUrl('www.google.com'), 'http://www.google.com');
});
});
describe('given an invalid URL', () => {
it('should throw an exception', () => {
expect(() => normalizeUrl('http://ssddfoo bar')).to.throw('Your Url: "http://ssddfoo bar" is invalid!');
});
});
});

View File

@ -17,7 +17,7 @@ module.exports = {
externals: nodeModules,
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader' },
],
},
devtool: 'source-map',