refactor: adhere mostly to StandardJS guidelines (#1657)

This commit changes the whole codebase to adhere to all StandardJS
guidelines rules except semicolons, since the removal of semicolons
affect pretty much all lines, and the final diff is very hard to follow
(and to assess other more involved changes).

In a nutshell:

- When using `function`, we now require a space before the opening
  parenthesis
- If a line with operators is broken into multiple lines, the operator
  should now go after the line break
- Unnecessary padding lines are now forbidden

There were also some minor things that the `standard` CLI caught that I
updated here.

See: https://standardjs.com
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
This commit is contained in:
Juan Cruz Viotti 2017-08-03 06:59:02 -04:00 committed by GitHub
parent 064c741e3f
commit 5c19b70e83
91 changed files with 1339 additions and 1956 deletions

View File

@ -461,10 +461,10 @@ rules:
- always - always
operator-linebreak: operator-linebreak:
- error - error
- before - after
padded-blocks: padded-blocks:
- error - error
- classes: always - never
quote-props: quote-props:
- error - error
- as-needed - as-needed
@ -489,7 +489,9 @@ rules:
- error - error
space-before-function-paren: space-before-function-paren:
- error - error
- never - anonymous: always
named: always
asyncArrow: never
space-in-parens: space-in-parens:
- error - error
- never - never

View File

@ -86,7 +86,6 @@ exports.write = (image, drive, options) => {
* terminateServer(); * terminateServer();
*/ */
const terminateServer = () => { const terminateServer = () => {
// Turns out we need to destroy all sockets for // Turns out we need to destroy all sockets for
// the server to actually close. Otherwise, it // the server to actually close. Otherwise, it
// just stops receiving any further connections, // just stops receiving any further connections,
@ -137,7 +136,6 @@ exports.write = (image, drive, options) => {
return robot.parseMessage(robot.buildMessage(robot.COMMAND.LOG, { return robot.parseMessage(robot.buildMessage(robot.COMMAND.LOG, {
message message
})); }));
}); });
if (_.isError(parsedMessage)) { if (_.isError(parsedMessage)) {
@ -146,7 +144,6 @@ exports.write = (image, drive, options) => {
} }
try { try {
// These are lighweight accessor methods for // These are lighweight accessor methods for
// the properties of the parsed message // the properties of the parsed message
const messageCommand = robot.getCommand(parsedMessage); const messageCommand = robot.getCommand(parsedMessage);
@ -158,7 +155,6 @@ exports.write = (image, drive, options) => {
if (messageCommand === robot.COMMAND.ERROR) { if (messageCommand === robot.COMMAND.ERROR) {
emitError(robot.recomposeErrorMessage(parsedMessage)); emitError(robot.recomposeErrorMessage(parsedMessage));
} else if (messageCommand === robot.COMMAND.LOG) { } else if (messageCommand === robot.COMMAND.LOG) {
// If the message data is an object and it contains a // If the message data is an object and it contains a
// message string then log the message string only. // message string then log the message string only.
if (_.isPlainObject(messageData) && _.isString(messageData.message)) { if (_.isPlainObject(messageData) && _.isString(messageData.message)) {
@ -166,11 +162,9 @@ exports.write = (image, drive, options) => {
} else { } else {
console.log(messageData); console.log(messageData);
} }
} else { } else {
emitter.emit(messageCommand, messageData); emitter.emit(messageCommand, messageData);
} }
} catch (error) { } catch (error) {
emitError(error); emitError(error);
} }
@ -194,7 +188,6 @@ exports.write = (image, drive, options) => {
// This function causes the `close` event to be emitted // This function causes the `close` event to be emitted
child.kill(); child.kill();
}); });
child.on('error', emitError); child.on('error', emitError);

View File

@ -47,5 +47,4 @@ exports.getApplicationEntryPoint = () => {
// from `/root`, therefore we pass an absolute path, // from `/root`, therefore we pass an absolute path,
// in order to be on the safe side. // in order to be on the safe side.
return path.join(CONSTANTS.PROJECT_ROOT, relativeEntryPoint); return path.join(CONSTANTS.PROJECT_ROOT, relativeEntryPoint);
}; };

View File

@ -64,14 +64,12 @@ const OPTIONS_INDEX_START = 2;
*/ */
const etcherArguments = process.argv.slice(OPTIONS_INDEX_START); const etcherArguments = process.argv.slice(OPTIONS_INDEX_START);
return permissions.isElevated().then((elevated) => { permissions.isElevated().then((elevated) => {
if (!elevated) { if (!elevated) {
console.log('Attempting to elevate'); console.log('Attempting to elevate');
const commandArguments = _.attempt(() => { const commandArguments = _.attempt(() => {
if (os.platform() === 'linux' && process.env.APPIMAGE && process.env.APPDIR) { if (os.platform() === 'linux' && process.env.APPIMAGE && process.env.APPDIR) {
// Translate the current arguments to point to the AppImage // Translate the current arguments to point to the AppImage
// Relative paths are resolved from `/tmp/.mount_XXXXXX/usr` // Relative paths are resolved from `/tmp/.mount_XXXXXX/usr`
const translatedArguments = _.chain(process.argv) const translatedArguments = _.chain(process.argv)
@ -125,7 +123,6 @@ return permissions.isElevated().then((elevated) => {
ipc.connectTo(process.env.IPC_SERVER_ID, () => { ipc.connectTo(process.env.IPC_SERVER_ID, () => {
ipc.of[process.env.IPC_SERVER_ID].on('error', reject); ipc.of[process.env.IPC_SERVER_ID].on('error', reject);
ipc.of[process.env.IPC_SERVER_ID].on('connect', () => { ipc.of[process.env.IPC_SERVER_ID].on('connect', () => {
const child = childProcess.spawn(executable, etcherArguments, { const child = childProcess.spawn(executable, etcherArguments, {
env: { env: {
@ -160,7 +157,6 @@ return permissions.isElevated().then((elevated) => {
* }))); * })));
*/ */
const emitMessage = (data) => { const emitMessage = (data) => {
// Output from stdout/stderr coming from the CLI might be buffered, // Output from stdout/stderr coming from the CLI might be buffered,
// causing several progress lines to come up at once as single message. // causing several progress lines to come up at once as single message.
// Trying to parse multiple JSON objects separated by new lines will // Trying to parse multiple JSON objects separated by new lines will
@ -168,7 +164,6 @@ return permissions.isElevated().then((elevated) => {
_.each(utils.splitObjectLines(data.toString()), (object) => { _.each(utils.splitObjectLines(data.toString()), (object) => {
ipc.of[process.env.IPC_SERVER_ID].emit('message', object); ipc.of[process.env.IPC_SERVER_ID].emit('message', object);
}); });
}; };
child.stdout.on('data', emitMessage); child.stdout.on('data', emitMessage);

View File

@ -94,7 +94,6 @@ permissions.isElevated().then((elevated) => {
unmountOnSuccess: options.unmount, unmountOnSuccess: options.unmount,
validateWriteOnSuccess: options.check validateWriteOnSuccess: options.check
}, (state) => { }, (state) => {
if (robot.isEnabled(process.env)) { if (robot.isEnabled(process.env)) {
robot.printMessage('progress', { robot.printMessage('progress', {
type: state.type, type: state.type,
@ -105,7 +104,6 @@ permissions.isElevated().then((elevated) => {
} else { } else {
progressBars[state.type].update(state); progressBars[state.type].update(state);
} }
}).then((results) => { }).then((results) => {
return { return {
imagePath, imagePath,
@ -115,7 +113,6 @@ permissions.isElevated().then((elevated) => {
}); });
}); });
}).then((results) => { }).then((results) => {
return Bluebird.try(() => { return Bluebird.try(() => {
if (robot.isEnabled(process.env)) { if (robot.isEnabled(process.env)) {
return robot.printMessage('done', { return robot.printMessage('done', {
@ -136,9 +133,7 @@ permissions.isElevated().then((elevated) => {
}).then(() => { }).then(() => {
process.exit(EXIT_CODES.SUCCESS); process.exit(EXIT_CODES.SUCCESS);
}); });
}).catch((error) => { }).catch((error) => {
return Bluebird.try(() => { return Bluebird.try(() => {
if (robot.isEnabled(process.env)) { if (robot.isEnabled(process.env)) {
return robot.printError(error); return robot.printError(error);
@ -153,5 +148,4 @@ permissions.isElevated().then((elevated) => {
process.exit(EXIT_CODES.GENERAL_ERROR); process.exit(EXIT_CODES.GENERAL_ERROR);
}); });
}); });

View File

@ -65,7 +65,6 @@ const UNMOUNT_ON_SUCCESS_TIMEOUT_MS = 2000;
*/ */
exports.writeImage = (imagePath, drive, options, onProgress) => { exports.writeImage = (imagePath, drive, options, onProgress) => {
return Bluebird.try(() => { return Bluebird.try(() => {
// Unmounting a drive in Windows means we can't write to it anymore // Unmounting a drive in Windows means we can't write to it anymore
if (os.platform() === 'win32') { if (os.platform() === 'win32') {
return Bluebird.resolve(); return Bluebird.resolve();
@ -103,14 +102,12 @@ exports.writeImage = (imagePath, drive, options, onProgress) => {
writer.on('done', resolve); writer.on('done', resolve);
}); });
}).tap(() => { }).tap(() => {
// Make sure the device stream file descriptor is closed // Make sure the device stream file descriptor is closed
// before returning control the the caller. Not closing // before returning control the the caller. Not closing
// the file descriptor (and waiting for it) results in // the file descriptor (and waiting for it) results in
// `EBUSY` errors when attempting to unmount the drive // `EBUSY` errors when attempting to unmount the drive
// right afterwards in some Windows 7 systems. // right afterwards in some Windows 7 systems.
return fs.closeAsync(driveFileDescriptor).then(() => { return fs.closeAsync(driveFileDescriptor).then(() => {
if (!options.unmountOnSuccess) { if (!options.unmountOnSuccess) {
return Bluebird.resolve(); return Bluebird.resolve();
} }
@ -122,7 +119,6 @@ exports.writeImage = (imagePath, drive, options, onProgress) => {
return Bluebird.delay(UNMOUNT_ON_SUCCESS_TIMEOUT_MS) return Bluebird.delay(UNMOUNT_ON_SUCCESS_TIMEOUT_MS)
.return(drive.device) .return(drive.device)
.then(mountutils.unmountDiskAsync); .then(mountutils.unmountDiskAsync);
}); });
}); });
}); });

View File

@ -184,7 +184,6 @@ app.run(() => {
app.run(($timeout) => { app.run(($timeout) => {
driveScanner.on('drives', (drives) => { driveScanner.on('drives', (drives) => {
// Safely trigger a digest cycle. // Safely trigger a digest cycle.
// In some cases, AngularJS doesn't acknowledge that the // In some cases, AngularJS doesn't acknowledge that the
// available drives list has changed, and incorrectly // available drives list has changed, and incorrectly
@ -195,7 +194,6 @@ app.run(($timeout) => {
}); });
driveScanner.on('error', (error) => { driveScanner.on('error', (error) => {
// Stop the drive scanning loop in case of errors, // Stop the drive scanning loop in case of errors,
// otherwise we risk presenting the same error over // otherwise we risk presenting the same error over
// and over again to the user, while also heavily // and over again to the user, while also heavily
@ -241,7 +239,6 @@ app.run(($window) => {
// This circumvents the 'beforeunload' event unlike // This circumvents the 'beforeunload' event unlike
// electron.remote.app.quit() which does not. // electron.remote.app.quit() which does not.
electron.remote.process.exit(EXIT_CODES.SUCCESS); electron.remote.process.exit(EXIT_CODES.SUCCESS);
} }
analytics.logEvent('Close rejected while flashing'); analytics.logEvent('Close rejected while flashing');
@ -252,7 +249,6 @@ app.run(($window) => {
app.run(($rootScope) => { app.run(($rootScope) => {
$rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState) => { $rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState) => {
// Ignore first navigation // Ignore first navigation
if (!fromState.name) { if (!fromState.name) {
return; return;
@ -279,7 +275,6 @@ app.config(($provide) => {
}); });
app.controller('HeaderController', function (OSOpenExternalService) { app.controller('HeaderController', function (OSOpenExternalService) {
/** /**
* @summary Open help page * @summary Open help page
* @function * @function
@ -297,7 +292,6 @@ app.controller('HeaderController', function(OSOpenExternalService) {
const supportUrl = selectionState.getImageSupportUrl() || DEFAULT_SUPPORT_URL; const supportUrl = selectionState.getImageSupportUrl() || DEFAULT_SUPPORT_URL;
OSOpenExternalService.open(supportUrl); OSOpenExternalService.open(supportUrl);
}; };
}); });
app.controller('StateController', function ($rootScope, $scope) { app.controller('StateController', function ($rootScope, $scope) {
@ -335,5 +329,4 @@ app.controller('StateController', function($rootScope, $scope) {
* } * }
*/ */
this.currentName = null; this.currentName = null;
}); });

View File

@ -29,7 +29,6 @@ module.exports = function(
$uibModalInstance, $uibModalInstance,
WarningModalService WarningModalService
) { ) {
/** /**
* @summary The drive selector state * @summary The drive selector state
* @type {Object} * @type {Object}
@ -108,7 +107,6 @@ module.exports = function(
* }); * });
*/ */
this.toggleDrive = (drive) => { this.toggleDrive = (drive) => {
analytics.logEvent('Toggle drive', { analytics.logEvent('Toggle drive', {
drive, drive,
previouslySelected: selectionState.isCurrentDrive(drive.device) previouslySelected: selectionState.isCurrentDrive(drive.device)
@ -118,7 +116,6 @@ module.exports = function(
if (canChangeDriveSelectionState) { if (canChangeDriveSelectionState) {
selectionState.toggleSetDrive(drive.device); selectionState.toggleSetDrive(drive.device);
} }
}); });
}; };
@ -141,7 +138,6 @@ module.exports = function(
} else { } else {
$uibModalInstance.close(selectedDrive); $uibModalInstance.close(selectedDrive);
} }
}; };
/** /**
@ -208,7 +204,6 @@ module.exports = function(
areArgsInTuple = true; areArgsInTuple = true;
if (angular.equals(state, oldState)) { if (angular.equals(state, oldState)) {
// Use the previously memoized state for this argument // Use the previously memoized state for this argument
state = oldState; state = oldState;
} }
@ -224,7 +219,6 @@ module.exports = function(
// Add the state associated with these args to be memoized // Add the state associated with these args to be memoized
if (!areArgsInTuple) { if (!areArgsInTuple) {
previousTuples.push([ restArgs, state ]); previousTuples.push([ restArgs, state ]);
} }
return state; return state;
@ -257,5 +251,4 @@ module.exports = function(
this.getDriveStatuses = this.memoizeImmutableListReference((drive) => { this.getDriveStatuses = this.memoizeImmutableListReference((drive) => {
return this.constraints.getDriveImageCompatibilityStatuses(drive, this.state.getImage()); return this.constraints.getDriveImageCompatibilityStatuses(drive, this.state.getImage());
}); });
}; };

View File

@ -17,7 +17,6 @@
'use strict'; 'use strict';
module.exports = function (ModalService, $q) { module.exports = function (ModalService, $q) {
let modal = null; let modal = null;
/** /**
@ -55,7 +54,6 @@ module.exports = function(ModalService, $q) {
* DriveSelectorService.close(); * DriveSelectorService.close();
*/ */
this.close = () => { this.close = () => {
if (modal) { if (modal) {
return modal.close(); return modal.close();
} }
@ -63,7 +61,5 @@ module.exports = function(ModalService, $q) {
// Resolve `undefined` if the modal // Resolve `undefined` if the modal
// was already closed for consistency // was already closed for consistency
return $q.resolve(); return $q.resolve();
}; };
}; };

View File

@ -21,7 +21,6 @@ const selectionState = require('../../../../shared/models/selection-state');
const analytics = require('../../../modules/analytics'); const analytics = require('../../../modules/analytics');
module.exports = function (WarningModalService) { module.exports = function (WarningModalService) {
/** /**
* @summary Open the flash error modal * @summary Open the flash error modal
* @function * @function
@ -47,5 +46,4 @@ module.exports = function(WarningModalService) {
} }
}); });
}; };
}; };

View File

@ -20,7 +20,6 @@ const _ = require('lodash');
const analytics = require('../../../modules/analytics'); const analytics = require('../../../modules/analytics');
module.exports = function ($uibModal, $q) { module.exports = function ($uibModal, $q) {
/** /**
* @summary Open a modal * @summary Open a modal
* @function * @function
@ -40,7 +39,6 @@ module.exports = function($uibModal, $q) {
* }); * });
*/ */
this.open = (options = {}) => { this.open = (options = {}) => {
_.defaults(options, { _.defaults(options, {
size: 'sm' size: 'sm'
}); });
@ -67,7 +65,6 @@ module.exports = function($uibModal, $q) {
resolve(value); resolve(value);
}).catch((error) => { }).catch((error) => {
// Bootstrap doesn't 'resolve' these but cancels the dialog // Bootstrap doesn't 'resolve' these but cancels the dialog
if (error === 'escape key press' || error === 'backdrop click') { if (error === 'escape key press' || error === 'backdrop click') {
analytics.logEvent('Modal rejected', { analytics.logEvent('Modal rejected', {
@ -86,5 +83,4 @@ module.exports = function($uibModal, $q) {
}) })
}; };
}; };
}; };

View File

@ -78,7 +78,6 @@ const API_VERSION = 1;
* <safe-webview src="https://etcher.io/"></safe-webview> * <safe-webview src="https://etcher.io/"></safe-webview>
*/ */
class SafeWebview extends react.PureComponent { class SafeWebview extends react.PureComponent {
/** /**
* @param {Object} props - React element properties * @param {Object} props - React element properties
*/ */
@ -89,7 +88,7 @@ class SafeWebview extends react.PureComponent {
shouldShow: true shouldShow: true
}; };
const url = new URL(props.src); const url = new window.URL(props.src);
// We set the version GET parameters here. // We set the version GET parameters here.
url.searchParams.set(ETCHER_VERSION_PARAM, packageJSON.version); url.searchParams.set(ETCHER_VERSION_PARAM, packageJSON.version);
@ -134,7 +133,6 @@ class SafeWebview extends react.PureComponent {
* @summary Add the Webview events * @summary Add the Webview events
*/ */
componentDidMount () { componentDidMount () {
// Events React is unaware of have to be handled manually // Events React is unaware of have to be handled manually
_.map(this.eventTuples, (tuple) => { _.map(this.eventTuples, (tuple) => {
this.refs.webview.addEventListener(...tuple); this.refs.webview.addEventListener(...tuple);
@ -152,7 +150,6 @@ class SafeWebview extends react.PureComponent {
* @summary Remove the Webview events * @summary Remove the Webview events
*/ */
componentWillUnmount () { componentWillUnmount () {
// Events that React is unaware of have to be handled manually // Events that React is unaware of have to be handled manually
_.map(this.eventTuples, (tuple) => { _.map(this.eventTuples, (tuple) => {
this.refs.webview.removeEventListener(...tuple); this.refs.webview.removeEventListener(...tuple);
@ -165,13 +162,11 @@ class SafeWebview extends react.PureComponent {
*/ */
componentWillReceiveProps (nextProps) { componentWillReceiveProps (nextProps) {
if (nextProps.refreshNow && !this.props.refreshNow) { if (nextProps.refreshNow && !this.props.refreshNow) {
// Reload the page if it hasn't changed, otherwise reset the source URL, // Reload the page if it hasn't changed, otherwise reset the source URL,
// because reload interferes with 'src' setting, resetting the 'src' attribute // because reload interferes with 'src' setting, resetting the 'src' attribute
// to what it was was just prior. // to what it was was just prior.
if (this.refs.webview.src === this.entryHref) { if (this.refs.webview.src === this.entryHref) {
this.refs.webview.reload(); this.refs.webview.reload();
} else { } else {
this.refs.webview.src = this.entryHref; this.refs.webview.src = this.entryHref;
} }
@ -209,7 +204,7 @@ class SafeWebview extends react.PureComponent {
* @param {Event} event - event object * @param {Event} event - event object
*/ */
static newWindow (event) { static newWindow (event) {
const url = new URL(event.url); const url = new window.URL(event.url);
if (_.every([ if (_.every([
url.protocol === 'http:' || url.protocol === 'https:', url.protocol === 'http:' || url.protocol === 'https:',
@ -245,12 +240,10 @@ class SafeWebview extends react.PureComponent {
if (robot.getCommand(message) === robot.COMMAND.LOG) { if (robot.getCommand(message) === robot.COMMAND.LOG) {
analytics.logEvent(robot.getData(message)); analytics.logEvent(robot.getData(message));
} else if (robot.getCommand(message) === robot.COMMAND.ERROR) { } else if (robot.getCommand(message) === robot.COMMAND.ERROR) {
analytics.logException(robot.getData(message)); analytics.logException(robot.getData(message));
} }
} }
} }
SafeWebview.propTypes = { SafeWebview.propTypes = {

View File

@ -41,13 +41,11 @@ const DEFAULT_SIZE = '40px';
* @public * @public
*/ */
class SVGIcon extends react.Component { class SVGIcon extends react.Component {
/** /**
* @summary Render the SVG * @summary Render the SVG
* @returns {react.Element} * @returns {react.Element}
*/ */
render () { render () {
// This means the path to the icon should be // This means the path to the icon should be
// relative to *this directory*. // relative to *this directory*.
// TODO: There might be a way to compute the path // TODO: There might be a way to compute the path
@ -58,7 +56,6 @@ class SVGIcon extends react.Component {
if (_.startsWith(this.props.path, '<')) { if (_.startsWith(this.props.path, '<')) {
contents = this.props.path; contents = this.props.path;
} else { } else {
contents = fs.readFileSync(imagePath, { contents = fs.readFileSync(imagePath, {
encoding: 'utf8' encoding: 'utf8'
@ -68,7 +65,7 @@ class SVGIcon extends react.Component {
const width = this.props.width || DEFAULT_SIZE; const width = this.props.width || DEFAULT_SIZE;
const height = this.props.height || DEFAULT_SIZE; const height = this.props.height || DEFAULT_SIZE;
const parser = new DOMParser(); const parser = new window.DOMParser();
const doc = parser.parseFromString(contents, 'image/svg+xml'); const doc = parser.parseFromString(contents, 'image/svg+xml');
const svg = doc.querySelector('svg'); const svg = doc.querySelector('svg');
@ -95,11 +92,9 @@ class SVGIcon extends react.Component {
* @param {Object} nextProps - the new properties * @param {Object} nextProps - the new properties
*/ */
componentWillReceiveProps (nextProps) { componentWillReceiveProps (nextProps) {
// This will update the element if the properties change // This will update the element if the properties change
this.setState(nextProps); this.setState(nextProps);
} }
} }
SVGIcon.propTypes = { SVGIcon.propTypes = {

View File

@ -17,7 +17,6 @@
'use strict'; 'use strict';
module.exports = function ($uibModalInstance, tooltipData) { module.exports = function ($uibModalInstance, tooltipData) {
/** /**
* @summary Tooltip data * @summary Tooltip data
* @type {Object} * @type {Object}
@ -36,5 +35,4 @@ module.exports = function($uibModalInstance, tooltipData) {
this.closeModal = () => { this.closeModal = () => {
$uibModalInstance.dismiss(); $uibModalInstance.dismiss();
}; };
}; };

View File

@ -19,7 +19,6 @@
const _ = require('lodash'); const _ = require('lodash');
module.exports = function (ModalService) { module.exports = function (ModalService) {
/** /**
* @summary Open the tooltip modal * @summary Open the tooltip modal
* @function * @function
@ -46,5 +45,4 @@ module.exports = function(ModalService) {
} }
}).result; }).result;
}; };
}; };

View File

@ -125,7 +125,6 @@ exports.notify = (version, options = {}) => {
}); });
}); });
}).tap((results) => { }).tap((results) => {
// Only update the last slept update timestamp if the // Only update the last slept update timestamp if the
// user ticked the "Remind me again in ..." checkbox, // user ticked the "Remind me again in ..." checkbox,
// but didn't agree. // but didn't agree.

View File

@ -17,7 +17,6 @@
'use strict'; 'use strict';
module.exports = function ($uibModalInstance, options) { module.exports = function ($uibModalInstance, options) {
/** /**
* @summary Modal options * @summary Modal options
* @type {Object} * @type {Object}
@ -48,5 +47,4 @@ module.exports = function($uibModalInstance, options) {
this.accept = () => { this.accept = () => {
$uibModalInstance.close(true); $uibModalInstance.close(true);
}; };
}; };

View File

@ -19,7 +19,6 @@
const _ = require('lodash'); const _ = require('lodash');
module.exports = function ($sce, ModalService) { module.exports = function ($sce, ModalService) {
/** /**
* @summary Display the warning modal * @summary Display the warning modal
* @function * @function
@ -49,5 +48,4 @@ module.exports = function($sce, ModalService) {
} }
}).result; }).result;
}; };
}; };

View File

@ -39,7 +39,6 @@ electron.app.on('before-quit', () => {
}); });
electron.app.on('ready', () => { electron.app.on('ready', () => {
// No menu bar // No menu bar
electron.Menu.setApplicationMenu(null); electron.Menu.setApplicationMenu(null);
@ -83,7 +82,6 @@ electron.app.on('ready', () => {
// See: https://github.com/electron/electron/issues/8841 // See: https://github.com/electron/electron/issues/8841
electron.globalShortcut.register('CmdOrCtrl+R', _.noop); electron.globalShortcut.register('CmdOrCtrl+R', _.noop);
electron.globalShortcut.register('F5', _.noop); electron.globalShortcut.register('F5', _.noop);
}); });
mainWindow.on('blur', () => { mainWindow.on('blur', () => {
@ -109,4 +107,3 @@ electron.app.on('ready', () => {
mainWindow.loadURL(`file://${path.join(__dirname, 'index.html')}`); mainWindow.loadURL(`file://${path.join(__dirname, 'index.html')}`);
}); });

View File

@ -40,7 +40,7 @@ const LOCAL_STORAGE_SETTINGS_KEY = 'etcher-settings';
*/ */
exports.readAll = () => { exports.readAll = () => {
return Bluebird.try(() => { return Bluebird.try(() => {
return JSON.parse(localStorage.getItem(LOCAL_STORAGE_SETTINGS_KEY)) || {}; return JSON.parse(window.localStorage.getItem(LOCAL_STORAGE_SETTINGS_KEY)) || {};
}); });
}; };
@ -62,7 +62,7 @@ exports.readAll = () => {
exports.writeAll = (settings) => { exports.writeAll = (settings) => {
const INDENTATION_SPACES = 2; const INDENTATION_SPACES = 2;
return Bluebird.try(() => { return Bluebird.try(() => {
localStorage.setItem(LOCAL_STORAGE_SETTINGS_KEY, JSON.stringify(settings, null, INDENTATION_SPACES)); window.localStorage.setItem(LOCAL_STORAGE_SETTINGS_KEY, JSON.stringify(settings, null, INDENTATION_SPACES));
}); });
}; };
@ -83,6 +83,6 @@ exports.writeAll = (settings) => {
*/ */
exports.clear = () => { exports.clear = () => {
return Bluebird.try(() => { return Bluebird.try(() => {
localStorage.removeItem(LOCAL_STORAGE_SETTINGS_KEY); window.localStorage.removeItem(LOCAL_STORAGE_SETTINGS_KEY);
}); });
}; };

View File

@ -56,7 +56,6 @@ const setSettingsObject = (settings) => {
data: settings data: settings
}); });
}).then(() => { }).then(() => {
// Revert the application state if writing the data // Revert the application state if writing the data
// to the local machine was not successful // to the local machine was not successful
return localSettings.writeAll(settings).catch((error) => { return localSettings.writeAll(settings).catch((error) => {
@ -67,7 +66,6 @@ const setSettingsObject = (settings) => {
throw error; throw error;
}); });
}); });
}; };

View File

@ -33,7 +33,6 @@ const MODULE_NAME = 'Etcher.Modules.ImageWriter';
const imageWriter = angular.module(MODULE_NAME, []); const imageWriter = angular.module(MODULE_NAME, []);
imageWriter.service('ImageWriterService', function ($q, $rootScope) { imageWriter.service('ImageWriterService', function ($q, $rootScope) {
/** /**
* @summary Perform write operation * @summary Perform write operation
* @function * @function
@ -105,7 +104,6 @@ imageWriter.service('ImageWriterService', function($q, $rootScope) {
analytics.logEvent('Flash', analyticsData); analytics.logEvent('Flash', analyticsData);
return this.performWrite(image, drive, (state) => { return this.performWrite(image, drive, (state) => {
// Bring this value to the world of angular. // Bring this value to the world of angular.
// If we don't trigger a digest loop, // If we don't trigger a digest loop,
// `.getFlashState()` will not return // `.getFlashState()` will not return
@ -113,7 +111,6 @@ imageWriter.service('ImageWriterService', function($q, $rootScope) {
$rootScope.$apply(() => { $rootScope.$apply(() => {
flashState.setProgressState(state); flashState.setProgressState(state);
}); });
}).then(flashState.unsetFlashingFlag).then(() => { }).then(flashState.unsetFlashingFlag).then(() => {
if (flashState.wasLastFlashCancelled()) { if (flashState.wasLastFlashCancelled()) {
analytics.logEvent('Elevation cancelled', analyticsData); analytics.logEvent('Elevation cancelled', analyticsData);
@ -144,7 +141,6 @@ imageWriter.service('ImageWriterService', function($q, $rootScope) {
windowProgress.clear(); windowProgress.clear();
}); });
}; };
}); });
module.exports = MODULE_NAME; module.exports = MODULE_NAME;

View File

@ -68,12 +68,10 @@ exports.selectImage = () => {
} }
] ]
}, (files) => { }, (files) => {
// `_.first` is smart enough to not throw and return `undefined` // `_.first` is smart enough to not throw and return `undefined`
// if we pass it an `undefined` value (e.g: when the selection // if we pass it an `undefined` value (e.g: when the selection
// dialog was cancelled). // dialog was cancelled).
return resolve(_.first(files)); return resolve(_.first(files));
}); });
}); });
}; };

View File

@ -41,11 +41,10 @@ const electron = require('electron');
* }); * });
*/ */
exports.send = (title, options) => { exports.send = (title, options) => {
// `app.dock` is only defined in OS X // `app.dock` is only defined in OS X
if (electron.remote.app.dock) { if (electron.remote.app.dock) {
electron.remote.app.dock.bounce(); electron.remote.app.dock.bounce();
} }
return new Notification(title, options); return new window.Notification(title, options);
}; };

View File

@ -36,7 +36,6 @@ module.exports = (OSOpenExternalService) => {
restrict: 'A', restrict: 'A',
scope: false, scope: false,
link: (scope, element, attributes) => { link: (scope, element, attributes) => {
// This directive might be added to elements // This directive might be added to elements
// other than buttons. // other than buttons.
element.css('cursor', 'pointer'); element.css('cursor', 'pointer');

View File

@ -32,9 +32,10 @@ OSOpenExternal.run((OSOpenExternalService) => {
document.addEventListener('click', (event) => { document.addEventListener('click', (event) => {
const target = event.target; const target = event.target;
if (target.tagName === 'A' && angular.isDefined(target.href)) { if (target.tagName === 'A' && angular.isDefined(target.href)) {
// Electron interprets relative URLs as being relative to the
// Electron interprets relative URLs as being relative to the current loaded URL (with `webContents.loadURL`) and expands // current loaded URL (with `webContents.loadURL`) and expands
// them to the corresponding absolute URL. If it's a `file://` URL, we don't want it opened in an external browser. // them to the corresponding absolute URL. If it's a `file://`
// URL, we don't want it opened in an external browser.
if (url.parse(target.href).protocol !== 'file:') { if (url.parse(target.href).protocol !== 'file:') {
OSOpenExternalService.open(target.href); OSOpenExternalService.open(target.href);
} }

View File

@ -20,7 +20,6 @@ const electron = require('electron');
const analytics = require('../../../modules/analytics'); const analytics = require('../../../modules/analytics');
module.exports = function () { module.exports = function () {
/** /**
* @summary Open an external resource * @summary Open an external resource
* @function * @function
@ -40,5 +39,4 @@ module.exports = function() {
electron.shell.openExternal(url); electron.shell.openExternal(url);
} }
}; };
}; };

View File

@ -55,7 +55,6 @@ exports.set = (percentage) => {
* windowProgress.clear(); * windowProgress.clear();
*/ */
exports.clear = () => { exports.clear = () => {
// Passing 0 or null/undefined doesn't work. // Passing 0 or null/undefined doesn't work.
const ELECTRON_PROGRESS_BAR_RESET_VALUE = -1; const ELECTRON_PROGRESS_BAR_RESET_VALUE = -1;

View File

@ -22,7 +22,6 @@ const selectionState = require('../../../../shared/models/selection-state');
const analytics = require('../../../modules/analytics'); const analytics = require('../../../modules/analytics');
module.exports = function ($state) { module.exports = function ($state) {
/** /**
* @summary Settings model * @summary Settings model
* @type {Object} * @type {Object}
@ -53,5 +52,4 @@ module.exports = function($state) {
analytics.logEvent('Restart', options); analytics.logEvent('Restart', options);
$state.go('main'); $state.go('main');
}; };
}; };

View File

@ -22,7 +22,6 @@ const analytics = require('../../../modules/analytics');
const exceptionReporter = require('../../../modules/exception-reporter'); const exceptionReporter = require('../../../modules/exception-reporter');
module.exports = function (DriveSelectorService) { module.exports = function (DriveSelectorService) {
/** /**
* @summary Open drive selector * @summary Open drive selector
* @function * @function
@ -58,5 +57,4 @@ module.exports = function(DriveSelectorService) {
this.openDriveSelector(); this.openDriveSelector();
analytics.logEvent('Reselect drive'); analytics.logEvent('Reselect drive');
}; };
}; };

View File

@ -30,7 +30,6 @@ module.exports = function(
ImageWriterService, ImageWriterService,
FlashErrorModalService FlashErrorModalService
) { ) {
/** /**
* @summary Flash image to a drive * @summary Flash image to a drive
* @function * @function
@ -98,9 +97,7 @@ module.exports = function(
FlashErrorModalService.show(messages.error.genericFlashError()); FlashErrorModalService.show(messages.error.genericFlashError());
exceptionReporter.report(error); exceptionReporter.report(error);
} }
}).finally(() => {
})
.finally(() => {
driveScanner.start(); driveScanner.start();
}); });
}; };
@ -135,5 +132,4 @@ module.exports = function(
return `${currentFlashState.percentage}%`; return `${currentFlashState.percentage}%`;
}; };
}; };

View File

@ -32,7 +32,6 @@ module.exports = function(
$timeout, $timeout,
WarningModalService WarningModalService
) { ) {
/** /**
* @summary Main supported extensions * @summary Main supported extensions
* @constant * @constant
@ -103,9 +102,7 @@ module.exports = function(
} }
return false; return false;
}).then((shouldChange) => { }).then((shouldChange) => {
if (shouldChange) { if (shouldChange) {
return this.reselectImage(); return this.reselectImage();
} }
@ -164,7 +161,6 @@ module.exports = function(
analytics.logEvent('Open image selector'); analytics.logEvent('Open image selector');
osDialog.selectImage().then((imagePath) => { osDialog.selectImage().then((imagePath) => {
// Avoid analytics and selection state changes // Avoid analytics and selection state changes
// if no file was resolved from the dialog. // if no file was resolved from the dialog.
if (!imagePath) { if (!imagePath) {
@ -209,5 +205,4 @@ module.exports = function(
return path.basename(selectionState.getImagePath()); return path.basename(selectionState.getImagePath());
}; };
}; };

View File

@ -27,7 +27,6 @@ module.exports = function(
TooltipModalService, TooltipModalService,
OSOpenExternalService OSOpenExternalService
) { ) {
// Expose several modules to the template for convenience // Expose several modules to the template for convenience
this.selection = selectionState; this.selection = selectionState;
this.drives = availableDrives; this.drives = availableDrives;
@ -87,5 +86,4 @@ module.exports = function(
message: selectionState.getImagePath() message: selectionState.getImagePath()
}).catch(exceptionReporter.report); }).catch(exceptionReporter.report);
}; };
}; };

View File

@ -23,7 +23,6 @@ const analytics = require('../../../modules/analytics');
const exceptionReporter = require('../../../modules/exception-reporter'); const exceptionReporter = require('../../../modules/exception-reporter');
module.exports = function (WarningModalService) { module.exports = function (WarningModalService) {
/** /**
* @summary Client platform * @summary Client platform
* @type {String} * @type {String}
@ -82,7 +81,6 @@ module.exports = function(WarningModalService) {
* }); * });
*/ */
this.toggle = (setting, options) => { this.toggle = (setting, options) => {
const value = this.currentData[setting]; const value = this.currentData[setting];
const dangerous = !_.isUndefined(options); const dangerous = !_.isUndefined(options);
@ -106,5 +104,4 @@ module.exports = function(WarningModalService) {
} }
}).catch(exceptionReporter.report); }).catch(exceptionReporter.report);
}; };
}; };

View File

@ -19,7 +19,6 @@
const units = require('../../../shared/units'); const units = require('../../../shared/units');
module.exports = () => { module.exports = () => {
/** /**
* @summary Convert bytes to the closest unit * @summary Convert bytes to the closest unit
* @function * @function
@ -32,5 +31,4 @@ module.exports = () => {
* {{ 7801405440 | closestUnit }} * {{ 7801405440 | closestUnit }}
*/ */
return units.bytesToClosestUnit; return units.bytesToClosestUnit;
}; };

View File

@ -20,7 +20,6 @@ const _ = require('lodash');
const packageJSON = require('../../../../../package.json'); const packageJSON = require('../../../../../package.json');
module.exports = function () { module.exports = function () {
/** /**
* @summary Get a package.json property * @summary Get a package.json property
* @function * @function
@ -35,5 +34,4 @@ module.exports = function() {
this.get = (attribute) => { this.get = (attribute) => {
return _.get(packageJSON, attribute); return _.get(packageJSON, attribute);
}; };
}; };

View File

@ -172,7 +172,6 @@ const extractArchiveMetadata = (archive, basePath, options) => {
*/ */
exports.extractImage = (archive, hooks) => { exports.extractImage = (archive, hooks) => {
return hooks.getEntries(archive).then((entries) => { return hooks.getEntries(archive).then((entries) => {
const imageEntries = _.filter(entries, (entry) => { const imageEntries = _.filter(entries, (entry) => {
return _.includes(IMAGE_EXTENSIONS, fileExtensions.getLastFileExtension(entry.name)); return _.includes(IMAGE_EXTENSIONS, fileExtensions.getLastFileExtension(entry.name));
}); });

View File

@ -186,9 +186,9 @@ module.exports = {
if (/invalid footer/i.test(error.message)) { if (/invalid footer/i.test(error.message)) {
throw errors.createUserError({ throw errors.createUserError({
title: 'Invalid image', title: 'Invalid image',
description: `There was an error reading "${path.basename(imagePath)}". ` description: `There was an error reading "${path.basename(imagePath)}". ` +
+ 'The image does not appear to be a valid Apple Disk Image (dmg), or may have the wrong filename extension.\n\n' 'The image does not appear to be a valid Apple Disk Image (dmg), or may have the wrong filename extension.\n\n' +
+ `Error: ${error.description || error.message}` `Error: ${error.description || error.message}`
}); });
} }
throw error; throw error;

View File

@ -66,7 +66,6 @@ const MAX_BLOCK_SIZE = 4096;
* } * }
*/ */
const detectGPT = (buffer) => { const detectGPT = (buffer) => {
let blockSize = INITIAL_BLOCK_SIZE; let blockSize = INITIAL_BLOCK_SIZE;
let gpt = null; let gpt = null;
@ -83,7 +82,6 @@ const detectGPT = (buffer) => {
} }
return null; return null;
}; };
/** /**
@ -102,7 +100,6 @@ const detectGPT = (buffer) => {
* } * }
*/ */
const parsePartitionTables = (image, buffer) => { const parsePartitionTables = (image, buffer) => {
const mbr = _.attempt(MBR.parse, buffer); const mbr = _.attempt(MBR.parse, buffer);
let gpt = null; let gpt = null;
@ -138,7 +135,6 @@ const parsePartitionTables = (image, buffer) => {
}; };
}); });
} }
}; };
/** /**
@ -163,7 +159,6 @@ const parsePartitionTables = (image, buffer) => {
*/ */
module.exports = (image) => { module.exports = (image) => {
return new Bluebird((resolve, reject) => { return new Bluebird((resolve, reject) => {
const chunks = []; const chunks = [];
let length = INITIAL_LENGTH; let length = INITIAL_LENGTH;
let destroyed = false; let destroyed = false;
@ -184,7 +179,6 @@ module.exports = (image) => {
// Once we've read enough bytes, terminate the stream // Once we've read enough bytes, terminate the stream
if (length >= MAX_STREAM_BYTES && !destroyed) { if (length >= MAX_STREAM_BYTES && !destroyed) {
// Prefer close() over destroy(), as some streams // Prefer close() over destroy(), as some streams
// from dependencies exhibit quirky behavior when destroyed // from dependencies exhibit quirky behavior when destroyed
if (image.stream.close) { if (image.stream.close) {
@ -202,10 +196,7 @@ module.exports = (image) => {
// Parse the MBR, GPT and partitions from the obtained buffer // Parse the MBR, GPT and partitions from the obtained buffer
parsePartitionTables(image, Buffer.concat(chunks)); parsePartitionTables(image, Buffer.concat(chunks));
resolve(image); resolve(image);
} }
}); });
}); });
}; };

View File

@ -145,7 +145,6 @@ exports.isDriveLargeEnough = (drive, image) => {
const driveSize = _.get(drive, [ 'size' ], UNKNOWN_SIZE); const driveSize = _.get(drive, [ 'size' ], UNKNOWN_SIZE);
if (_.get(image, [ 'size', 'final', 'estimation' ])) { if (_.get(image, [ 'size', 'final', 'estimation' ])) {
// If the drive size is smaller than the original image size, and // If the drive size is smaller than the original image size, and
// the final image size is just an estimation, then we stop right // the final image size is just an estimation, then we stop right
// here, based on the assumption that the final size will never // here, based on the assumption that the final size will never
@ -159,7 +158,6 @@ exports.isDriveLargeEnough = (drive, image) => {
// the drive has ran out of space, instead of prohibiting the flash // the drive has ran out of space, instead of prohibiting the flash
// at all, when the estimation may be wrong. // at all, when the estimation may be wrong.
return true; return true;
} }
return driveSize >= _.get(image, [ return driveSize >= _.get(image, [
@ -349,21 +347,17 @@ exports.getDriveImageCompatibilityStatuses = (drive, image) => {
type: exports.COMPATIBILITY_STATUS_TYPES.ERROR, type: exports.COMPATIBILITY_STATUS_TYPES.ERROR,
message: exports.COMPATIBILITY_STATUS_MESSAGES.CONTAINS_IMAGE message: exports.COMPATIBILITY_STATUS_MESSAGES.CONTAINS_IMAGE
}); });
} else if (exports.isDriveLocked(drive)) { } else if (exports.isDriveLocked(drive)) {
statusList.push({ statusList.push({
type: exports.COMPATIBILITY_STATUS_TYPES.ERROR, type: exports.COMPATIBILITY_STATUS_TYPES.ERROR,
message: exports.COMPATIBILITY_STATUS_MESSAGES.LOCKED message: exports.COMPATIBILITY_STATUS_MESSAGES.LOCKED
}); });
} else if (!_.isNil(drive) && !exports.isDriveLargeEnough(drive, image)) { } else if (!_.isNil(drive) && !exports.isDriveLargeEnough(drive, image)) {
statusList.push({ statusList.push({
type: exports.COMPATIBILITY_STATUS_TYPES.ERROR, type: exports.COMPATIBILITY_STATUS_TYPES.ERROR,
message: exports.COMPATIBILITY_STATUS_MESSAGES.TOO_SMALL message: exports.COMPATIBILITY_STATUS_MESSAGES.TOO_SMALL
}); });
} else { } else {
if (exports.isSystemDrive(drive)) { if (exports.isSystemDrive(drive)) {
statusList.push({ statusList.push({
type: exports.COMPATIBILITY_STATUS_TYPES.WARNING, type: exports.COMPATIBILITY_STATUS_TYPES.WARNING,

View File

@ -326,7 +326,6 @@ exports.isUserError = (error) => {
* > 'foo' * > 'foo'
*/ */
exports.toJSON = (error) => { exports.toJSON = (error) => {
// Handle string error objects to be on the safe side // Handle string error objects to be on the safe side
const isErrorLike = _.isError(error) || _.isPlainObject(error); const isErrorLike = _.isError(error) || _.isPlainObject(error);
const errorObject = isErrorLike ? error : new Error(error); const errorObject = isErrorLike ? error : new Error(error);

View File

@ -123,11 +123,9 @@ exports.setProgressState = (state) => {
speed: _.attempt(() => { speed: _.attempt(() => {
if (_.isNumber(state.speed) && !_.isNaN(state.speed)) { if (_.isNumber(state.speed) && !_.isNaN(state.speed)) {
// Preserve only two decimal places // Preserve only two decimal places
const PRECISION = 2; const PRECISION = 2;
return _.round(units.bytesToMegabytes(state.speed), PRECISION); return _.round(units.bytesToMegabytes(state.speed), PRECISION);
} }
return null; return null;

View File

@ -57,7 +57,6 @@ const UNIX_SUPERUSER_USER_ID = 0;
*/ */
exports.isElevated = () => { exports.isElevated = () => {
if (os.platform() === 'win32') { if (os.platform() === 'win32') {
// `fltmc` is available on WinPE, XP, Vista, 7, 8, and 10 // `fltmc` is available on WinPE, XP, Vista, 7, 8, and 10
// Works even when the "Server" service is disabled // Works even when the "Server" service is disabled
// See http://stackoverflow.com/a/28268802 // See http://stackoverflow.com/a/28268802
@ -66,7 +65,6 @@ exports.isElevated = () => {
.catch({ .catch({
code: os.constants.errno.EPERM code: os.constants.errno.EPERM
}, _.constant(false)); }, _.constant(false));
} }
return Bluebird.resolve(process.geteuid() === UNIX_SUPERUSER_USER_ID); return Bluebird.resolve(process.geteuid() === UNIX_SUPERUSER_USER_ID);
@ -108,11 +106,9 @@ exports.getEnvironmentCommandPrefix = (environment) => {
}); });
if (isWindows) { if (isWindows) {
// This is a trick to make the binary afterwards catch // This is a trick to make the binary afterwards catch
// the environment variables set just previously. // the environment variables set just previously.
return _.concat(argv, [ 'call' ]); return _.concat(argv, [ 'call' ]);
} }
return _.concat([ 'env' ], argv); return _.concat([ 'env' ], argv);
@ -197,7 +193,6 @@ exports.elevateCommand = (command, options) => {
// There doesn't seem to be a better way to handle these errors, so // There doesn't seem to be a better way to handle these errors, so
// for now, we should make sure we double check if the error messages // for now, we should make sure we double check if the error messages
// have changed every time we upgrade `sudo-prompt`. // have changed every time we upgrade `sudo-prompt`.
}).catch((error) => { }).catch((error) => {
return _.includes(error.message, 'is not in the sudoers file'); return _.includes(error.message, 'is not in the sudoers file');
}, () => { }, () => {
@ -219,5 +214,4 @@ exports.elevateCommand = (command, options) => {
description: 'Please install a polkit authentication agent for your desktop environment of choice to continue' description: 'Please install a polkit authentication agent for your desktop environment of choice to continue'
}); });
}); });
}; };

View File

@ -187,7 +187,6 @@ exports.getRemoteVersions = _.memoize((bucketUrl) => {
* } * }
*/ */
const semverSatisfies = (version, range) => { const semverSatisfies = (version, range) => {
// The `semver` module refuses to apply ranges to prerelease versions // The `semver` module refuses to apply ranges to prerelease versions
// As a workaround, we drop the prerelease tags, if any, apply the range // As a workaround, we drop the prerelease tags, if any, apply the range
// on that, and keep using the prerelease tag from then on. // on that, and keep using the prerelease tag from then on.
@ -218,7 +217,6 @@ const semverSatisfies = (version, range) => {
* }); * });
*/ */
exports.getLatestVersion = (releaseType, options = {}) => { exports.getLatestVersion = (releaseType, options = {}) => {
// For manual testing purposes // For manual testing purposes
const ETCHER_FAKE_S3_LATEST_VERSION = process.env.ETCHER_FAKE_S3_LATEST_VERSION; const ETCHER_FAKE_S3_LATEST_VERSION = process.env.ETCHER_FAKE_S3_LATEST_VERSION;
if (!_.isNil(ETCHER_FAKE_S3_LATEST_VERSION)) { if (!_.isNil(ETCHER_FAKE_S3_LATEST_VERSION)) {
@ -235,11 +233,8 @@ exports.getLatestVersion = (releaseType, options = {}) => {
} }
/* eslint-disable lodash/prefer-lodash-method */ /* eslint-disable lodash/prefer-lodash-method */
return exports.getRemoteVersions(bucketUrl).filter((version) => { return exports.getRemoteVersions(bucketUrl).filter((version) => {
/* eslint-enable lodash/prefer-lodash-method */ /* eslint-enable lodash/prefer-lodash-method */
if (_.some([ if (_.some([
// This check allows us to ignore snapshot builds in production // This check allows us to ignore snapshot builds in production

View File

@ -88,7 +88,6 @@ const ACTIONS = _.fromPairs(_.map([
* const drive = findDrive(state, '/dev/disk2'); * const drive = findDrive(state, '/dev/disk2');
*/ */
const findDrive = (state, device) => { const findDrive = (state, device) => {
/* eslint-disable lodash/prefer-lodash-method */ /* eslint-disable lodash/prefer-lodash-method */
return state.get('availableDrives').find((drive) => { return state.get('availableDrives').find((drive) => {
@ -96,7 +95,6 @@ const findDrive = (state, device) => {
}); });
/* eslint-enable lodash/prefer-lodash-method */ /* eslint-enable lodash/prefer-lodash-method */
}; };
/** /**
@ -115,7 +113,6 @@ const findDrive = (state, device) => {
*/ */
const storeReducer = (state = DEFAULT_STATE, action) => { const storeReducer = (state = DEFAULT_STATE, action) => {
switch (action.type) { switch (action.type) {
case ACTIONS.SET_AVAILABLE_DRIVES: { case ACTIONS.SET_AVAILABLE_DRIVES: {
if (!action.data) { if (!action.data) {
throw errors.createError({ throw errors.createError({
@ -134,7 +131,6 @@ const storeReducer = (state = DEFAULT_STATE, action) => {
const AUTOSELECT_DRIVE_COUNT = 1; const AUTOSELECT_DRIVE_COUNT = 1;
const numberOfDrives = action.data.length; const numberOfDrives = action.data.length;
if (numberOfDrives === AUTOSELECT_DRIVE_COUNT) { if (numberOfDrives === AUTOSELECT_DRIVE_COUNT) {
const drive = _.first(action.data); const drive = _.first(action.data);
// Even if there's no image selected, we need to call several // Even if there's no image selected, we need to call several
@ -155,7 +151,6 @@ const storeReducer = (state = DEFAULT_STATE, action) => {
data: drive.device data: drive.device
}); });
} }
} }
const selectedDevice = newState.getIn([ 'selection', 'drive' ]); const selectedDevice = newState.getIn([ 'selection', 'drive' ]);
@ -482,7 +477,6 @@ const storeReducer = (state = DEFAULT_STATE, action) => {
default: { default: {
return state; return state;
} }
} }
}; };

View File

@ -32,7 +32,6 @@ process.env.DEBUG = '*';
// using `child_process.fork()`. // using `child_process.fork()`.
if (process.env.ELECTRON_RUN_AS_NODE || process.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE) { if (process.env.ELECTRON_RUN_AS_NODE || process.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE) {
require('./cli/etcher'); require('./cli/etcher');
} else { } else {
require('./gui/etcher'); require('./gui/etcher');
} }

View File

@ -42,4 +42,3 @@ _.each([
const filename = path.join(currentDirectory, `Dockerfile-${options.architecture}`); const filename = path.join(currentDirectory, `Dockerfile-${options.architecture}`);
fs.writeFileSync(filename, result); fs.writeFileSync(filename, result);
}); });

View File

@ -113,11 +113,9 @@ const getShrinkwrapDependencyManifest = (shrinkwrapPath) => {
.value(); .value();
try { try {
// For example // For example
// ./node_modules/drivelist/node_modules/lodash/package.json // ./node_modules/drivelist/node_modules/lodash/package.json
return require(`.${path.sep}${manifestPath}`); return require(`.${path.sep}${manifestPath}`);
} catch (error) { } catch (error) {
if (error.code === 'MODULE_NOT_FOUND') { if (error.code === 'MODULE_NOT_FOUND') {
return null; return null;

View File

@ -47,7 +47,6 @@ angularValidate.validate(
} }
).then((result) => { ).then((result) => {
_.each(result.failed, (failure) => { _.each(result.failed, (failure) => {
// The module has a typo in the "numbers" property // The module has a typo in the "numbers" property
console.error(chalk.red(`${failure.numerrs} errors at ${path.relative(PROJECT_ROOT, failure.filepath)}`)); console.error(chalk.red(`${failure.numerrs} errors at ${path.relative(PROJECT_ROOT, failure.filepath)}`));
@ -77,9 +76,7 @@ angularValidate.validate(
setTimeout(() => { setTimeout(() => {
process.exit(EXIT_CODES.GENERAL_ERROR); process.exit(EXIT_CODES.GENERAL_ERROR);
}, EXIT_TIMEOUT_MS); }, EXIT_TIMEOUT_MS);
} }
}, (error) => { }, (error) => {
console.error(error); console.error(error);
process.exit(EXIT_CODES.GENERAL_ERROR); process.exit(EXIT_CODES.GENERAL_ERROR);

View File

@ -20,9 +20,7 @@ const m = require('mochainon');
const cli = require('../../lib/child-writer/cli'); const cli = require('../../lib/child-writer/cli');
describe('ChildWriter CLI', function () { describe('ChildWriter CLI', function () {
describe('.getBooleanArgumentForm()', function () { describe('.getBooleanArgumentForm()', function () {
it('should prepend --no if the value is false and option is long', function () { it('should prepend --no if the value is false and option is long', function () {
m.chai.expect(cli.getBooleanArgumentForm('foo', false)).to.equal('--no-foo'); m.chai.expect(cli.getBooleanArgumentForm('foo', false)).to.equal('--no-foo');
}); });
@ -38,11 +36,9 @@ describe('ChildWriter CLI', function() {
it('should prepend - if the value is true and option is short', function () { it('should prepend - if the value is true and option is short', function () {
m.chai.expect(cli.getBooleanArgumentForm('x', true)).to.equal('-x'); m.chai.expect(cli.getBooleanArgumentForm('x', true)).to.equal('-x');
}); });
}); });
describe('.getArguments()', function () { describe('.getArguments()', function () {
it('should return a list of arguments given validate = false, unmount = false', function () { it('should return a list of arguments given validate = false, unmount = false', function () {
m.chai.expect(cli.getArguments({ m.chai.expect(cli.getArguments({
image: 'path/to/image.img', image: 'path/to/image.img',
@ -110,7 +106,5 @@ describe('ChildWriter CLI', function() {
'--check' '--check'
]); ]);
}); });
}); });
}); });

View File

@ -20,9 +20,7 @@ const m = require('mochainon');
const utils = require('../../lib/child-writer/utils'); const utils = require('../../lib/child-writer/utils');
describe('ChildWriter Utils', function () { describe('ChildWriter Utils', function () {
describe('.splitObjectLines()', function () { describe('.splitObjectLines()', function () {
it('should split multiple object lines', function () { it('should split multiple object lines', function () {
const input = '{"id":"foo"}\n{"id":"bar"}\n{"id":"baz"}'; const input = '{"id":"foo"}\n{"id":"bar"}\n{"id":"baz"}';
m.chai.expect(utils.splitObjectLines(input)).to.deep.equal([ m.chai.expect(utils.splitObjectLines(input)).to.deep.equal([
@ -75,7 +73,5 @@ describe('ChildWriter Utils', function() {
'{"id":"baz"}' '{"id":"baz"}'
]); ]);
}); });
}); });
}); });

View File

@ -1,3 +1,19 @@
/*
* Copyright 2017 resin.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict'; 'use strict';
const _ = require('lodash'); const _ = require('lodash');
@ -6,13 +22,11 @@ const angular = require('angular');
require('angular-mocks'); require('angular-mocks');
describe('Browser: DriveSelector', function () { describe('Browser: DriveSelector', function () {
beforeEach(angular.mock.module( beforeEach(angular.mock.module(
require('../../../lib/gui/components/drive-selector/drive-selector') require('../../../lib/gui/components/drive-selector/drive-selector')
)); ));
describe('DriveSelectorController', function () { describe('DriveSelectorController', function () {
let $controller; let $controller;
let $rootScope; let $rootScope;
let $q; let $q;
@ -44,7 +58,6 @@ describe('Browser: DriveSelector', function() {
}); });
describe('.memoizeImmutableListReference()', function () { describe('.memoizeImmutableListReference()', function () {
it('constant true should return memoized true', function () { it('constant true should return memoized true', function () {
const memoizedConstTrue = controller.memoizeImmutableListReference(_.constant(true)); const memoizedConstTrue = controller.memoizeImmutableListReference(_.constant(true));
m.chai.expect(memoizedConstTrue()).to.be.true; m.chai.expect(memoizedConstTrue()).to.be.true;
@ -84,9 +97,6 @@ describe('Browser: DriveSelector', function() {
m.chai.expect(memoizedParameter(angularObjectA)).to.equal(angularObjectA); m.chai.expect(memoizedParameter(angularObjectA)).to.equal(angularObjectA);
m.chai.expect(memoizedParameter(angularObjectB)).to.equal(angularObjectA); m.chai.expect(memoizedParameter(angularObjectB)).to.equal(angularObjectA);
}); });
}); });
}); });
}); });

View File

@ -1,3 +1,19 @@
/*
* Copyright 2017 resin.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict'; 'use strict';
const m = require('mochainon'); const m = require('mochainon');
@ -8,20 +24,17 @@ const angular = require('angular');
require('angular-mocks'); require('angular-mocks');
describe('Browser: SVGIcon', function () { describe('Browser: SVGIcon', function () {
beforeEach(angular.mock.module( beforeEach(angular.mock.module(
require('../../../lib/gui/components/svg-icon') require('../../../lib/gui/components/svg-icon')
)); ));
describe('svgIcon', function () { describe('svgIcon', function () {
let $compile; let $compile;
let $rootScope; let $rootScope;
beforeEach(angular.mock.inject(function (_$compile_, _$rootScope_) { beforeEach(angular.mock.inject(function (_$compile_, _$rootScope_) {
$compile = _$compile_; $compile = _$compile_;
$rootScope = _$rootScope_; $rootScope = _$rootScope_;
})); }));
it('should inline the svg contents in the element', function () { it('should inline the svg contents in the element', function () {
@ -82,7 +95,5 @@ describe('Browser: SVGIcon', function() {
m.chai.expect(element.children().css('width')).to.equal('40px'); m.chai.expect(element.children().css('width')).to.equal('40px');
m.chai.expect(element.children().css('height')).to.equal('20px'); m.chai.expect(element.children().css('height')).to.equal('20px');
}); });
}); });
}); });

View File

@ -22,9 +22,7 @@ const units = require('../../../lib/shared/units');
const updateNotifier = require('../../../lib/gui/components/update-notifier'); const updateNotifier = require('../../../lib/gui/components/update-notifier');
describe('Browser: updateNotifier', function () { describe('Browser: updateNotifier', function () {
describe('.UPDATE_NOTIFIER_SLEEP_DAYS', function () { describe('.UPDATE_NOTIFIER_SLEEP_DAYS', function () {
it('should be an integer', function () { it('should be an integer', function () {
m.chai.expect(_.isInteger(updateNotifier.UPDATE_NOTIFIER_SLEEP_DAYS)).to.be.true; m.chai.expect(_.isInteger(updateNotifier.UPDATE_NOTIFIER_SLEEP_DAYS)).to.be.true;
}); });
@ -32,11 +30,9 @@ describe('Browser: updateNotifier', function() {
it('should be greater than 0', function () { it('should be greater than 0', function () {
m.chai.expect(updateNotifier.UPDATE_NOTIFIER_SLEEP_DAYS > 0).to.be.true; m.chai.expect(updateNotifier.UPDATE_NOTIFIER_SLEEP_DAYS > 0).to.be.true;
}); });
}); });
describe('.shouldCheckForUpdates()', function () { describe('.shouldCheckForUpdates()', function () {
const UPDATE_NOTIFIER_SLEEP_MS = units.daysToMilliseconds(updateNotifier.UPDATE_NOTIFIER_SLEEP_DAYS); const UPDATE_NOTIFIER_SLEEP_MS = units.daysToMilliseconds(updateNotifier.UPDATE_NOTIFIER_SLEEP_DAYS);
_.each([ _.each([
@ -441,7 +437,6 @@ describe('Browser: updateNotifier', function() {
} }
], (testCase) => { ], (testCase) => {
it(_.join([ it(_.join([
`should return ${testCase.expected} if`, `should return ${testCase.expected} if`,
`lastSleptUpdateNotifier=${testCase.options.lastSleptUpdateNotifier},`, `lastSleptUpdateNotifier=${testCase.options.lastSleptUpdateNotifier},`,
@ -450,9 +445,6 @@ describe('Browser: updateNotifier', function() {
], ' '), function () { ], ' '), function () {
m.chai.expect(updateNotifier.shouldCheckForUpdates(testCase.options)).to.equal(testCase.expected); m.chai.expect(updateNotifier.shouldCheckForUpdates(testCase.options)).to.equal(testCase.expected);
}); });
}); });
}); });
}); });

View File

@ -1,3 +1,19 @@
/*
* Copyright 2017 resin.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict'; 'use strict';
const m = require('mochainon'); const m = require('mochainon');
@ -8,7 +24,6 @@ const settings = require('../../../lib/gui/models/settings');
const localSettings = require('../../../lib/gui/models/local-settings'); const localSettings = require('../../../lib/gui/models/local-settings');
describe('Browser: settings', function () { describe('Browser: settings', function () {
beforeEach(function () { beforeEach(function () {
return settings.reset(); return settings.reset();
}); });
@ -26,7 +41,6 @@ describe('Browser: settings', function() {
}); });
describe('.reset()', function () { describe('.reset()', function () {
it('should reset the settings to their default values', function () { it('should reset the settings to their default values', function () {
m.chai.expect(settings.getAll()).to.deep.equal(DEFAULT_SETTINGS); m.chai.expect(settings.getAll()).to.deep.equal(DEFAULT_SETTINGS);
return settings.set('foo', 1234).then(() => { return settings.set('foo', 1234).then(() => {
@ -47,7 +61,6 @@ describe('Browser: settings', function() {
}); });
describe('given the local settings are cleared', function () { describe('given the local settings are cleared', function () {
beforeEach(function () { beforeEach(function () {
return localSettings.clear(); return localSettings.clear();
}); });
@ -57,13 +70,10 @@ describe('Browser: settings', function() {
m.chai.expect(data).to.deep.equal(DEFAULT_SETTINGS); m.chai.expect(data).to.deep.equal(DEFAULT_SETTINGS);
}); });
}); });
}); });
}); });
describe('.assign()', function () { describe('.assign()', function () {
it('should throw if no settings', function (done) { it('should throw if no settings', function (done) {
settings.assign().asCallback((error) => { settings.assign().asCallback((error) => {
m.chai.expect(error).to.be.an.instanceof(Error); m.chai.expect(error).to.be.an.instanceof(Error);
@ -146,11 +156,9 @@ describe('Browser: settings', function() {
}); });
}).catch(done); }).catch(done);
}); });
}); });
describe('.load()', function () { describe('.load()', function () {
it('should extend the application state with the local settings content', function () { it('should extend the application state with the local settings content', function () {
const object = { const object = {
foo: 'bar' foo: 'bar'
@ -172,11 +180,9 @@ describe('Browser: settings', function() {
m.chai.expect(settings.getAll()).to.deep.equal(DEFAULT_SETTINGS); m.chai.expect(settings.getAll()).to.deep.equal(DEFAULT_SETTINGS);
}); });
}); });
}); });
describe('.set()', function () { describe('.set()', function () {
it('should set an unknown key', function () { it('should set an unknown key', function () {
m.chai.expect(settings.get('foobar')).to.be.undefined; m.chai.expect(settings.get('foobar')).to.be.undefined;
return settings.set('foobar', true).then(() => { return settings.set('foobar', true).then(() => {
@ -268,15 +274,11 @@ describe('Browser: settings', function() {
}); });
}).catch(done); }).catch(done);
}); });
}); });
describe('.getAll()', function () { describe('.getAll()', function () {
it('should initial return all default values', function () { it('should initial return all default values', function () {
m.chai.expect(settings.getAll()).to.deep.equal(DEFAULT_SETTINGS); m.chai.expect(settings.getAll()).to.deep.equal(DEFAULT_SETTINGS);
}); });
}); });
}); });

View File

@ -1,3 +1,19 @@
/*
* Copyright 2017 resin.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict'; 'use strict';
const m = require('mochainon'); const m = require('mochainon');
@ -6,9 +22,7 @@ const drivelist = require('drivelist');
const driveScanner = require('../../../lib/gui/modules/drive-scanner'); const driveScanner = require('../../../lib/gui/modules/drive-scanner');
describe('Browser: driveScanner', function () { describe('Browser: driveScanner', function () {
describe('given no available drives', function () { describe('given no available drives', function () {
beforeEach(function () { beforeEach(function () {
this.drivelistStub = m.sinon.stub(drivelist, 'list'); this.drivelistStub = m.sinon.stub(drivelist, 'list');
this.drivelistStub.yields(null, []); this.drivelistStub.yields(null, []);
@ -27,11 +41,9 @@ describe('Browser: driveScanner', function() {
driveScanner.start(); driveScanner.start();
}); });
}); });
describe('given only system available drives', function () { describe('given only system available drives', function () {
beforeEach(function () { beforeEach(function () {
this.drivelistStub = m.sinon.stub(drivelist, 'list'); this.drivelistStub = m.sinon.stub(drivelist, 'list');
this.drivelistStub.yields(null, [ { this.drivelistStub.yields(null, [ {
@ -60,11 +72,9 @@ describe('Browser: driveScanner', function() {
driveScanner.start(); driveScanner.start();
}); });
}); });
describe('given linux', function () { describe('given linux', function () {
beforeEach(function () { beforeEach(function () {
this.osPlatformStub = m.sinon.stub(os, 'platform'); this.osPlatformStub = m.sinon.stub(os, 'platform');
this.osPlatformStub.returns('linux'); this.osPlatformStub.returns('linux');
@ -75,7 +85,6 @@ describe('Browser: driveScanner', function() {
}); });
describe('given available drives', function () { describe('given available drives', function () {
beforeEach(function () { beforeEach(function () {
this.drivelistStub = m.sinon.stub(drivelist, 'list'); this.drivelistStub = m.sinon.stub(drivelist, 'list');
this.drivelistStub.yields(null, [ this.drivelistStub.yields(null, [
@ -157,13 +166,10 @@ describe('Browser: driveScanner', function() {
driveScanner.start(); driveScanner.start();
}); });
}); });
}); });
describe('given windows', function () { describe('given windows', function () {
beforeEach(function () { beforeEach(function () {
this.osPlatformStub = m.sinon.stub(os, 'platform'); this.osPlatformStub = m.sinon.stub(os, 'platform');
this.osPlatformStub.returns('win32'); this.osPlatformStub.returns('win32');
@ -174,7 +180,6 @@ describe('Browser: driveScanner', function() {
}); });
describe('given available drives', function () { describe('given available drives', function () {
beforeEach(function () { beforeEach(function () {
this.drivelistStub = m.sinon.stub(drivelist, 'list'); this.drivelistStub = m.sinon.stub(drivelist, 'list');
this.drivelistStub.yields(null, [ this.drivelistStub.yields(null, [
@ -248,11 +253,9 @@ describe('Browser: driveScanner', function() {
driveScanner.start(); driveScanner.start();
}); });
}); });
describe('given a drive with a single drive letters', function () { describe('given a drive with a single drive letters', function () {
beforeEach(function () { beforeEach(function () {
this.drivelistStub = m.sinon.stub(drivelist, 'list'); this.drivelistStub = m.sinon.stub(drivelist, 'list');
this.drivelistStub.yields(null, [ this.drivelistStub.yields(null, [
@ -285,11 +288,9 @@ describe('Browser: driveScanner', function() {
driveScanner.start(); driveScanner.start();
}); });
}); });
describe('given a drive with multiple drive letters', function () { describe('given a drive with multiple drive letters', function () {
beforeEach(function () { beforeEach(function () {
this.drivesListStub = m.sinon.stub(drivelist, 'list'); this.drivesListStub = m.sinon.stub(drivelist, 'list');
this.drivesListStub.yields(null, [ this.drivesListStub.yields(null, [
@ -328,13 +329,10 @@ describe('Browser: driveScanner', function() {
driveScanner.start(); driveScanner.start();
}); });
}); });
}); });
describe('given an error when listing the drives', function () { describe('given an error when listing the drives', function () {
beforeEach(function () { beforeEach(function () {
this.drivesListStub = m.sinon.stub(drivelist, 'list'); this.drivesListStub = m.sinon.stub(drivelist, 'list');
this.drivesListStub.yields(new Error('scan error')); this.drivesListStub.yields(new Error('scan error'));
@ -354,7 +352,5 @@ describe('Browser: driveScanner', function() {
driveScanner.start(); driveScanner.start();
}); });
}); });
}); });

View File

@ -1,3 +1,19 @@
/*
* Copyright 2017 resin.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict'; 'use strict';
const m = require('mochainon'); const m = require('mochainon');
@ -6,13 +22,11 @@ const flashState = require('../../../lib/shared/models/flash-state');
require('angular-mocks'); require('angular-mocks');
describe('Browser: ImageWriter', function () { describe('Browser: ImageWriter', function () {
beforeEach(angular.mock.module( beforeEach(angular.mock.module(
require('../../../lib/gui/modules/image-writer') require('../../../lib/gui/modules/image-writer')
)); ));
describe('ImageWriterService', function () { describe('ImageWriterService', function () {
let $q; let $q;
let $rootScope; let $rootScope;
let ImageWriterService; let ImageWriterService;
@ -24,9 +38,7 @@ describe('Browser: ImageWriter', function() {
})); }));
describe('.flash()', function () { describe('.flash()', function () {
describe('given a successful write', function () { describe('given a successful write', function () {
beforeEach(function () { beforeEach(function () {
this.performWriteStub = m.sinon.stub(ImageWriterService, 'performWrite'); this.performWriteStub = m.sinon.stub(ImageWriterService, 'performWrite');
this.performWriteStub.returns($q.resolve({ this.performWriteStub.returns($q.resolve({
@ -75,11 +87,9 @@ describe('Browser: ImageWriter', function() {
m.chai.expect(rejectError).to.be.an.instanceof(Error); m.chai.expect(rejectError).to.be.an.instanceof(Error);
m.chai.expect(rejectError.message).to.equal('There is already a flash in progress'); m.chai.expect(rejectError.message).to.equal('There is already a flash in progress');
}); });
}); });
describe('given an unsuccessful write', function () { describe('given an unsuccessful write', function () {
beforeEach(function () { beforeEach(function () {
this.performWriteStub = m.sinon.stub(ImageWriterService, 'performWrite'); this.performWriteStub = m.sinon.stub(ImageWriterService, 'performWrite');
this.error = new Error('write error'); this.error = new Error('write error');
@ -120,11 +130,7 @@ describe('Browser: ImageWriter', function() {
m.chai.expect(rejection).to.be.an.instanceof(Error); m.chai.expect(rejection).to.be.an.instanceof(Error);
m.chai.expect(rejection.message).to.equal('write error'); m.chai.expect(rejection.message).to.equal('write error');
}); });
}); });
}); });
}); });
}); });

View File

@ -21,13 +21,11 @@ const angular = require('angular');
require('angular-mocks'); require('angular-mocks');
describe('Browser: OSDropzone', function () { describe('Browser: OSDropzone', function () {
beforeEach(angular.mock.module( beforeEach(angular.mock.module(
require('../../../lib/gui/os/dropzone/dropzone') require('../../../lib/gui/os/dropzone/dropzone')
)); ));
describe('osDropzone', function () { describe('osDropzone', function () {
let $compile; let $compile;
let $rootScope; let $rootScope;
let $timeout; let $timeout;
@ -85,7 +83,5 @@ describe('Browser: OSDropzone', function() {
$rootScope.$digest(); $rootScope.$digest();
$timeout.flush(); $timeout.flush();
}); });
}); });
}); });

View File

@ -22,13 +22,11 @@ const electron = require('electron');
require('angular-mocks'); require('angular-mocks');
describe('Browser: OSOpenExternal', function () { describe('Browser: OSOpenExternal', function () {
beforeEach(angular.mock.module( beforeEach(angular.mock.module(
require('../../../lib/gui/os/open-external/open-external') require('../../../lib/gui/os/open-external/open-external')
)); ));
describe('osOpenExternal', function () { describe('osOpenExternal', function () {
let $compile; let $compile;
let $rootScope; let $rootScope;
@ -60,7 +58,5 @@ describe('Browser: OSOpenExternal', function() {
m.chai.expect(shellExternalStub).to.not.have.been.called; m.chai.expect(shellExternalStub).to.not.have.been.called;
shellExternalStub.restore(); shellExternalStub.restore();
}); });
}); });
}); });

View File

@ -20,11 +20,8 @@ const m = require('mochainon');
const windowProgress = require('../../../lib/gui/os/window-progress'); const windowProgress = require('../../../lib/gui/os/window-progress');
describe('Browser: WindowProgress', function () { describe('Browser: WindowProgress', function () {
describe('windowProgress', function () { describe('windowProgress', function () {
describe('given a stubbed current window', function () { describe('given a stubbed current window', function () {
beforeEach(function () { beforeEach(function () {
this.setProgressBarSpy = m.sinon.spy(); this.setProgressBarSpy = m.sinon.spy();
@ -34,7 +31,6 @@ describe('Browser: WindowProgress', function() {
}); });
describe('.set()', function () { describe('.set()', function () {
it('should translate 0-100 percentages to 0-1 ranges', function () { it('should translate 0-100 percentages to 0-1 ranges', function () {
windowProgress.set(85); windowProgress.set(85);
m.chai.expect(this.setProgressBarSpy).to.have.been.calledWith(0.85); m.chai.expect(this.setProgressBarSpy).to.have.been.calledWith(0.85);
@ -61,20 +57,14 @@ describe('Browser: WindowProgress', function() {
windowProgress.set(-1); windowProgress.set(-1);
}).to.throw('Invalid percentage: -1'); }).to.throw('Invalid percentage: -1');
}); });
}); });
describe('.clear()', function () { describe('.clear()', function () {
it('should set -1', function () { it('should set -1', function () {
windowProgress.clear(); windowProgress.clear();
m.chai.expect(this.setProgressBarSpy).to.have.been.calledWith(-1); m.chai.expect(this.setProgressBarSpy).to.have.been.calledWith(-1);
}); });
}); });
}); });
}); });
}); });

View File

@ -1,3 +1,19 @@
/*
* Copyright 2017 resin.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict'; 'use strict';
const m = require('mochainon'); const m = require('mochainon');
@ -12,13 +28,11 @@ const selectionState = require('../../../lib/shared/models/selection-state');
require('angular-mocks'); require('angular-mocks');
describe('Browser: MainPage', function () { describe('Browser: MainPage', function () {
beforeEach(angular.mock.module( beforeEach(angular.mock.module(
require('../../../lib/gui/pages/main/main') require('../../../lib/gui/pages/main/main')
)); ));
describe('MainController', function () { describe('MainController', function () {
let $controller; let $controller;
beforeEach(angular.mock.inject(function (_$controller_) { beforeEach(angular.mock.inject(function (_$controller_) {
@ -26,7 +40,6 @@ describe('Browser: MainPage', function() {
})); }));
describe('.shouldDriveStepBeDisabled()', function () { describe('.shouldDriveStepBeDisabled()', function () {
it('should return true if there is no drive', function () { it('should return true if there is no drive', function () {
const controller = $controller('MainController', { const controller = $controller('MainController', {
$scope: {} $scope: {}
@ -56,11 +69,9 @@ describe('Browser: MainPage', function() {
m.chai.expect(controller.shouldDriveStepBeDisabled()).to.be.false; m.chai.expect(controller.shouldDriveStepBeDisabled()).to.be.false;
}); });
}); });
describe('.shouldFlashStepBeDisabled()', function () { describe('.shouldFlashStepBeDisabled()', function () {
it('should return true if there is no selected drive nor image', function () { it('should return true if there is no selected drive nor image', function () {
const controller = $controller('MainController', { const controller = $controller('MainController', {
$scope: {} $scope: {}
@ -145,13 +156,10 @@ describe('Browser: MainPage', function() {
m.chai.expect(controller.shouldFlashStepBeDisabled()).to.be.false; m.chai.expect(controller.shouldFlashStepBeDisabled()).to.be.false;
}); });
}); });
}); });
describe('ImageSelectionController', function () { describe('ImageSelectionController', function () {
let $controller; let $controller;
beforeEach(angular.mock.inject(function (_$controller_) { beforeEach(angular.mock.inject(function (_$controller_) {
@ -169,7 +177,6 @@ describe('Browser: MainPage', function() {
}); });
describe('.getImageBasename()', function () { describe('.getImageBasename()', function () {
it('should return the basename of the selected image', function () { it('should return the basename of the selected image', function () {
const controller = $controller('ImageSelectionController', { const controller = $controller('ImageSelectionController', {
$scope: {} $scope: {}
@ -199,13 +206,10 @@ describe('Browser: MainPage', function() {
selectionState.removeImage(); selectionState.removeImage();
m.chai.expect(controller.getImageBasename()).to.equal(''); m.chai.expect(controller.getImageBasename()).to.equal('');
}); });
}); });
}); });
describe('FlashController', function () { describe('FlashController', function () {
let $controller; let $controller;
beforeEach(angular.mock.inject(function (_$controller_) { beforeEach(angular.mock.inject(function (_$controller_) {
@ -213,7 +217,6 @@ describe('Browser: MainPage', function() {
})); }));
describe('.getProgressButtonLabel()', function () { describe('.getProgressButtonLabel()', function () {
it('should return "Flash!" given a clean state', function () { it('should return "Flash!" given a clean state', function () {
const controller = $controller('FlashController', { const controller = $controller('FlashController', {
$scope: {} $scope: {}
@ -224,7 +227,6 @@ describe('Browser: MainPage', function() {
}); });
describe('given there is a flash in progress', function () { describe('given there is a flash in progress', function () {
beforeEach(function () { beforeEach(function () {
flashState.setFlashingFlag(); flashState.setFlashingFlag();
}); });
@ -449,11 +451,7 @@ describe('Browser: MainPage', function() {
m.chai.expect(controller.getProgressButtonLabel()).to.equal('Finishing...'); m.chai.expect(controller.getProgressButtonLabel()).to.equal('Finishing...');
}); });
}); });
}); });
}); });
}); });
}); });

View File

@ -1,3 +1,19 @@
/*
* Copyright 2017 resin.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict'; 'use strict';
const m = require('mochainon'); const m = require('mochainon');
@ -6,13 +22,11 @@ require('angular-mocks');
const units = require('../../../lib/shared/units'); const units = require('../../../lib/shared/units');
describe('Browser: ByteSize', function () { describe('Browser: ByteSize', function () {
beforeEach(angular.mock.module( beforeEach(angular.mock.module(
require('../../../lib/gui/utils/byte-size/byte-size') require('../../../lib/gui/utils/byte-size/byte-size')
)); ));
describe('ClosestUnitFilter', function () { describe('ClosestUnitFilter', function () {
let closestUnitFilter; let closestUnitFilter;
beforeEach(angular.mock.inject(function (_closestUnitFilter_) { beforeEach(angular.mock.inject(function (_closestUnitFilter_) {
@ -22,6 +36,5 @@ describe('Browser: ByteSize', function() {
it('should expose lib/shared/units.js bytesToGigabytes()', function () { it('should expose lib/shared/units.js bytesToGigabytes()', function () {
m.chai.expect(closestUnitFilter).to.equal(units.bytesToClosestUnit); m.chai.expect(closestUnitFilter).to.equal(units.bytesToClosestUnit);
}); });
}); });
}); });

View File

@ -22,7 +22,6 @@ const packageJSON = require('../../../package.json');
require('angular-mocks'); require('angular-mocks');
describe('Browser: ManifestBind', function () { describe('Browser: ManifestBind', function () {
beforeEach(angular.mock.module( beforeEach(angular.mock.module(
require('../../../lib/gui/utils/manifest-bind/manifest-bind') require('../../../lib/gui/utils/manifest-bind/manifest-bind')
)); ));
@ -36,7 +35,6 @@ describe('Browser: ManifestBind', function() {
})); }));
describe('ManifestBindService', function () { describe('ManifestBindService', function () {
let ManifestBindService; let ManifestBindService;
beforeEach(angular.mock.inject(function (_ManifestBindService_) { beforeEach(angular.mock.inject(function (_ManifestBindService_) {
@ -57,11 +55,9 @@ describe('Browser: ManifestBind', function() {
const value = ManifestBindService.get('foo.bar'); const value = ManifestBindService.get('foo.bar');
m.chai.expect(value).to.be.undefined; m.chai.expect(value).to.be.undefined;
}); });
}); });
describe('manifestBind', function () { describe('manifestBind', function () {
it('should bind to top level properties', function () { it('should bind to top level properties', function () {
const element = $compile('<span manifest-bind="version"></span>')($rootScope); const element = $compile('<span manifest-bind="version"></span>')($rootScope);
$rootScope.$digest(); $rootScope.$digest();
@ -79,7 +75,5 @@ describe('Browser: ManifestBind', function() {
$compile('<span manifest-bind="foo.bar"></span>')($rootScope); $compile('<span manifest-bind="foo.bar"></span>')($rootScope);
}).to.throw('ManifestBind: Unknown property `foo.bar`'); }).to.throw('ManifestBind: Unknown property `foo.bar`');
}); });
}); });
}); });

View File

@ -24,13 +24,10 @@ const tester = require('../tester');
const ZIP_PATH = path.join(__dirname, '..', 'data', 'zip'); const ZIP_PATH = path.join(__dirname, '..', 'data', 'zip');
describe('ImageStream: Archive hooks: ZIP', function () { describe('ImageStream: Archive hooks: ZIP', function () {
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT); this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
describe('.getEntries()', function () { describe('.getEntries()', function () {
describe('given an empty zip', function () { describe('given an empty zip', function () {
beforeEach(function () { beforeEach(function () {
this.zip = path.join(ZIP_PATH, 'zip-directory-empty.zip'); this.zip = path.join(ZIP_PATH, 'zip-directory-empty.zip');
}); });
@ -40,11 +37,9 @@ describe('ImageStream: Archive hooks: ZIP', function() {
m.chai.expect(entries).to.deep.equal([]); m.chai.expect(entries).to.deep.equal([]);
}); });
}); });
}); });
describe('given a zip with multiple files in it', function () { describe('given a zip with multiple files in it', function () {
beforeEach(function () { beforeEach(function () {
this.zip = path.join(ZIP_PATH, 'zip-directory-multiple-images.zip'); this.zip = path.join(ZIP_PATH, 'zip-directory-multiple-images.zip');
}); });
@ -63,11 +58,9 @@ describe('ImageStream: Archive hooks: ZIP', function() {
]); ]);
}); });
}); });
}); });
describe('given a zip with nested files in it', function () { describe('given a zip with nested files in it', function () {
beforeEach(function () { beforeEach(function () {
this.zip = path.join(ZIP_PATH, 'zip-directory-nested-misc.zip'); this.zip = path.join(ZIP_PATH, 'zip-directory-nested-misc.zip');
}); });
@ -86,13 +79,10 @@ describe('ImageStream: Archive hooks: ZIP', function() {
]); ]);
}); });
}); });
}); });
}); });
describe('.extractFile()', function () { describe('.extractFile()', function () {
beforeEach(function () { beforeEach(function () {
this.zip = path.join(ZIP_PATH, 'zip-directory-nested-misc.zip'); this.zip = path.join(ZIP_PATH, 'zip-directory-nested-misc.zip');
}); });
@ -134,7 +124,5 @@ describe('ImageStream: Archive hooks: ZIP', function() {
m.chai.expect(error.message).to.equal(`Invalid entry: ${fileName}`); m.chai.expect(error.message).to.equal(`Invalid entry: ${fileName}`);
}); });
}); });
}); });
}); });

View File

@ -26,11 +26,9 @@ const imageStream = require('../../lib/image-stream/index');
const tester = require('./tester'); const tester = require('./tester');
describe('ImageStream: BZ2', function () { describe('ImageStream: BZ2', function () {
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT); this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
describe('compression method', function () { describe('compression method', function () {
describe('bzip2 level 9', function () { describe('bzip2 level 9', function () {
tester.extractFromFilePath( tester.extractFromFilePath(
path.join(BZ2_PATH, 'etcher-test-9.img.bz2'), path.join(BZ2_PATH, 'etcher-test-9.img.bz2'),
@ -42,11 +40,9 @@ describe('ImageStream: BZ2', function() {
path.join(BZ2_PATH, 'etcher-test.img.bz2'), path.join(BZ2_PATH, 'etcher-test.img.bz2'),
path.join(IMAGES_PATH, 'etcher-test.img')); path.join(IMAGES_PATH, 'etcher-test.img'));
}); });
}); });
describe('.getImageMetadata()', function () { describe('.getImageMetadata()', function () {
it('should return the correct metadata', function () { it('should return the correct metadata', function () {
const image = path.join(BZ2_PATH, 'etcher-test.img.bz2'); const image = path.join(BZ2_PATH, 'etcher-test.img.bz2');
const expectedSize = fs.statSync(image).size; const expectedSize = fs.statSync(image).size;
@ -69,7 +65,5 @@ describe('ImageStream: BZ2', function() {
}); });
}); });
}); });
}); });
}); });

View File

@ -24,11 +24,8 @@ const errors = require('../../lib/shared/errors');
const imageStream = require('../../lib/image-stream/index'); const imageStream = require('../../lib/image-stream/index');
describe('ImageStream: Directory', function () { describe('ImageStream: Directory', function () {
describe('.getFromFilePath()', function () { describe('.getFromFilePath()', function () {
describe('given a directory', function () { describe('given a directory', function () {
it('should be rejected with an error', function (done) { it('should be rejected with an error', function (done) {
imageStream.getFromFilePath(IMAGES_PATH).catch((error) => { imageStream.getFromFilePath(IMAGES_PATH).catch((error) => {
m.chai.expect(error).to.be.an.instanceof(Error); m.chai.expect(error).to.be.an.instanceof(Error);
@ -38,13 +35,10 @@ describe('ImageStream: Directory', function() {
done(); done();
}); });
}); });
}); });
}); });
describe('.getImageMetadata()', function () { describe('.getImageMetadata()', function () {
it('should be rejected with an error', function (done) { it('should be rejected with an error', function (done) {
imageStream.getImageMetadata(IMAGES_PATH).catch((error) => { imageStream.getImageMetadata(IMAGES_PATH).catch((error) => {
m.chai.expect(error).to.be.an.instanceof(Error); m.chai.expect(error).to.be.an.instanceof(Error);
@ -54,7 +48,5 @@ describe('ImageStream: Directory', function() {
done(); done();
}); });
}); });
}); });
}); });

View File

@ -26,11 +26,9 @@ const imageStream = require('../../lib/image-stream/index');
const tester = require('./tester'); const tester = require('./tester');
describe('ImageStream: DMG', function () { describe('ImageStream: DMG', function () {
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT); this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
describe('compression method', function () { describe('compression method', function () {
describe('NONE', function () { describe('NONE', function () {
tester.extractFromFilePath( tester.extractFromFilePath(
path.join(DMG_PATH, 'etcher-test-raw.dmg'), path.join(DMG_PATH, 'etcher-test-raw.dmg'),
@ -61,23 +59,18 @@ describe('ImageStream: DMG', function() {
path.join(DMG_PATH, 'etcher-test-lzfse.dmg'), path.join(DMG_PATH, 'etcher-test-lzfse.dmg'),
path.join(IMAGES_PATH, 'etcher-test.img')); path.join(IMAGES_PATH, 'etcher-test.img'));
}); });
}); });
context('zlib compressed', function () { context('zlib compressed', function () {
describe('.getFromFilePath()', function () { describe('.getFromFilePath()', function () {
describe('given an dmg image', function () { describe('given an dmg image', function () {
tester.extractFromFilePath( tester.extractFromFilePath(
path.join(DMG_PATH, 'etcher-test-zlib.dmg'), path.join(DMG_PATH, 'etcher-test-zlib.dmg'),
path.join(IMAGES_PATH, 'etcher-test.img')); path.join(IMAGES_PATH, 'etcher-test.img'));
}); });
}); });
describe('.getImageMetadata()', function () { describe('.getImageMetadata()', function () {
it('should return the correct metadata', function () { it('should return the correct metadata', function () {
const image = path.join(DMG_PATH, 'etcher-test-zlib.dmg'); const image = path.join(DMG_PATH, 'etcher-test-zlib.dmg');
const uncompressedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size; const uncompressedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size;
@ -99,25 +92,19 @@ describe('ImageStream: DMG', function() {
}); });
}); });
}); });
}); });
}); });
context('uncompressed', function () { context('uncompressed', function () {
describe('.getFromFilePath()', function () { describe('.getFromFilePath()', function () {
describe('given an dmg image', function () { describe('given an dmg image', function () {
tester.extractFromFilePath( tester.extractFromFilePath(
path.join(DMG_PATH, 'etcher-test-raw.dmg'), path.join(DMG_PATH, 'etcher-test-raw.dmg'),
path.join(IMAGES_PATH, 'etcher-test.img')); path.join(IMAGES_PATH, 'etcher-test.img'));
}); });
}); });
describe('.getImageMetadata()', function () { describe('.getImageMetadata()', function () {
it('should return the correct metadata', function () { it('should return the correct metadata', function () {
const image = path.join(DMG_PATH, 'etcher-test-raw.dmg'); const image = path.join(DMG_PATH, 'etcher-test-raw.dmg');
const uncompressedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size; const uncompressedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size;
@ -139,19 +126,14 @@ describe('ImageStream: DMG', function() {
}); });
}); });
}); });
}); });
}); });
context('invalid', function () { context('invalid', function () {
describe('given an invalid dmg file', function () { describe('given an invalid dmg file', function () {
tester.expectError( tester.expectError(
path.join(DATA_PATH, 'unrecognized', 'invalid.dmg'), path.join(DATA_PATH, 'unrecognized', 'invalid.dmg'),
'Invalid image', 'Invalid footer'); 'Invalid image', 'Invalid footer');
}); });
}); });
}); });

View File

@ -26,21 +26,17 @@ const imageStream = require('../../lib/image-stream/index');
const tester = require('./tester'); const tester = require('./tester');
describe('ImageStream: GZ', function () { describe('ImageStream: GZ', function () {
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT); this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
describe('.getFromFilePath()', function () { describe('.getFromFilePath()', function () {
describe('given a gz image', function () { describe('given a gz image', function () {
tester.extractFromFilePath( tester.extractFromFilePath(
path.join(GZ_PATH, 'etcher-test.img.gz'), path.join(GZ_PATH, 'etcher-test.img.gz'),
path.join(IMAGES_PATH, 'etcher-test.img')); path.join(IMAGES_PATH, 'etcher-test.img'));
}); });
}); });
describe('.getImageMetadata()', function () { describe('.getImageMetadata()', function () {
it('should return the correct metadata', function () { it('should return the correct metadata', function () {
const image = path.join(GZ_PATH, 'etcher-test.img.gz'); const image = path.join(GZ_PATH, 'etcher-test.img.gz');
const uncompressedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size; const uncompressedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size;
@ -64,7 +60,5 @@ describe('ImageStream: GZ', function() {
}); });
}); });
}); });
}); });
}); });

View File

@ -25,23 +25,18 @@ const imageStream = require('../../lib/image-stream/index');
const tester = require('./tester'); const tester = require('./tester');
describe('ImageStream: IMG', function () { describe('ImageStream: IMG', function () {
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT); this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
describe('.getFromFilePath()', function () { describe('.getFromFilePath()', function () {
describe('given an img image', function () { describe('given an img image', function () {
tester.extractFromFilePath( tester.extractFromFilePath(
path.join(IMAGES_PATH, 'etcher-test.img'), path.join(IMAGES_PATH, 'etcher-test.img'),
path.join(IMAGES_PATH, 'etcher-test.img')); path.join(IMAGES_PATH, 'etcher-test.img'));
}); });
}); });
describe('.getImageMetadata()', function () { describe('.getImageMetadata()', function () {
context('Master Boot Record', function () { context('Master Boot Record', function () {
it('should return the correct metadata', function () { it('should return the correct metadata', function () {
const image = path.join(IMAGES_PATH, 'etcher-test.img'); const image = path.join(IMAGES_PATH, 'etcher-test.img');
const expectedSize = fs.statSync(image).size; const expectedSize = fs.statSync(image).size;
@ -63,11 +58,9 @@ describe('ImageStream: IMG', function() {
}); });
}); });
}); });
}); });
context('GUID Partition Table', function () { context('GUID Partition Table', function () {
it('should return the correct metadata', function () { it('should return the correct metadata', function () {
const image = path.join(IMAGES_PATH, 'etcher-gpt-test.img.gz'); const image = path.join(IMAGES_PATH, 'etcher-gpt-test.img.gz');
const uncompressedSize = 134217728; const uncompressedSize = 134217728;
@ -91,9 +84,6 @@ describe('ImageStream: IMG', function() {
}); });
}); });
}); });
}); });
}); });
}); });

View File

@ -21,9 +21,7 @@ const _ = require('lodash');
const imageStream = require('../../lib/image-stream/index'); const imageStream = require('../../lib/image-stream/index');
describe('ImageStream', function () { describe('ImageStream', function () {
describe('.supportedFileTypes', function () { describe('.supportedFileTypes', function () {
it('should be an array', function () { it('should be an array', function () {
m.chai.expect(_.isArray(imageStream.supportedFileTypes)).to.be.true; m.chai.expect(_.isArray(imageStream.supportedFileTypes)).to.be.true;
}); });
@ -49,7 +47,5 @@ describe('ImageStream', function() {
return _.first(fileType.extension) !== '.'; return _.first(fileType.extension) !== '.';
}))).to.be.true; }))).to.be.true;
}); });
}); });
}); });

View File

@ -25,21 +25,17 @@ const imageStream = require('../../lib/image-stream/index');
const tester = require('./tester'); const tester = require('./tester');
describe('ImageStream: ISO', function () { describe('ImageStream: ISO', function () {
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT); this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
describe('.getFromFilePath()', function () { describe('.getFromFilePath()', function () {
describe('given an iso image', function () { describe('given an iso image', function () {
tester.extractFromFilePath( tester.extractFromFilePath(
path.join(IMAGES_PATH, 'etcher-test.iso'), path.join(IMAGES_PATH, 'etcher-test.iso'),
path.join(IMAGES_PATH, 'etcher-test.iso')); path.join(IMAGES_PATH, 'etcher-test.iso'));
}); });
}); });
describe('.getImageMetadata()', function () { describe('.getImageMetadata()', function () {
it('should return the correct metadata', function () { it('should return the correct metadata', function () {
const image = path.join(IMAGES_PATH, 'etcher-test.iso'); const image = path.join(IMAGES_PATH, 'etcher-test.iso');
const expectedSize = fs.statSync(image).size; const expectedSize = fs.statSync(image).size;
@ -61,7 +57,5 @@ describe('ImageStream: ISO', function() {
}); });
}); });
}); });
}); });
}); });

View File

@ -35,17 +35,14 @@ const testMetadataProperty = (archivePath, propertyName, expectedValue) => {
}; };
describe('ImageStream: Metadata ZIP', function () { describe('ImageStream: Metadata ZIP', function () {
this.timeout(10000); this.timeout(10000);
describe('given an archive with an invalid `manifest.json`', function () { describe('given an archive with an invalid `manifest.json`', function () {
tester.expectError( tester.expectError(
path.join(ZIP_PATH, 'etcher-test-invalid-manifest.zip'), path.join(ZIP_PATH, 'etcher-test-invalid-manifest.zip'),
'Invalid archive manifest.json'); 'Invalid archive manifest.json');
describe('.getImageMetadata()', function () { describe('.getImageMetadata()', function () {
it('should be rejected with an error', function () { it('should be rejected with an error', function () {
const image = path.join(ZIP_PATH, 'etcher-test-invalid-manifest.zip'); const image = path.join(ZIP_PATH, 'etcher-test-invalid-manifest.zip');
@ -54,13 +51,10 @@ describe('ImageStream: Metadata ZIP', function() {
m.chai.expect(error.message).to.equal('Invalid archive manifest.json'); m.chai.expect(error.message).to.equal('Invalid archive manifest.json');
}); });
}); });
}); });
}); });
describe('given an archive with a `manifest.json`', function () { describe('given an archive with a `manifest.json`', function () {
const archive = path.join(ZIP_PATH, 'etcher-test-with-manifest.zip'); const archive = path.join(ZIP_PATH, 'etcher-test-with-manifest.zip');
tester.extractFromFilePath( tester.extractFromFilePath(
@ -104,11 +98,9 @@ describe('ImageStream: Metadata ZIP', function() {
it('should read the manifest recommendedDriveSize property', function () { it('should read the manifest recommendedDriveSize property', function () {
return testMetadataProperty(archive, 'recommendedDriveSize', 4294967296); return testMetadataProperty(archive, 'recommendedDriveSize', 4294967296);
}); });
}); });
describe('given an archive with a `logo.svg`', function () { describe('given an archive with a `logo.svg`', function () {
const archive = path.join(ZIP_PATH, 'etcher-test-with-logo.zip'); const archive = path.join(ZIP_PATH, 'etcher-test-with-logo.zip');
const logo = [ const logo = [
@ -121,11 +113,9 @@ describe('ImageStream: Metadata ZIP', function() {
it('should read the logo contents', function () { it('should read the logo contents', function () {
return testMetadataProperty(archive, 'logo', logo); return testMetadataProperty(archive, 'logo', logo);
}); });
}); });
describe('given an archive with a bmap file', function () { describe('given an archive with a bmap file', function () {
const archive = path.join(ZIP_PATH, 'etcher-test-with-bmap.zip'); const archive = path.join(ZIP_PATH, 'etcher-test-with-bmap.zip');
const bmap = [ const bmap = [
@ -146,11 +136,9 @@ describe('ImageStream: Metadata ZIP', function() {
it('should read the bmap contents', function () { it('should read the bmap contents', function () {
return testMetadataProperty(archive, 'bmap', bmap); return testMetadataProperty(archive, 'bmap', bmap);
}); });
}); });
describe('given an archive with instructions', function () { describe('given an archive with instructions', function () {
const archive = path.join(ZIP_PATH, 'etcher-test-with-instructions.zip'); const archive = path.join(ZIP_PATH, 'etcher-test-with-instructions.zip');
const instructions = [ const instructions = [
@ -163,7 +151,5 @@ describe('ImageStream: Metadata ZIP', function() {
it('should read the instruction contents', function () { it('should read the instruction contents', function () {
return testMetadataProperty(archive, 'instructions', instructions); return testMetadataProperty(archive, 'instructions', instructions);
}); });
}); });
}); });

View File

@ -22,9 +22,7 @@ const DATA_PATH = path.join(__dirname, 'data');
const mime = require('../../lib/image-stream/mime'); const mime = require('../../lib/image-stream/mime');
describe('ImageStream: MIME', function () { describe('ImageStream: MIME', function () {
describe('.getMimeTypeFromFileName()', function () { describe('.getMimeTypeFromFileName()', function () {
it('should resolve application/x-bzip2 for a bz2 archive', function () { it('should resolve application/x-bzip2 for a bz2 archive', function () {
const file = path.join(DATA_PATH, 'bz2', 'etcher-test.img.bz2'); const file = path.join(DATA_PATH, 'bz2', 'etcher-test.img.bz2');
return mime.getMimeTypeFromFileName(file).then((type) => { return mime.getMimeTypeFromFileName(file).then((type) => {
@ -101,7 +99,5 @@ describe('ImageStream: MIME', function() {
m.chai.expect(type).to.equal('application/x-xz'); m.chai.expect(type).to.equal('application/x-xz');
}); });
}); });
}); });
}); });

View File

@ -21,20 +21,14 @@ const StreamReadable = require('stream').Readable;
const utils = require('../../lib/image-stream/utils'); const utils = require('../../lib/image-stream/utils');
describe('ImageStream: Utils', function () { describe('ImageStream: Utils', function () {
describe('.extractStream()', function () { describe('.extractStream()', function () {
describe('given a stream that emits data', function () { describe('given a stream that emits data', function () {
beforeEach(function () { beforeEach(function () {
this.stream = new StreamReadable(); this.stream = new StreamReadable();
/* eslint-disable no-underscore-dangle */ /* eslint-disable no-underscore-dangle */
this.stream._read = function () { this.stream._read = function () {
/* eslint-enable no-underscore-dangle */ /* eslint-enable no-underscore-dangle */
this.push(Buffer.from('Hello', 'utf8')); this.push(Buffer.from('Hello', 'utf8'));
this.push(Buffer.from(' ', 'utf8')); this.push(Buffer.from(' ', 'utf8'));
this.push(Buffer.from('World', 'utf8')); this.push(Buffer.from('World', 'utf8'));
@ -47,20 +41,15 @@ describe('ImageStream: Utils', function() {
m.chai.expect(data.toString()).to.equal('Hello World'); m.chai.expect(data.toString()).to.equal('Hello World');
}); });
}); });
}); });
describe('given a stream that throws an error', function () { describe('given a stream that throws an error', function () {
beforeEach(function () { beforeEach(function () {
this.stream = new StreamReadable(); this.stream = new StreamReadable();
/* eslint-disable no-underscore-dangle */ /* eslint-disable no-underscore-dangle */
this.stream._read = function () { this.stream._read = function () {
/* eslint-enable no-underscore-dangle */ /* eslint-enable no-underscore-dangle */
this.emit('error', new Error('stream error')); this.emit('error', new Error('stream error'));
}; };
}); });
@ -71,9 +60,6 @@ describe('ImageStream: Utils', function() {
m.chai.expect(error.message).to.equal('stream error'); m.chai.expect(error.message).to.equal('stream error');
}); });
}); });
}); });
}); });
}); });

View File

@ -26,21 +26,17 @@ const imageStream = require('../../lib/image-stream/index');
const tester = require('./tester'); const tester = require('./tester');
describe('ImageStream: XZ', function () { describe('ImageStream: XZ', function () {
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT); this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
describe('.getFromFilePath()', function () { describe('.getFromFilePath()', function () {
describe('given a xz image', function () { describe('given a xz image', function () {
tester.extractFromFilePath( tester.extractFromFilePath(
path.join(XZ_PATH, 'etcher-test.img.xz'), path.join(XZ_PATH, 'etcher-test.img.xz'),
path.join(IMAGES_PATH, 'etcher-test.img')); path.join(IMAGES_PATH, 'etcher-test.img'));
}); });
}); });
describe('.getImageMetadata()', function () { describe('.getImageMetadata()', function () {
it('should return the correct metadata', function () { it('should return the correct metadata', function () {
const image = path.join(XZ_PATH, 'etcher-test.img.xz'); const image = path.join(XZ_PATH, 'etcher-test.img.xz');
const compressedSize = fs.statSync(image).size; const compressedSize = fs.statSync(image).size;
@ -64,7 +60,5 @@ describe('ImageStream: XZ', function() {
}); });
}); });
}); });
}); });
}); });

View File

@ -26,11 +26,9 @@ const imageStream = require('../../lib/image-stream/index');
const tester = require('./tester'); const tester = require('./tester');
describe('ImageStream: ZIP', function () { describe('ImageStream: ZIP', function () {
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT); this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
describe('.getFromFilePath()', function () { describe('.getFromFilePath()', function () {
describe('given an empty zip directory', function () { describe('given an empty zip directory', function () {
tester.expectError( tester.expectError(
path.join(ZIP_PATH, 'zip-directory-empty.zip'), path.join(ZIP_PATH, 'zip-directory-empty.zip'),
@ -66,11 +64,9 @@ describe('ImageStream: ZIP', function() {
path.join(ZIP_PATH, 'zip-directory-etcher-test-and-misc.zip'), path.join(ZIP_PATH, 'zip-directory-etcher-test-and-misc.zip'),
path.join(IMAGES_PATH, 'etcher-test.img')); path.join(IMAGES_PATH, 'etcher-test.img'));
}); });
}); });
describe('compression method', function () { describe('compression method', function () {
context('DEFLATE', function () { context('DEFLATE', function () {
tester.extractFromFilePath( tester.extractFromFilePath(
path.join(ZIP_PATH, 'zip-deflate.zip'), path.join(ZIP_PATH, 'zip-deflate.zip'),
@ -102,11 +98,9 @@ describe('ImageStream: ZIP', function() {
path.join(ZIP_PATH, 'zip-lzma.zip'), path.join(ZIP_PATH, 'zip-lzma.zip'),
path.join(IMAGES_PATH, 'etcher-test.img')); path.join(IMAGES_PATH, 'etcher-test.img'));
}); });
}); });
describe('.getImageMetadata()', function () { describe('.getImageMetadata()', function () {
it('should return the correct metadata', function () { it('should return the correct metadata', function () {
const image = path.join(ZIP_PATH, 'zip-directory-etcher-test-only.zip'); const image = path.join(ZIP_PATH, 'zip-directory-etcher-test-only.zip');
const expectedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size; const expectedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size;
@ -129,7 +123,5 @@ describe('ImageStream: ZIP', function() {
}); });
}); });
}); });
}); });
}); });

View File

@ -1,3 +1,19 @@
/*
* Copyright 2017 resin.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict'; 'use strict';
const m = require('mochainon'); const m = require('mochainon');
@ -6,9 +22,7 @@ const path = require('path');
const constraints = require('../../lib/shared/drive-constraints'); const constraints = require('../../lib/shared/drive-constraints');
describe('Shared: DriveConstraints', function () { describe('Shared: DriveConstraints', function () {
describe('.isDriveLocked()', function () { describe('.isDriveLocked()', function () {
it('should return true if the drive is protected', function () { it('should return true if the drive is protected', function () {
const result = constraints.isDriveLocked({ const result = constraints.isDriveLocked({
device: '/dev/disk2', device: '/dev/disk2',
@ -46,11 +60,9 @@ describe('Shared: DriveConstraints', function() {
m.chai.expect(result).to.be.false; m.chai.expect(result).to.be.false;
}); });
}); });
describe('.isSystemDrive()', function () { describe('.isSystemDrive()', function () {
it('should return true if the drive is a system drive', function () { it('should return true if the drive is a system drive', function () {
const result = constraints.isSystemDrive({ const result = constraints.isSystemDrive({
device: '/dev/disk2', device: '/dev/disk2',
@ -91,11 +103,9 @@ describe('Shared: DriveConstraints', function() {
m.chai.expect(result).to.be.false; m.chai.expect(result).to.be.false;
}); });
}); });
describe('.isSourceDrive()', function () { describe('.isSourceDrive()', function () {
it('should return false if no image', function () { it('should return false if no image', function () {
const result = constraints.isSourceDrive({ const result = constraints.isSourceDrive({
device: '/dev/disk2', device: '/dev/disk2',
@ -131,7 +141,6 @@ describe('Shared: DriveConstraints', function() {
}); });
describe('given Windows paths', function () { describe('given Windows paths', function () {
beforeEach(function () { beforeEach(function () {
this.separator = path.sep; this.separator = path.sep;
path.sep = '\\'; path.sep = '\\';
@ -205,11 +214,9 @@ describe('Shared: DriveConstraints', function() {
m.chai.expect(result).to.be.false; m.chai.expect(result).to.be.false;
}); });
}); });
describe('given UNIX paths', function () { describe('given UNIX paths', function () {
beforeEach(function () { beforeEach(function () {
this.separator = path.sep; this.separator = path.sep;
path.sep = '/'; path.sep = '/';
@ -297,13 +304,10 @@ describe('Shared: DriveConstraints', function() {
m.chai.expect(result).to.be.false; m.chai.expect(result).to.be.false;
}); });
}); });
}); });
describe('.isDriveLargeEnough()', function () { describe('.isDriveLargeEnough()', function () {
beforeEach(function () { beforeEach(function () {
this.drive = { this.drive = {
device: '/dev/disk1', device: '/dev/disk1',
@ -314,9 +318,7 @@ describe('Shared: DriveConstraints', function() {
}); });
describe('given the final image size estimation flag is false', function () { describe('given the final image size estimation flag is false', function () {
describe('given the original size is less than the drive size', function () { describe('given the original size is less than the drive size', function () {
beforeEach(function () { beforeEach(function () {
this.image = { this.image = {
path: path.join(__dirname, 'rpi.img'), path: path.join(__dirname, 'rpi.img'),
@ -343,11 +345,9 @@ describe('Shared: DriveConstraints', function() {
this.image.size.final.value = this.drive.size + 1; this.image.size.final.value = this.drive.size + 1;
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false; m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false;
}); });
}); });
describe('given the original size is equal to the drive size', function () { describe('given the original size is equal to the drive size', function () {
beforeEach(function () { beforeEach(function () {
this.image = { this.image = {
path: path.join(__dirname, 'rpi.img'), path: path.join(__dirname, 'rpi.img'),
@ -374,11 +374,9 @@ describe('Shared: DriveConstraints', function() {
this.image.size.final.value = this.drive.size + 1; this.image.size.final.value = this.drive.size + 1;
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false; m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false;
}); });
}); });
describe('given the original size is greater than the drive size', function () { describe('given the original size is greater than the drive size', function () {
beforeEach(function () { beforeEach(function () {
this.image = { this.image = {
path: path.join(__dirname, 'rpi.img'), path: path.join(__dirname, 'rpi.img'),
@ -405,15 +403,11 @@ describe('Shared: DriveConstraints', function() {
this.image.size.final.value = this.drive.size + 1; this.image.size.final.value = this.drive.size + 1;
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false; m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false;
}); });
}); });
}); });
describe('given the final image size estimation flag is true', function () { describe('given the final image size estimation flag is true', function () {
describe('given the original size is less than the drive size', function () { describe('given the original size is less than the drive size', function () {
beforeEach(function () { beforeEach(function () {
this.image = { this.image = {
path: path.join(__dirname, 'rpi.img'), path: path.join(__dirname, 'rpi.img'),
@ -440,11 +434,9 @@ describe('Shared: DriveConstraints', function() {
this.image.size.final.value = this.drive.size + 1; this.image.size.final.value = this.drive.size + 1;
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true; m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true;
}); });
}); });
describe('given the original size is equal to the drive size', function () { describe('given the original size is equal to the drive size', function () {
beforeEach(function () { beforeEach(function () {
this.image = { this.image = {
path: path.join(__dirname, 'rpi.img'), path: path.join(__dirname, 'rpi.img'),
@ -471,11 +463,9 @@ describe('Shared: DriveConstraints', function() {
this.image.size.final.value = this.drive.size + 1; this.image.size.final.value = this.drive.size + 1;
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true; m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true;
}); });
}); });
describe('given the original size is greater than the drive size', function () { describe('given the original size is greater than the drive size', function () {
beforeEach(function () { beforeEach(function () {
this.image = { this.image = {
path: path.join(__dirname, 'rpi.img'), path: path.join(__dirname, 'rpi.img'),
@ -502,9 +492,7 @@ describe('Shared: DriveConstraints', function() {
this.image.size.final.value = this.drive.size + 1; this.image.size.final.value = this.drive.size + 1;
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false; m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false;
}); });
}); });
}); });
it('should return false if the drive is undefined', function () { it('should return false if the drive is undefined', function () {
@ -537,11 +525,9 @@ describe('Shared: DriveConstraints', function() {
const result = constraints.isDriveLargeEnough(undefined, undefined); const result = constraints.isDriveLargeEnough(undefined, undefined);
m.chai.expect(result).to.be.true; m.chai.expect(result).to.be.true;
}); });
}); });
describe('.isDriveSizeRecommended()', function () { describe('.isDriveSizeRecommended()', function () {
it('should return true if the drive size is greater than the recommended size ', function () { it('should return true if the drive size is greater than the recommended size ', function () {
const result = constraints.isDriveSizeRecommended({ const result = constraints.isDriveSizeRecommended({
device: '/dev/disk1', device: '/dev/disk1',
@ -626,11 +612,9 @@ describe('Shared: DriveConstraints', function() {
const result = constraints.isDriveSizeRecommended(undefined, undefined); const result = constraints.isDriveSizeRecommended(undefined, undefined);
m.chai.expect(result).to.be.true; m.chai.expect(result).to.be.true;
}); });
}); });
describe('.isDriveValid()', function () { describe('.isDriveValid()', function () {
beforeEach(function () { beforeEach(function () {
if (process.platform === 'win32') { if (process.platform === 'win32') {
this.mountpoint = 'E:\\foo'; this.mountpoint = 'E:\\foo';
@ -651,7 +635,6 @@ describe('Shared: DriveConstraints', function() {
}); });
describe('given the drive is locked', function () { describe('given the drive is locked', function () {
beforeEach(function () { beforeEach(function () {
this.drive.protected = true; this.drive.protected = true;
}); });
@ -707,11 +690,9 @@ describe('Shared: DriveConstraints', function() {
} }
})).to.be.false; })).to.be.false;
}); });
}); });
describe('given the drive is not locked', function () { describe('given the drive is not locked', function () {
beforeEach(function () { beforeEach(function () {
this.drive.protected = false; this.drive.protected = false;
}); });
@ -767,13 +748,10 @@ describe('Shared: DriveConstraints', function() {
} }
})).to.be.true; })).to.be.true;
}); });
}); });
}); });
describe('.getDriveImageCompatibilityStatuses', function () { describe('.getDriveImageCompatibilityStatuses', function () {
beforeEach(function () { beforeEach(function () {
if (process.platform === 'win32') { if (process.platform === 'win32') {
this.mountpoint = 'E:'; this.mountpoint = 'E:';
@ -808,7 +786,6 @@ describe('Shared: DriveConstraints', function() {
}); });
const expectStatusTypesAndMessagesToBe = (resultList, expectedTuples) => { const expectStatusTypesAndMessagesToBe = (resultList, expectedTuples) => {
// Sort so that order doesn't matter // Sort so that order doesn't matter
const expectedTuplesSorted = _.sortBy(_.map(expectedTuples, (tuple) => { const expectedTuplesSorted = _.sortBy(_.map(expectedTuples, (tuple) => {
return { return {
@ -822,7 +799,6 @@ describe('Shared: DriveConstraints', function() {
}; };
describe('given there are no errors or warnings', () => { describe('given there are no errors or warnings', () => {
it('should return an empty list', function () { it('should return an empty list', function () {
const result = constraints.getDriveImageCompatibilityStatuses(this.drive, { const result = constraints.getDriveImageCompatibilityStatuses(this.drive, {
path: '/mnt/disk2/rpi.img', path: '/mnt/disk2/rpi.img',
@ -831,11 +807,9 @@ describe('Shared: DriveConstraints', function() {
m.chai.expect(result).to.deep.equal([]); m.chai.expect(result).to.deep.equal([]);
}); });
}); });
describe('given the drive contains the image', () => { describe('given the drive contains the image', () => {
it('should return the contains-image error', function () { it('should return the contains-image error', function () {
this.image.path = path.join(this.mountpoint, 'rpi.img'); this.image.path = path.join(this.mountpoint, 'rpi.img');
@ -844,11 +818,9 @@ describe('Shared: DriveConstraints', function() {
expectStatusTypesAndMessagesToBe(result, expectedTuples); expectStatusTypesAndMessagesToBe(result, expectedTuples);
}); });
}); });
describe('given the drive is a system drive', () => { describe('given the drive is a system drive', () => {
it('should return the system drive warning', function () { it('should return the system drive warning', function () {
this.drive.system = true; this.drive.system = true;
@ -857,11 +829,9 @@ describe('Shared: DriveConstraints', function() {
expectStatusTypesAndMessagesToBe(result, expectedTuples); expectStatusTypesAndMessagesToBe(result, expectedTuples);
}); });
}); });
describe('given the drive is too small', () => { describe('given the drive is too small', () => {
it('should return the too small error', function () { it('should return the too small error', function () {
this.image.size.final.value = this.drive.size + 1; this.image.size.final.value = this.drive.size + 1;
@ -870,11 +840,9 @@ describe('Shared: DriveConstraints', function() {
expectStatusTypesAndMessagesToBe(result, expectedTuples); expectStatusTypesAndMessagesToBe(result, expectedTuples);
}); });
}); });
describe('given the drive is locked', () => { describe('given the drive is locked', () => {
it('should return the locked drive error', function () { it('should return the locked drive error', function () {
this.drive.protected = true; this.drive.protected = true;
@ -883,11 +851,9 @@ describe('Shared: DriveConstraints', function() {
expectStatusTypesAndMessagesToBe(result, expectedTuples); expectStatusTypesAndMessagesToBe(result, expectedTuples);
}); });
}); });
describe('given the drive is smaller than the recommended size', () => { describe('given the drive is smaller than the recommended size', () => {
it('should return the smaller than recommended size warning', function () { it('should return the smaller than recommended size warning', function () {
this.image.recommendedDriveSize = this.drive.size + 1; this.image.recommendedDriveSize = this.drive.size + 1;
@ -896,31 +862,25 @@ describe('Shared: DriveConstraints', function() {
expectStatusTypesAndMessagesToBe(result, expectedTuples); expectStatusTypesAndMessagesToBe(result, expectedTuples);
}); });
}); });
describe('given the image is null', () => { describe('given the image is null', () => {
it('should return an empty list', function () { it('should return an empty list', function () {
const result = constraints.getDriveImageCompatibilityStatuses(this.drive, null); const result = constraints.getDriveImageCompatibilityStatuses(this.drive, null);
m.chai.expect(result).to.deep.equal([]); m.chai.expect(result).to.deep.equal([]);
}); });
}); });
describe('given the drive is null', () => { describe('given the drive is null', () => {
it('should return an empty list', function () { it('should return an empty list', function () {
const result = constraints.getDriveImageCompatibilityStatuses(null, this.image); const result = constraints.getDriveImageCompatibilityStatuses(null, this.image);
m.chai.expect(result).to.deep.equal([]); m.chai.expect(result).to.deep.equal([]);
}); });
}); });
describe('given a locked drive and image is null', () => { describe('given a locked drive and image is null', () => {
it('should return locked drive error', function () { it('should return locked drive error', function () {
this.drive.protected = true; this.drive.protected = true;
@ -929,11 +889,9 @@ describe('Shared: DriveConstraints', function() {
expectStatusTypesAndMessagesToBe(result, expectedTuples); expectStatusTypesAndMessagesToBe(result, expectedTuples);
}); });
}); });
describe('given a system drive and image is null', () => { describe('given a system drive and image is null', () => {
it('should return system drive warning', function () { it('should return system drive warning', function () {
this.drive.system = true; this.drive.system = true;
@ -942,11 +900,9 @@ describe('Shared: DriveConstraints', function() {
expectStatusTypesAndMessagesToBe(result, expectedTuples); expectStatusTypesAndMessagesToBe(result, expectedTuples);
}); });
}); });
describe('given the drive contains the image and the drive is locked', () => { describe('given the drive contains the image and the drive is locked', () => {
it('should return the contains-image drive error by precedence', function () { it('should return the contains-image drive error by precedence', function () {
this.drive.protected = true; this.drive.protected = true;
this.image.path = path.join(this.mountpoint, 'rpi.img'); this.image.path = path.join(this.mountpoint, 'rpi.img');
@ -956,11 +912,9 @@ describe('Shared: DriveConstraints', function() {
expectStatusTypesAndMessagesToBe(result, expectedTuples); expectStatusTypesAndMessagesToBe(result, expectedTuples);
}); });
}); });
describe('given a locked and too small drive', () => { describe('given a locked and too small drive', () => {
it('should return the locked error by precedence', function () { it('should return the locked error by precedence', function () {
this.drive.protected = true; this.drive.protected = true;
@ -969,11 +923,9 @@ describe('Shared: DriveConstraints', function() {
expectStatusTypesAndMessagesToBe(result, expectedTuples); expectStatusTypesAndMessagesToBe(result, expectedTuples);
}); });
}); });
describe('given a too small and system drive', () => { describe('given a too small and system drive', () => {
it('should return the too small drive error by precedence', function () { it('should return the too small drive error by precedence', function () {
this.image.size.final.value = this.drive.size + 1; this.image.size.final.value = this.drive.size + 1;
this.drive.system = true; this.drive.system = true;
@ -983,11 +935,9 @@ describe('Shared: DriveConstraints', function() {
expectStatusTypesAndMessagesToBe(result, expectedTuples); expectStatusTypesAndMessagesToBe(result, expectedTuples);
}); });
}); });
describe('given a system drive and not recommended drive size', () => { describe('given a system drive and not recommended drive size', () => {
it('should return both warnings', function () { it('should return both warnings', function () {
this.drive.system = true; this.drive.system = true;
this.image.recommendedDriveSize = this.drive.size + 1; this.image.recommendedDriveSize = this.drive.size + 1;
@ -997,8 +947,6 @@ describe('Shared: DriveConstraints', function() {
expectStatusTypesAndMessagesToBe(result, expectedTuples); expectStatusTypesAndMessagesToBe(result, expectedTuples);
}); });
}); });
}); });
}); });

View File

@ -21,9 +21,7 @@ const _ = require('lodash');
const errors = require('../../lib/shared/errors'); const errors = require('../../lib/shared/errors');
describe('Shared: Errors', function () { describe('Shared: Errors', function () {
describe('.HUMAN_FRIENDLY', function () { describe('.HUMAN_FRIENDLY', function () {
it('should be a plain object', function () { it('should be a plain object', function () {
m.chai.expect(_.isPlainObject(errors.HUMAN_FRIENDLY)).to.be.true; m.chai.expect(_.isPlainObject(errors.HUMAN_FRIENDLY)).to.be.true;
}); });
@ -33,11 +31,9 @@ describe('Shared: Errors', function() {
return _.isFunction(error.title) && _.isFunction(error.description); return _.isFunction(error.title) && _.isFunction(error.description);
}))).to.be.true; }))).to.be.true;
}); });
}); });
describe('.getTitle()', function () { describe('.getTitle()', function () {
it('should accept a string', function () { it('should accept a string', function () {
const error = 'This is an error'; const error = 'This is an error';
m.chai.expect(errors.getTitle(error)).to.equal('This is an error'); m.chai.expect(errors.getTitle(error)).to.equal('This is an error');
@ -201,11 +197,9 @@ describe('Shared: Errors', function() {
error.code = 'ENOMEM'; error.code = 'ENOMEM';
m.chai.expect(errors.getTitle(error)).to.equal('Your system ran out of memory'); m.chai.expect(errors.getTitle(error)).to.equal('Your system ran out of memory');
}); });
}); });
describe('.getDescription()', function () { describe('.getDescription()', function () {
it('should return an empty string if the error is a string', function () { it('should return an empty string if the error is a string', function () {
const error = 'My error'; const error = 'My error';
m.chai.expect(errors.getDescription(error)).to.equal(''); m.chai.expect(errors.getDescription(error)).to.equal('');
@ -332,7 +326,6 @@ describe('Shared: Errors', function() {
}); });
describe('given userFriendlyDescriptionsOnly is false', function () { describe('given userFriendlyDescriptionsOnly is false', function () {
it('should return the stack for a basic error', function () { it('should return the stack for a basic error', function () {
const error = new Error('Foo'); const error = new Error('Foo');
m.chai.expect(errors.getDescription(error, { m.chai.expect(errors.getDescription(error, {
@ -355,11 +348,9 @@ describe('Shared: Errors', function() {
userFriendlyDescriptionsOnly: false userFriendlyDescriptionsOnly: false
})).to.equal(error.stack); })).to.equal(error.stack);
}); });
}); });
describe('given userFriendlyDescriptionsOnly is true', function () { describe('given userFriendlyDescriptionsOnly is true', function () {
it('should return an empty string for a basic error', function () { it('should return an empty string for a basic error', function () {
const error = new Error('Foo'); const error = new Error('Foo');
m.chai.expect(errors.getDescription(error, { m.chai.expect(errors.getDescription(error, {
@ -382,13 +373,10 @@ describe('Shared: Errors', function() {
userFriendlyDescriptionsOnly: true userFriendlyDescriptionsOnly: true
})).to.equal(''); })).to.equal('');
}); });
}); });
}); });
describe('.createError()', function () { describe('.createError()', function () {
it('should not be a user error', function () { it('should not be a user error', function () {
const error = errors.createError({ const error = errors.createError({
title: 'Foo', title: 'Foo',
@ -513,11 +501,9 @@ describe('Shared: Errors', function() {
}); });
}).to.throw('Invalid error title: '); }).to.throw('Invalid error title: ');
}); });
}); });
describe('.createUserError()', function () { describe('.createUserError()', function () {
it('should be a user error', function () { it('should be a user error', function () {
const error = errors.createUserError({ const error = errors.createUserError({
title: 'Foo', title: 'Foo',
@ -602,23 +588,19 @@ describe('Shared: Errors', function() {
}); });
}).to.throw('Invalid error title: '); }).to.throw('Invalid error title: ');
}); });
}); });
describe('.isUserError()', function () { describe('.isUserError()', function () {
_.each([ _.each([
0, 0,
'', '',
false false
], (value) => { ], (value) => {
it(`should return true if report equals ${value}`, function () { it(`should return true if report equals ${value}`, function () {
const error = new Error('foo bar'); const error = new Error('foo bar');
error.report = value; error.report = value;
m.chai.expect(errors.isUserError(error)).to.be.true; m.chai.expect(errors.isUserError(error)).to.be.true;
}); });
}); });
_.each([ _.each([
@ -629,19 +611,15 @@ describe('Shared: Errors', function() {
3, 3,
'foo' 'foo'
], (value) => { ], (value) => {
it(`should return false if report equals ${value}`, function () { it(`should return false if report equals ${value}`, function () {
const error = new Error('foo bar'); const error = new Error('foo bar');
error.report = value; error.report = value;
m.chai.expect(errors.isUserError(error)).to.be.false; m.chai.expect(errors.isUserError(error)).to.be.false;
}); });
}); });
}); });
describe('.toJSON()', function () { describe('.toJSON()', function () {
it('should convert a simple error', function () { it('should convert a simple error', function () {
const error = new Error('My error'); const error = new Error('My error');
m.chai.expect(errors.toJSON(error)).to.deep.equal({ m.chai.expect(errors.toJSON(error)).to.deep.equal({
@ -717,11 +695,9 @@ describe('Shared: Errors', function() {
report: undefined report: undefined
}); });
}); });
}); });
describe('.fromJSON()', function () { describe('.fromJSON()', function () {
it('should return an Error object', function () { it('should return an Error object', function () {
const error = new Error('My error'); const error = new Error('My error');
const result = errors.fromJSON(errors.toJSON(error)); const result = errors.fromJSON(errors.toJSON(error));
@ -774,7 +750,5 @@ describe('Shared: Errors', function() {
m.chai.expect(result.stack).to.equal(error.stack); m.chai.expect(result.stack).to.equal(error.stack);
m.chai.expect(result.report).to.equal(error.report); m.chai.expect(result.report).to.equal(error.report);
}); });
}); });
}); });

View File

@ -21,9 +21,7 @@ const _ = require('lodash');
const fileExtensions = require('../../lib/shared/file-extensions'); const fileExtensions = require('../../lib/shared/file-extensions');
describe('Shared: fileExtensions', function () { describe('Shared: fileExtensions', function () {
describe('.getFileExtensions()', function () { describe('.getFileExtensions()', function () {
_.forEach([ _.forEach([
// No extension // No extension
@ -99,11 +97,9 @@ describe('Shared: fileExtensions', function() {
'gz' 'gz'
]); ]);
}); });
}); });
describe('.getLastFileExtension()', function () { describe('.getLastFileExtension()', function () {
it('should return undefined if the file path has no extension', function () { it('should return undefined if the file path has no extension', function () {
m.chai.expect(fileExtensions.getLastFileExtension('foo')).to.be.undefined; m.chai.expect(fileExtensions.getLastFileExtension('foo')).to.be.undefined;
}); });
@ -119,11 +115,9 @@ describe('Shared: fileExtensions', function() {
it('should return the last extension if there are three extensions', function () { it('should return the last extension if there are three extensions', function () {
m.chai.expect(fileExtensions.getLastFileExtension('foo.bar.img.gz')).to.equal('gz'); m.chai.expect(fileExtensions.getLastFileExtension('foo.bar.img.gz')).to.equal('gz');
}); });
}); });
describe('.getPenultimateFileExtension()', function () { describe('.getPenultimateFileExtension()', function () {
it('should return undefined in the file path has no extension', function () { it('should return undefined in the file path has no extension', function () {
m.chai.expect(fileExtensions.getPenultimateFileExtension('foo')).to.be.undefined; m.chai.expect(fileExtensions.getPenultimateFileExtension('foo')).to.be.undefined;
}); });
@ -139,7 +133,5 @@ describe('Shared: fileExtensions', function() {
it('should return the penultimate extension if there are three extensions', function () { it('should return the penultimate extension if there are three extensions', function () {
m.chai.expect(fileExtensions.getPenultimateFileExtension('foo.bar.img.gz')).to.equal('img'); m.chai.expect(fileExtensions.getPenultimateFileExtension('foo.bar.img.gz')).to.equal('img');
}); });
}); });
}); });

View File

@ -21,7 +21,6 @@ const _ = require('lodash');
const messages = require('../../lib/shared/messages'); const messages = require('../../lib/shared/messages');
describe('Shared: Messages', function () { describe('Shared: Messages', function () {
it('should contain object properties', function () { it('should contain object properties', function () {
m.chai.expect(_.every(_.map(messages, _.isPlainObject))).to.be.true; m.chai.expect(_.every(_.map(messages, _.isPlainObject))).to.be.true;
}); });
@ -31,5 +30,4 @@ describe('Shared: Messages', function() {
m.chai.expect(_.every(_.map(category, _.isFunction))).to.be.true; m.chai.expect(_.every(_.map(category, _.isFunction))).to.be.true;
}); });
}); });
}); });

View File

@ -22,15 +22,12 @@ const availableDrives = require('../../../lib/shared/models/available-drives');
const selectionState = require('../../../lib/shared/models/selection-state'); const selectionState = require('../../../lib/shared/models/selection-state');
describe('Model: availableDrives', function () { describe('Model: availableDrives', function () {
describe('availableDrives', function () { describe('availableDrives', function () {
it('should have no drives by default', function () { it('should have no drives by default', function () {
m.chai.expect(availableDrives.getDrives()).to.deep.equal([]); m.chai.expect(availableDrives.getDrives()).to.deep.equal([]);
}); });
describe('.setDrives()', function () { describe('.setDrives()', function () {
it('should throw if no drives', function () { it('should throw if no drives', function () {
m.chai.expect(function () { m.chai.expect(function () {
availableDrives.setDrives(); availableDrives.setDrives();
@ -52,21 +49,16 @@ describe('Model: availableDrives', function() {
]); ]);
}).to.throw('Invalid drives: 123,123,123'); }).to.throw('Invalid drives: 123,123,123');
}); });
}); });
describe('given no drives', function () { describe('given no drives', function () {
describe('.hasAvailableDrives()', function () { describe('.hasAvailableDrives()', function () {
it('should return false', function () { it('should return false', function () {
m.chai.expect(availableDrives.hasAvailableDrives()).to.be.false; m.chai.expect(availableDrives.hasAvailableDrives()).to.be.false;
}); });
}); });
describe('.setDrives()', function () { describe('.setDrives()', function () {
it('should be able to set drives', function () { it('should be able to set drives', function () {
const drives = [ const drives = [
{ {
@ -83,7 +75,6 @@ describe('Model: availableDrives', function() {
}); });
describe('given no selected image and no selected drive', function () { describe('given no selected image and no selected drive', function () {
beforeEach(function () { beforeEach(function () {
selectionState.removeDrive(); selectionState.removeDrive();
selectionState.removeImage(); selectionState.removeImage();
@ -106,11 +97,9 @@ describe('Model: availableDrives', function() {
m.chai.expect(selectionState.hasDrive()).to.be.true; m.chai.expect(selectionState.hasDrive()).to.be.true;
m.chai.expect(selectionState.getDrive().device).to.equal('/dev/sdb'); m.chai.expect(selectionState.getDrive().device).to.equal('/dev/sdb');
}); });
}); });
describe('given a selected image and no selected drive', function () { describe('given a selected image and no selected drive', function () {
beforeEach(function () { beforeEach(function () {
if (process.platform === 'win32') { if (process.platform === 'win32') {
this.imagePath = 'E:\\bar\\foo.img'; this.imagePath = 'E:\\bar\\foo.img';
@ -274,15 +263,11 @@ describe('Model: availableDrives', function() {
m.chai.expect(selectionState.hasDrive()).to.be.false; m.chai.expect(selectionState.hasDrive()).to.be.false;
}); });
}); });
}); });
}); });
describe('given drives', function () { describe('given drives', function () {
beforeEach(function () { beforeEach(function () {
this.drives = [ this.drives = [
{ {
@ -307,7 +292,6 @@ describe('Model: availableDrives', function() {
}); });
describe('given one of the drives was selected', function () { describe('given one of the drives was selected', function () {
beforeEach(function () { beforeEach(function () {
availableDrives.setDrives([ availableDrives.setDrives([
{ {
@ -354,20 +338,16 @@ describe('Model: availableDrives', function() {
m.chai.expect(selectionState.hasDrive()).to.be.false; m.chai.expect(selectionState.hasDrive()).to.be.false;
}); });
}); });
describe('.hasAvailableDrives()', function () { describe('.hasAvailableDrives()', function () {
it('should return true', function () { it('should return true', function () {
const hasDrives = availableDrives.hasAvailableDrives(); const hasDrives = availableDrives.hasAvailableDrives();
m.chai.expect(hasDrives).to.be.true; m.chai.expect(hasDrives).to.be.true;
}); });
}); });
describe('.setDrives()', function () { describe('.setDrives()', function () {
it('should keep the same drives if equal', function () { it('should keep the same drives if equal', function () {
availableDrives.setDrives(this.drives); availableDrives.setDrives(this.drives);
m.chai.expect(availableDrives.getDrives()).to.deep.equal(this.drives); m.chai.expect(availableDrives.getDrives()).to.deep.equal(this.drives);
@ -383,10 +363,7 @@ describe('Model: availableDrives', function() {
availableDrives.setDrives(this.drives); availableDrives.setDrives(this.drives);
m.chai.expect(availableDrives.getDrives()).to.deep.equal(this.drives); m.chai.expect(availableDrives.getDrives()).to.deep.equal(this.drives);
}); });
});
}); });
});
}); });
}); });

View File

@ -20,15 +20,12 @@ const m = require('mochainon');
const flashState = require('../../../lib/shared/models/flash-state'); const flashState = require('../../../lib/shared/models/flash-state');
describe('Model: flashState', function () { describe('Model: flashState', function () {
beforeEach(function () { beforeEach(function () {
flashState.resetState(); flashState.resetState();
}); });
describe('flashState', function () { describe('flashState', function () {
describe('.resetState()', function () { describe('.resetState()', function () {
it('should be able to reset the progress state', function () { it('should be able to reset the progress state', function () {
flashState.setFlashingFlag(); flashState.setFlashingFlag();
flashState.setProgressState({ flashState.setProgressState({
@ -67,11 +64,9 @@ describe('Model: flashState', function() {
flashState.resetState(); flashState.resetState();
m.chai.expect(flashState.getFlashUuid()).to.be.undefined; m.chai.expect(flashState.getFlashUuid()).to.be.undefined;
}); });
}); });
describe('.isFlashing()', function () { describe('.isFlashing()', function () {
it('should return false by default', function () { it('should return false by default', function () {
m.chai.expect(flashState.isFlashing()).to.be.false; m.chai.expect(flashState.isFlashing()).to.be.false;
}); });
@ -80,11 +75,9 @@ describe('Model: flashState', function() {
flashState.setFlashingFlag(); flashState.setFlashingFlag();
m.chai.expect(flashState.isFlashing()).to.be.true; m.chai.expect(flashState.isFlashing()).to.be.true;
}); });
}); });
describe('.setProgressState()', function () { describe('.setProgressState()', function () {
it('should not allow setting the state if flashing is false', function () { it('should not allow setting the state if flashing is false', function () {
flashState.unsetFlashingFlag({ flashState.unsetFlashingFlag({
cancelled: false, cancelled: false,
@ -240,11 +233,9 @@ describe('Model: flashState', function() {
}); });
}).to.not.throw('Missing state speed'); }).to.not.throw('Missing state speed');
}); });
}); });
describe('.getFlashResults()', function () { describe('.getFlashResults()', function () {
it('should get the flash results', function () { it('should get the flash results', function () {
flashState.setFlashingFlag(); flashState.setFlashingFlag();
@ -257,11 +248,9 @@ describe('Model: flashState', function() {
const results = flashState.getFlashResults(); const results = flashState.getFlashResults();
m.chai.expect(results).to.deep.equal(expectedResults); m.chai.expect(results).to.deep.equal(expectedResults);
}); });
}); });
describe('.getFlashState()', function () { describe('.getFlashState()', function () {
it('should initially return an empty state', function () { it('should initially return an empty state', function () {
flashState.resetState(); flashState.resetState();
const currentFlashState = flashState.getFlashState(); const currentFlashState = flashState.getFlashState();
@ -284,11 +273,9 @@ describe('Model: flashState', function() {
const currentFlashState = flashState.getFlashState(); const currentFlashState = flashState.getFlashState();
m.chai.expect(currentFlashState).to.deep.equal(state); m.chai.expect(currentFlashState).to.deep.equal(state);
}); });
}); });
describe('.unsetFlashingFlag()', function () { describe('.unsetFlashingFlag()', function () {
it('should throw if no flashing results', function () { it('should throw if no flashing results', function () {
m.chai.expect(function () { m.chai.expect(function () {
flashState.unsetFlashingFlag(); flashState.unsetFlashingFlag();
@ -405,11 +392,9 @@ describe('Model: flashState', function() {
const uuidAfterUnset = flashState.getFlashUuid(); const uuidAfterUnset = flashState.getFlashUuid();
m.chai.expect(uuidBeforeUnset).to.equal(uuidAfterUnset); m.chai.expect(uuidBeforeUnset).to.equal(uuidAfterUnset);
}); });
}); });
describe('.setFlashingFlag()', function () { describe('.setFlashingFlag()', function () {
it('should be able to set flashing to true', function () { it('should be able to set flashing to true', function () {
flashState.setFlashingFlag(); flashState.setFlashingFlag();
m.chai.expect(flashState.isFlashing()).to.be.true; m.chai.expect(flashState.isFlashing()).to.be.true;
@ -427,11 +412,9 @@ describe('Model: flashState', function() {
flashState.setFlashingFlag(); flashState.setFlashingFlag();
m.chai.expect(flashState.getFlashResults()).to.deep.equal({}); m.chai.expect(flashState.getFlashResults()).to.deep.equal({});
}); });
}); });
describe('.wasLastFlashCancelled()', function () { describe('.wasLastFlashCancelled()', function () {
it('should return false given a pristine state', function () { it('should return false given a pristine state', function () {
flashState.resetState(); flashState.resetState();
m.chai.expect(flashState.wasLastFlashCancelled()).to.be.false; m.chai.expect(flashState.wasLastFlashCancelled()).to.be.false;
@ -453,11 +436,9 @@ describe('Model: flashState', function() {
m.chai.expect(flashState.wasLastFlashCancelled()).to.be.true; m.chai.expect(flashState.wasLastFlashCancelled()).to.be.true;
}); });
}); });
describe('.getLastFlashSourceChecksum()', function () { describe('.getLastFlashSourceChecksum()', function () {
it('should return undefined given a pristine state', function () { it('should return undefined given a pristine state', function () {
flashState.resetState(); flashState.resetState();
m.chai.expect(flashState.getLastFlashSourceChecksum()).to.be.undefined; m.chai.expect(flashState.getLastFlashSourceChecksum()).to.be.undefined;
@ -479,11 +460,9 @@ describe('Model: flashState', function() {
m.chai.expect(flashState.getLastFlashSourceChecksum()).to.be.undefined; m.chai.expect(flashState.getLastFlashSourceChecksum()).to.be.undefined;
}); });
}); });
describe('.getLastFlashErrorCode()', function () { describe('.getLastFlashErrorCode()', function () {
it('should return undefined given a pristine state', function () { it('should return undefined given a pristine state', function () {
flashState.resetState(); flashState.resetState();
m.chai.expect(flashState.getLastFlashErrorCode()).to.be.undefined; m.chai.expect(flashState.getLastFlashErrorCode()).to.be.undefined;
@ -507,11 +486,9 @@ describe('Model: flashState', function() {
m.chai.expect(flashState.getLastFlashErrorCode()).to.be.undefined; m.chai.expect(flashState.getLastFlashErrorCode()).to.be.undefined;
}); });
}); });
describe('.getFlashUuid()', function () { describe('.getFlashUuid()', function () {
const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/; const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
it('should be initially undefined', function () { it('should be initially undefined', function () {
@ -553,9 +530,6 @@ describe('Model: flashState', function() {
m.chai.expect(uuid2).to.not.equal(uuid3); m.chai.expect(uuid2).to.not.equal(uuid3);
m.chai.expect(uuid3).to.not.equal(uuid1); m.chai.expect(uuid3).to.not.equal(uuid1);
}); });
}); });
}); });
}); });

View File

@ -23,9 +23,7 @@ const availableDrives = require('../../../lib/shared/models/available-drives');
const selectionState = require('../../../lib/shared/models/selection-state'); const selectionState = require('../../../lib/shared/models/selection-state');
describe('Model: selectionState', function () { describe('Model: selectionState', function () {
describe('given a clean state', function () { describe('given a clean state', function () {
beforeEach(function () { beforeEach(function () {
selectionState.clear(); selectionState.clear();
}); });
@ -76,11 +74,9 @@ describe('Model: selectionState', function() {
const hasImage = selectionState.hasImage(); const hasImage = selectionState.hasImage();
m.chai.expect(hasImage).to.be.false; m.chai.expect(hasImage).to.be.false;
}); });
}); });
describe('given a drive', function () { describe('given a drive', function () {
beforeEach(function () { beforeEach(function () {
availableDrives.setDrives([ availableDrives.setDrives([
{ {
@ -101,7 +97,6 @@ describe('Model: selectionState', function() {
}); });
describe('.getDrive()', function () { describe('.getDrive()', function () {
it('should return the drive', function () { it('should return the drive', function () {
const drive = selectionState.getDrive(); const drive = selectionState.getDrive();
m.chai.expect(drive).to.deep.equal({ m.chai.expect(drive).to.deep.equal({
@ -111,20 +106,16 @@ describe('Model: selectionState', function() {
protected: false protected: false
}); });
}); });
}); });
describe('.hasDrive()', function () { describe('.hasDrive()', function () {
it('should return true', function () { it('should return true', function () {
const hasDrive = selectionState.hasDrive(); const hasDrive = selectionState.hasDrive();
m.chai.expect(hasDrive).to.be.true; m.chai.expect(hasDrive).to.be.true;
}); });
}); });
describe('.setDrive()', function () { describe('.setDrive()', function () {
it('should override the drive', function () { it('should override the drive', function () {
selectionState.setDrive('/dev/disk5'); selectionState.setDrive('/dev/disk5');
const drive = selectionState.getDrive(); const drive = selectionState.getDrive();
@ -135,25 +126,19 @@ describe('Model: selectionState', function() {
protected: false protected: false
}); });
}); });
}); });
describe('.removeDrive()', function () { describe('.removeDrive()', function () {
it('should clear the drive', function () { it('should clear the drive', function () {
selectionState.removeDrive(); selectionState.removeDrive();
const drive = selectionState.getDrive(); const drive = selectionState.getDrive();
m.chai.expect(drive).to.be.undefined; m.chai.expect(drive).to.be.undefined;
}); });
}); });
}); });
describe('given no drive', function () { describe('given no drive', function () {
describe('.setDrive()', function () { describe('.setDrive()', function () {
it('should be able to set a drive', function () { it('should be able to set a drive', function () {
availableDrives.setDrives([ availableDrives.setDrives([
{ {
@ -209,13 +194,10 @@ describe('Model: selectionState', function() {
selectionState.setDrive(123); selectionState.setDrive(123);
}).to.throw('Invalid drive: 123'); }).to.throw('Invalid drive: 123');
}); });
}); });
}); });
describe('given an image', function () { describe('given an image', function () {
beforeEach(function () { beforeEach(function () {
this.image = { this.image = {
path: 'foo.img', path: 'foo.img',
@ -238,7 +220,6 @@ describe('Model: selectionState', function() {
}); });
describe('.setDrive()', function () { describe('.setDrive()', function () {
it('should throw if drive is not large enough', function () { it('should throw if drive is not large enough', function () {
availableDrives.setDrives([ availableDrives.setDrives([
{ {
@ -253,91 +234,71 @@ describe('Model: selectionState', function() {
selectionState.setDrive('/dev/disk2'); selectionState.setDrive('/dev/disk2');
}).to.throw('The drive is not large enough'); }).to.throw('The drive is not large enough');
}); });
}); });
describe('.getImage()', function () { describe('.getImage()', function () {
it('should return the image', function () { it('should return the image', function () {
m.chai.expect(selectionState.getImage()).to.deep.equal(this.image); m.chai.expect(selectionState.getImage()).to.deep.equal(this.image);
}); });
}); });
describe('.getImagePath()', function () { describe('.getImagePath()', function () {
it('should return the image path', function () { it('should return the image path', function () {
const imagePath = selectionState.getImagePath(); const imagePath = selectionState.getImagePath();
m.chai.expect(imagePath).to.equal('foo.img'); m.chai.expect(imagePath).to.equal('foo.img');
}); });
}); });
describe('.getImageSize()', function () { describe('.getImageSize()', function () {
it('should return the image size', function () { it('should return the image size', function () {
const imageSize = selectionState.getImageSize(); const imageSize = selectionState.getImageSize();
m.chai.expect(imageSize).to.equal(999999999); m.chai.expect(imageSize).to.equal(999999999);
}); });
}); });
describe('.getImageUrl()', function () { describe('.getImageUrl()', function () {
it('should return the image url', function () { it('should return the image url', function () {
const imageUrl = selectionState.getImageUrl(); const imageUrl = selectionState.getImageUrl();
m.chai.expect(imageUrl).to.equal('https://www.raspbian.org'); m.chai.expect(imageUrl).to.equal('https://www.raspbian.org');
}); });
}); });
describe('.getImageName()', function () { describe('.getImageName()', function () {
it('should return the image name', function () { it('should return the image name', function () {
const imageName = selectionState.getImageName(); const imageName = selectionState.getImageName();
m.chai.expect(imageName).to.equal('Raspbian'); m.chai.expect(imageName).to.equal('Raspbian');
}); });
}); });
describe('.getImageLogo()', function () { describe('.getImageLogo()', function () {
it('should return the image logo', function () { it('should return the image logo', function () {
const imageLogo = selectionState.getImageLogo(); const imageLogo = selectionState.getImageLogo();
m.chai.expect(imageLogo).to.equal('<svg><text fill="red">Raspbian</text></svg>'); m.chai.expect(imageLogo).to.equal('<svg><text fill="red">Raspbian</text></svg>');
}); });
}); });
describe('.getImageSupportUrl()', function () { describe('.getImageSupportUrl()', function () {
it('should return the image support url', function () { it('should return the image support url', function () {
const imageSupportUrl = selectionState.getImageSupportUrl(); const imageSupportUrl = selectionState.getImageSupportUrl();
m.chai.expect(imageSupportUrl).to.equal('https://www.raspbian.org/forums/'); m.chai.expect(imageSupportUrl).to.equal('https://www.raspbian.org/forums/');
}); });
}); });
describe('.getImageRecommendedDriveSize()', function () { describe('.getImageRecommendedDriveSize()', function () {
it('should return the image recommended drive size', function () { it('should return the image recommended drive size', function () {
const imageRecommendedDriveSize = selectionState.getImageRecommendedDriveSize(); const imageRecommendedDriveSize = selectionState.getImageRecommendedDriveSize();
m.chai.expect(imageRecommendedDriveSize).to.equal(1000000000); m.chai.expect(imageRecommendedDriveSize).to.equal(1000000000);
}); });
}); });
describe('.hasImage()', function () { describe('.hasImage()', function () {
it('should return true', function () { it('should return true', function () {
const hasImage = selectionState.hasImage(); const hasImage = selectionState.hasImage();
m.chai.expect(hasImage).to.be.true; m.chai.expect(hasImage).to.be.true;
}); });
}); });
describe('.setImage()', function () { describe('.setImage()', function () {
it('should override the image', function () { it('should override the image', function () {
selectionState.setImage({ selectionState.setImage({
path: 'bar.img', path: 'bar.img',
@ -356,11 +317,9 @@ describe('Model: selectionState', function() {
const imageSize = selectionState.getImageSize(); const imageSize = selectionState.getImageSize();
m.chai.expect(imageSize).to.equal(999999999); m.chai.expect(imageSize).to.equal(999999999);
}); });
}); });
describe('.removeImage()', function () { describe('.removeImage()', function () {
it('should clear the image', function () { it('should clear the image', function () {
selectionState.removeImage(); selectionState.removeImage();
@ -369,15 +328,11 @@ describe('Model: selectionState', function() {
const imageSize = selectionState.getImageSize(); const imageSize = selectionState.getImageSize();
m.chai.expect(imageSize).to.be.undefined; m.chai.expect(imageSize).to.be.undefined;
}); });
}); });
}); });
describe('given no image', function () { describe('given no image', function () {
describe('.setImage()', function () { describe('.setImage()', function () {
it('should be able to set an image', function () { it('should be able to set an image', function () {
selectionState.setImage({ selectionState.setImage({
path: 'foo.img', path: 'foo.img',
@ -859,13 +814,10 @@ describe('Model: selectionState', function() {
m.chai.expect(selectionState.hasDrive()).to.be.false; m.chai.expect(selectionState.hasDrive()).to.be.false;
selectionState.removeImage(); selectionState.removeImage();
}); });
}); });
}); });
describe('given a drive', function () { describe('given a drive', function () {
beforeEach(function () { beforeEach(function () {
availableDrives.setDrives([ availableDrives.setDrives([
{ {
@ -892,7 +844,6 @@ describe('Model: selectionState', function() {
}); });
describe('.clear()', function () { describe('.clear()', function () {
it('should clear all selections', function () { it('should clear all selections', function () {
m.chai.expect(selectionState.hasDrive()).to.be.true; m.chai.expect(selectionState.hasDrive()).to.be.true;
m.chai.expect(selectionState.hasImage()).to.be.true; m.chai.expect(selectionState.hasImage()).to.be.true;
@ -902,11 +853,9 @@ describe('Model: selectionState', function() {
m.chai.expect(selectionState.hasDrive()).to.be.false; m.chai.expect(selectionState.hasDrive()).to.be.false;
m.chai.expect(selectionState.hasImage()).to.be.false; m.chai.expect(selectionState.hasImage()).to.be.false;
}); });
}); });
describe('given the preserveImage option', function () { describe('given the preserveImage option', function () {
beforeEach(function () { beforeEach(function () {
selectionState.clear({ selectionState.clear({
preserveImage: true preserveImage: true
@ -937,15 +886,11 @@ describe('Model: selectionState', function() {
const hasImage = selectionState.hasImage(); const hasImage = selectionState.hasImage();
m.chai.expect(hasImage).to.be.true; m.chai.expect(hasImage).to.be.true;
}); });
}); });
}); });
describe('.isCurrentDrive()', function () { describe('.isCurrentDrive()', function () {
describe('given a selected drive', function () { describe('given a selected drive', function () {
beforeEach(function () { beforeEach(function () {
availableDrives.setDrives([ availableDrives.setDrives([
{ {
@ -973,11 +918,9 @@ describe('Model: selectionState', function() {
it('should return false if it is not the current drive', function () { it('should return false if it is not the current drive', function () {
m.chai.expect(selectionState.isCurrentDrive('/dev/sdc')).to.be.false; m.chai.expect(selectionState.isCurrentDrive('/dev/sdc')).to.be.false;
}); });
}); });
describe('given no selected drive', function () { describe('given no selected drive', function () {
beforeEach(function () { beforeEach(function () {
selectionState.removeDrive(); selectionState.removeDrive();
}); });
@ -989,15 +932,11 @@ describe('Model: selectionState', function() {
it('should return false for anything', function () { it('should return false for anything', function () {
m.chai.expect(selectionState.isCurrentDrive('/dev/sdb')).to.be.false; m.chai.expect(selectionState.isCurrentDrive('/dev/sdb')).to.be.false;
}); });
}); });
}); });
describe('.toggleSetDrive()', function () { describe('.toggleSetDrive()', function () {
describe('given a selected drive', function () { describe('given a selected drive', function () {
beforeEach(function () { beforeEach(function () {
this.drive = { this.drive = {
device: '/dev/sdb', device: '/dev/sdb',
@ -1041,11 +980,9 @@ describe('Model: selectionState', function() {
m.chai.expect(selectionState.getDrive()).to.deep.equal(drive); m.chai.expect(selectionState.getDrive()).to.deep.equal(drive);
m.chai.expect(selectionState.getDrive()).to.not.deep.equal(this.drive); m.chai.expect(selectionState.getDrive()).to.not.deep.equal(this.drive);
}); });
}); });
describe('given no selected drive', function () { describe('given no selected drive', function () {
beforeEach(function () { beforeEach(function () {
selectionState.removeDrive(); selectionState.removeDrive();
}); });
@ -1062,9 +999,6 @@ describe('Model: selectionState', function() {
selectionState.toggleSetDrive(drive.device); selectionState.toggleSetDrive(drive.device);
m.chai.expect(selectionState.getDrive()).to.deep.equal(drive); m.chai.expect(selectionState.getDrive()).to.deep.equal(drive);
}); });
}); });
}); });
}); });

View File

@ -21,11 +21,8 @@ const os = require('os');
const permissions = require('../../lib/shared/permissions'); const permissions = require('../../lib/shared/permissions');
describe('Shared: permissions', function () { describe('Shared: permissions', function () {
describe('.getEnvironmentCommandPrefix()', function () { describe('.getEnvironmentCommandPrefix()', function () {
describe('given windows', function () { describe('given windows', function () {
beforeEach(function () { beforeEach(function () {
this.osPlatformStub = m.sinon.stub(os, 'platform'); this.osPlatformStub = m.sinon.stub(os, 'platform');
this.osPlatformStub.returns('win32'); this.osPlatformStub.returns('win32');
@ -104,11 +101,9 @@ describe('Shared: permissions', function() {
'call' 'call'
]); ]);
}); });
}); });
describe('given linux', function () { describe('given linux', function () {
beforeEach(function () { beforeEach(function () {
this.osPlatformStub = m.sinon.stub(os, 'platform'); this.osPlatformStub = m.sinon.stub(os, 'platform');
this.osPlatformStub.returns('linux'); this.osPlatformStub.returns('linux');
@ -171,11 +166,9 @@ describe('Shared: permissions', function() {
'BAZ=-1' 'BAZ=-1'
]); ]);
}); });
}); });
describe('given darwin', function () { describe('given darwin', function () {
beforeEach(function () { beforeEach(function () {
this.osPlatformStub = m.sinon.stub(os, 'platform'); this.osPlatformStub = m.sinon.stub(os, 'platform');
this.osPlatformStub.returns('darwin'); this.osPlatformStub.returns('darwin');
@ -238,9 +231,6 @@ describe('Shared: permissions', function() {
'BAZ=-1' 'BAZ=-1'
]); ]);
}); });
}); });
}); });
}); });

View File

@ -21,9 +21,7 @@ const _ = require('lodash');
const release = require('../../lib/shared/release'); const release = require('../../lib/shared/release');
describe('Shared: Release', function () { describe('Shared: Release', function () {
describe('.RELEASE_TYPE', function () { describe('.RELEASE_TYPE', function () {
it('should be a plain object', function () { it('should be a plain object', function () {
m.chai.expect(_.isPlainObject(release.RELEASE_TYPE)).to.be.true; m.chai.expect(_.isPlainObject(release.RELEASE_TYPE)).to.be.true;
}); });
@ -33,18 +31,15 @@ describe('Shared: Release', function() {
const uniqueValues = _.uniq(_.values(release.RELEASE_TYPE)); const uniqueValues = _.uniq(_.values(release.RELEASE_TYPE));
m.chai.expect(_.size(keys)).to.equal(_.size(uniqueValues)); m.chai.expect(_.size(keys)).to.equal(_.size(uniqueValues));
}); });
}); });
describe('.getReleaseType()', function () { describe('.getReleaseType()', function () {
it('should return the unknown release type if the version is not valid semver', function () { it('should return the unknown release type if the version is not valid semver', function () {
const releaseType = release.getReleaseType('foo.bar'); const releaseType = release.getReleaseType('foo.bar');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.UNKNOWN); m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.UNKNOWN);
}); });
describe('given the version has a short git commit hash build number', function () { describe('given the version has a short git commit hash build number', function () {
it('should return the snapshot release type', function () { it('should return the snapshot release type', function () {
const releaseType = release.getReleaseType('1.0.0+6374412'); const releaseType = release.getReleaseType('1.0.0+6374412');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT); m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT);
@ -54,11 +49,9 @@ describe('Shared: Release', function() {
const releaseType = release.getReleaseType('1.0.0-beta.19+6374412'); const releaseType = release.getReleaseType('1.0.0-beta.19+6374412');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT); m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT);
}); });
}); });
describe('given the version has a long git commit hash build number', function () { describe('given the version has a long git commit hash build number', function () {
it('should return the snapshot release type', function () { it('should return the snapshot release type', function () {
const releaseType = release.getReleaseType('1.0.0+6374412554b034799bfc6e13b4e39c3f5e6386e6'); const releaseType = release.getReleaseType('1.0.0+6374412554b034799bfc6e13b4e39c3f5e6386e6');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT); m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT);
@ -68,11 +61,9 @@ describe('Shared: Release', function() {
const releaseType = release.getReleaseType('1.0.0-beta.19+6374412554b034799bfc6e13b4e39c3f5e6386e6'); const releaseType = release.getReleaseType('1.0.0-beta.19+6374412554b034799bfc6e13b4e39c3f5e6386e6');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT); m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT);
}); });
}); });
describe('given the version has no build number', function () { describe('given the version has no build number', function () {
it('should return the production release type', function () { it('should return the production release type', function () {
const releaseType = release.getReleaseType('1.0.0'); const releaseType = release.getReleaseType('1.0.0');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.PRODUCTION); m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.PRODUCTION);
@ -82,11 +73,9 @@ describe('Shared: Release', function() {
const releaseType = release.getReleaseType('1.0.0-beta.19'); const releaseType = release.getReleaseType('1.0.0-beta.19');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.PRODUCTION); m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.PRODUCTION);
}); });
}); });
describe('given a build number that is not a git commit hash', function () { describe('given a build number that is not a git commit hash', function () {
it('should return the unknown release type', function () { it('should return the unknown release type', function () {
const releaseType = release.getReleaseType('1.0.0+foo'); const releaseType = release.getReleaseType('1.0.0+foo');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.UNKNOWN); m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.UNKNOWN);
@ -96,13 +85,10 @@ describe('Shared: Release', function() {
const releaseType = release.getReleaseType('1.0.0-beta.19+foo'); const releaseType = release.getReleaseType('1.0.0-beta.19+foo');
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.UNKNOWN); m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.UNKNOWN);
}); });
}); });
}); });
describe('.isStableRelease()', function () { describe('.isStableRelease()', function () {
it('should return true if given a production stable version', function () { it('should return true if given a production stable version', function () {
m.chai.expect(release.isStableRelease('1.0.0')).to.be.true; m.chai.expect(release.isStableRelease('1.0.0')).to.be.true;
}); });
@ -126,7 +112,5 @@ describe('Shared: Release', function() {
it('should return false if given a snapshot beta version', function () { it('should return false if given a snapshot beta version', function () {
m.chai.expect(release.isStableRelease('1.0.0-beta.1+6374412')).to.be.false; m.chai.expect(release.isStableRelease('1.0.0-beta.1+6374412')).to.be.false;
}); });
}); });
}); });

View File

@ -21,9 +21,7 @@ const _ = require('lodash');
const robot = require('../../lib/shared/robot'); const robot = require('../../lib/shared/robot');
describe('Shared: Robot', function () { describe('Shared: Robot', function () {
describe('.COMMAND', function () { describe('.COMMAND', function () {
it('should be a plain object', function () { it('should be a plain object', function () {
m.chai.expect(_.isPlainObject(robot.COMMAND)).to.be.true; m.chai.expect(_.isPlainObject(robot.COMMAND)).to.be.true;
}); });
@ -36,11 +34,9 @@ describe('Shared: Robot', function() {
const numberOfKeys = _.size(_.keys(robot.COMMAND)); const numberOfKeys = _.size(_.keys(robot.COMMAND));
m.chai.expect(_.size(_.uniq(_.values(robot.COMMAND)))).to.equal(numberOfKeys); m.chai.expect(_.size(_.uniq(_.values(robot.COMMAND)))).to.equal(numberOfKeys);
}); });
}); });
describe('.isEnabled()', function () { describe('.isEnabled()', function () {
it('should return false if ETCHER_CLI_ROBOT is not set', function () { it('should return false if ETCHER_CLI_ROBOT is not set', function () {
m.chai.expect(robot.isEnabled({})).to.be.false; m.chai.expect(robot.isEnabled({})).to.be.false;
}); });
@ -80,11 +76,9 @@ describe('Shared: Robot', function() {
ETCHER_CLI_ROBOT: false ETCHER_CLI_ROBOT: false
})).to.be.false; })).to.be.false;
}); });
}); });
describe('.buildMessage()', function () { describe('.buildMessage()', function () {
it('should build a message without data', function () { it('should build a message without data', function () {
const message = robot.buildMessage('hello'); const message = robot.buildMessage('hello');
const result = '{"command":"hello","data":{}}'; const result = '{"command":"hello","data":{}}';
@ -105,11 +99,9 @@ describe('Shared: Robot', function() {
robot.buildMessage('hello', 'world'); robot.buildMessage('hello', 'world');
}).to.throw('Invalid data: world'); }).to.throw('Invalid data: world');
}); });
}); });
describe('.isMessage()', function () { describe('.isMessage()', function () {
it('should return true if message is an empty object', function () { it('should return true if message is an empty object', function () {
m.chai.expect(robot.isMessage('{}')).to.be.true; m.chai.expect(robot.isMessage('{}')).to.be.true;
}); });
@ -200,11 +192,9 @@ describe('Shared: Robot', function() {
const error = new Error('foo'); const error = new Error('foo');
m.chai.expect(robot.isMessage(robot.buildErrorMessage(error))).to.be.true; m.chai.expect(robot.isMessage(robot.buildErrorMessage(error))).to.be.true;
}); });
}); });
describe('.buildErrorMessage()', function () { describe('.buildErrorMessage()', function () {
it('should build a message from a simple error', function () { it('should build a message from a simple error', function () {
const error = new Error('foo'); const error = new Error('foo');
const message = robot.buildErrorMessage(error); const message = robot.buildErrorMessage(error);
@ -254,11 +244,9 @@ describe('Shared: Robot', function() {
m.chai.expect(message.data.stack).to.be.a.string; m.chai.expect(message.data.stack).to.be.a.string;
m.chai.expect(_.isEmpty(message.data.stack)).to.be.false; m.chai.expect(_.isEmpty(message.data.stack)).to.be.false;
}); });
}); });
describe('.parseMessage()', function () { describe('.parseMessage()', function () {
it('should parse a valid message', function () { it('should parse a valid message', function () {
const message = robot.buildMessage('foo', { const message = robot.buildMessage('foo', {
bar: 1 bar: 1
@ -297,11 +285,9 @@ describe('Shared: Robot', function() {
robot.parseMessage('{"command":"foo"}'); robot.parseMessage('{"command":"foo"}');
}).to.throw('Invalid message'); }).to.throw('Invalid message');
}); });
}); });
describe('.getCommand()', function () { describe('.getCommand()', function () {
it('should get the command of a message', function () { it('should get the command of a message', function () {
const message = robot.parseMessage(robot.buildMessage('hello', { const message = robot.parseMessage(robot.buildMessage('hello', {
foo: 1, foo: 1,
@ -310,11 +296,9 @@ describe('Shared: Robot', function() {
m.chai.expect(robot.getCommand(message)).to.equal('hello'); m.chai.expect(robot.getCommand(message)).to.equal('hello');
}); });
}); });
describe('.getData()', function () { describe('.getData()', function () {
it('should get the data of a message', function () { it('should get the data of a message', function () {
const message = robot.parseMessage(robot.buildMessage('hello', { const message = robot.parseMessage(robot.buildMessage('hello', {
foo: 1, foo: 1,
@ -332,11 +316,9 @@ describe('Shared: Robot', function() {
command: 'foo' command: 'foo'
})).to.deep.equal({}); })).to.deep.equal({});
}); });
}); });
describe('.recomposeErrorMessage()', function () { describe('.recomposeErrorMessage()', function () {
it('should return an instance of Error', function () { it('should return an instance of Error', function () {
const error = new Error('Foo bar'); const error = new Error('Foo bar');
const message = robot.parseMessage(robot.buildErrorMessage(error)); const message = robot.parseMessage(robot.buildErrorMessage(error));
@ -362,7 +344,5 @@ describe('Shared: Robot', function() {
const message = robot.parseMessage(robot.buildErrorMessage(error)); const message = robot.parseMessage(robot.buildErrorMessage(error));
m.chai.expect(robot.recomposeErrorMessage(message)).to.deep.equal(error); m.chai.expect(robot.recomposeErrorMessage(message)).to.deep.equal(error);
}); });
}); });
}); });

View File

@ -24,9 +24,7 @@ const s3Packages = require('../../lib/shared/s3-packages');
const release = require('../../lib/shared/release'); const release = require('../../lib/shared/release');
describe('Shared: s3Packages', function () { describe('Shared: s3Packages', function () {
describe('.getBucketUrlFromReleaseType()', function () { describe('.getBucketUrlFromReleaseType()', function () {
it('should return the production URL if given a production release type', function () { it('should return the production URL if given a production release type', function () {
const bucketUrl = s3Packages.getBucketUrlFromReleaseType(release.RELEASE_TYPE.PRODUCTION); const bucketUrl = s3Packages.getBucketUrlFromReleaseType(release.RELEASE_TYPE.PRODUCTION);
m.chai.expect(bucketUrl).to.equal(s3Packages.BUCKET_URL.PRODUCTION); m.chai.expect(bucketUrl).to.equal(s3Packages.BUCKET_URL.PRODUCTION);
@ -41,11 +39,9 @@ describe('Shared: s3Packages', function() {
const bucketUrl = s3Packages.getBucketUrlFromReleaseType(release.RELEASE_TYPE.UNKNOWN); const bucketUrl = s3Packages.getBucketUrlFromReleaseType(release.RELEASE_TYPE.UNKNOWN);
m.chai.expect(bucketUrl).to.be.null; m.chai.expect(bucketUrl).to.be.null;
}); });
}); });
describe('.getRemoteVersions()', function () { describe('.getRemoteVersions()', function () {
beforeEach(function () { beforeEach(function () {
s3Packages.getRemoteVersions.cache.clear(); s3Packages.getRemoteVersions.cache.clear();
}); });
@ -59,7 +55,6 @@ describe('Shared: s3Packages', function() {
}); });
describe('given an empty bucket', function () { describe('given an empty bucket', function () {
beforeEach(function () { beforeEach(function () {
nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, ` nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, `
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
@ -82,11 +77,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given many versions', function () { describe('given many versions', function () {
beforeEach(function () { beforeEach(function () {
nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, ` nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, `
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
@ -224,11 +217,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given a version is being uploaded', function () { describe('given a version is being uploaded', function () {
beforeEach(function () { beforeEach(function () {
nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, ` nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, `
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
@ -358,11 +349,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given other programs in the bucket', function () { describe('given other programs in the bucket', function () {
beforeEach(function () { beforeEach(function () {
nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, ` nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, `
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
@ -499,11 +488,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given only other programs in the bucket', function () { describe('given only other programs in the bucket', function () {
beforeEach(function () { beforeEach(function () {
nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, ` nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, `
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> <ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
@ -575,11 +562,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given an unsuccessful request', function () { describe('given an unsuccessful request', function () {
beforeEach(function () { beforeEach(function () {
nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(500); nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(500);
}); });
@ -594,11 +579,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}); });
}); });
}); });
describe('given ENOTFOUND', function () { describe('given ENOTFOUND', function () {
beforeEach(function () { beforeEach(function () {
const error = new Error('ENOTFOUND'); const error = new Error('ENOTFOUND');
error.code = 'ENOTFOUND'; error.code = 'ENOTFOUND';
@ -617,11 +600,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given ETIMEDOUT', function () { describe('given ETIMEDOUT', function () {
beforeEach(function () { beforeEach(function () {
const error = new Error('ETIMEDOUT'); const error = new Error('ETIMEDOUT');
error.code = 'ETIMEDOUT'; error.code = 'ETIMEDOUT';
@ -640,11 +621,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given EHOSTDOWN', function () { describe('given EHOSTDOWN', function () {
beforeEach(function () { beforeEach(function () {
const error = new Error('EHOSTDOWN'); const error = new Error('EHOSTDOWN');
error.code = 'EHOSTDOWN'; error.code = 'EHOSTDOWN';
@ -663,11 +642,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given ECONNRESET', function () { describe('given ECONNRESET', function () {
beforeEach(function () { beforeEach(function () {
const error = new Error('ECONNRESET'); const error = new Error('ECONNRESET');
error.code = 'ECONNRESET'; error.code = 'ECONNRESET';
@ -686,11 +663,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given ECONNREFUSED', function () { describe('given ECONNREFUSED', function () {
beforeEach(function () { beforeEach(function () {
const error = new Error('ECONNREFUSED'); const error = new Error('ECONNREFUSED');
error.code = 'ECONNREFUSED'; error.code = 'ECONNREFUSED';
@ -709,11 +684,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given EACCES', function () { describe('given EACCES', function () {
beforeEach(function () { beforeEach(function () {
const error = new Error('EACCES'); const error = new Error('EACCES');
error.code = 'EACCES'; error.code = 'EACCES';
@ -732,11 +705,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given UNABLE_TO_VERIFY_LEAF_SIGNATURE', function () { describe('given UNABLE_TO_VERIFY_LEAF_SIGNATURE', function () {
beforeEach(function () { beforeEach(function () {
const error = new Error('UNABLE_TO_VERIFY_LEAF_SIGNATURE'); const error = new Error('UNABLE_TO_VERIFY_LEAF_SIGNATURE');
error.code = 'UNABLE_TO_VERIFY_LEAF_SIGNATURE'; error.code = 'UNABLE_TO_VERIFY_LEAF_SIGNATURE';
@ -755,15 +726,11 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
}); });
describe('.getLatestVersion()', function () { describe('.getLatestVersion()', function () {
describe('given a valid production ETCHER_FAKE_S3_LATEST_VERSION environment variable', function () { describe('given a valid production ETCHER_FAKE_S3_LATEST_VERSION environment variable', function () {
beforeEach(function () { beforeEach(function () {
process.env.ETCHER_FAKE_S3_LATEST_VERSION = '9.9.9'; process.env.ETCHER_FAKE_S3_LATEST_VERSION = '9.9.9';
}); });
@ -773,31 +740,25 @@ describe('Shared: s3Packages', function() {
}); });
describe('given a production release type', function () { describe('given a production release type', function () {
it('should resolve the variable', function (done) { it('should resolve the variable', function (done) {
s3Packages.getLatestVersion(release.RELEASE_TYPE.PRODUCTION).then((latestVersion) => { s3Packages.getLatestVersion(release.RELEASE_TYPE.PRODUCTION).then((latestVersion) => {
m.chai.expect(latestVersion).to.equal('9.9.9'); m.chai.expect(latestVersion).to.equal('9.9.9');
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given a snapshot release type', function () { describe('given a snapshot release type', function () {
it('should resolve undefined', function (done) { it('should resolve undefined', function (done) {
s3Packages.getLatestVersion(release.RELEASE_TYPE.SNAPSHOT).then((latestVersion) => { s3Packages.getLatestVersion(release.RELEASE_TYPE.SNAPSHOT).then((latestVersion) => {
m.chai.expect(latestVersion).to.be.undefined; m.chai.expect(latestVersion).to.be.undefined;
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
}); });
describe('given a valid snapshot ETCHER_FAKE_S3_LATEST_VERSION environment variable', function () { describe('given a valid snapshot ETCHER_FAKE_S3_LATEST_VERSION environment variable', function () {
beforeEach(function () { beforeEach(function () {
process.env.ETCHER_FAKE_S3_LATEST_VERSION = '9.9.9+7b47334'; process.env.ETCHER_FAKE_S3_LATEST_VERSION = '9.9.9+7b47334';
}); });
@ -807,31 +768,25 @@ describe('Shared: s3Packages', function() {
}); });
describe('given a snapshot release type', function () { describe('given a snapshot release type', function () {
it('should resolve the variable', function (done) { it('should resolve the variable', function (done) {
s3Packages.getLatestVersion(release.RELEASE_TYPE.SNAPSHOT).then((latestVersion) => { s3Packages.getLatestVersion(release.RELEASE_TYPE.SNAPSHOT).then((latestVersion) => {
m.chai.expect(latestVersion).to.equal('9.9.9+7b47334'); m.chai.expect(latestVersion).to.equal('9.9.9+7b47334');
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given a production release type', function () { describe('given a production release type', function () {
it('should resolve undefined', function (done) { it('should resolve undefined', function (done) {
s3Packages.getLatestVersion(release.RELEASE_TYPE.PRODUCTION).then((latestVersion) => { s3Packages.getLatestVersion(release.RELEASE_TYPE.PRODUCTION).then((latestVersion) => {
m.chai.expect(latestVersion).to.be.undefined; m.chai.expect(latestVersion).to.be.undefined;
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
}); });
describe('given an invalid ETCHER_FAKE_S3_LATEST_VERSION environment variable', function () { describe('given an invalid ETCHER_FAKE_S3_LATEST_VERSION environment variable', function () {
beforeEach(function () { beforeEach(function () {
process.env.ETCHER_FAKE_S3_LATEST_VERSION = 'foo'; process.env.ETCHER_FAKE_S3_LATEST_VERSION = 'foo';
}); });
@ -846,11 +801,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given an invalid release type', function () { describe('given an invalid release type', function () {
it('should be rejected with an error', function (done) { it('should be rejected with an error', function (done) {
s3Packages.getLatestVersion('foobar').catch((error) => { s3Packages.getLatestVersion('foobar').catch((error) => {
m.chai.expect(error).to.be.an.instanceof(Error); m.chai.expect(error).to.be.an.instanceof(Error);
@ -858,11 +811,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}); });
}); });
}); });
describe('given no remote versions', function () { describe('given no remote versions', function () {
beforeEach(function () { beforeEach(function () {
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions'); this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
this.getRemoteVersionsStub.returns(Bluebird.resolve([])); this.getRemoteVersionsStub.returns(Bluebird.resolve([]));
@ -878,11 +829,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given a single version', function () { describe('given a single version', function () {
beforeEach(function () { beforeEach(function () {
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions'); this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
this.getRemoteVersionsStub.returns(Bluebird.resolve([ '0.5.0' ])); this.getRemoteVersionsStub.returns(Bluebird.resolve([ '0.5.0' ]));
@ -898,11 +847,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given multiple versions', function () { describe('given multiple versions', function () {
beforeEach(function () { beforeEach(function () {
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions'); this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
this.getRemoteVersionsStub.returns(Bluebird.resolve([ this.getRemoteVersionsStub.returns(Bluebird.resolve([
@ -923,11 +870,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given a greater production version in a snapshot bucket', function () { describe('given a greater production version in a snapshot bucket', function () {
beforeEach(function () { beforeEach(function () {
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions'); this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
this.getRemoteVersionsStub.returns(Bluebird.resolve([ this.getRemoteVersionsStub.returns(Bluebird.resolve([
@ -946,11 +891,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given a greater snapshot version in a production bucket', function () { describe('given a greater snapshot version in a production bucket', function () {
beforeEach(function () { beforeEach(function () {
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions'); this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
this.getRemoteVersionsStub.returns(Bluebird.resolve([ this.getRemoteVersionsStub.returns(Bluebird.resolve([
@ -969,11 +912,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given production v1, v2, and v3 remote versions', function () { describe('given production v1, v2, and v3 remote versions', function () {
beforeEach(function () { beforeEach(function () {
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions'); this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
this.getRemoteVersionsStub.returns(Bluebird.resolve([ this.getRemoteVersionsStub.returns(Bluebird.resolve([
@ -1038,11 +979,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given unstable and stable versions where the last version is stable', function () { describe('given unstable and stable versions where the last version is stable', function () {
beforeEach(function () { beforeEach(function () {
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions'); this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
this.getRemoteVersionsStub.returns(Bluebird.resolve([ this.getRemoteVersionsStub.returns(Bluebird.resolve([
@ -1076,11 +1015,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given unstable and stable versions where the last version is unstable', function () { describe('given unstable and stable versions where the last version is unstable', function () {
beforeEach(function () { beforeEach(function () {
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions'); this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
this.getRemoteVersionsStub.returns(Bluebird.resolve([ this.getRemoteVersionsStub.returns(Bluebird.resolve([
@ -1115,11 +1052,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given pre-release production remote versions', function () { describe('given pre-release production remote versions', function () {
beforeEach(function () { beforeEach(function () {
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions'); this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
this.getRemoteVersionsStub.returns(Bluebird.resolve([ this.getRemoteVersionsStub.returns(Bluebird.resolve([
@ -1156,11 +1091,9 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
describe('given pre-release snapshot remote versions', function () { describe('given pre-release snapshot remote versions', function () {
beforeEach(function () { beforeEach(function () {
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions'); this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
this.getRemoteVersionsStub.returns(Bluebird.resolve([ this.getRemoteVersionsStub.returns(Bluebird.resolve([
@ -1197,9 +1130,6 @@ describe('Shared: s3Packages', function() {
done(); done();
}).catch(done); }).catch(done);
}); });
}); });
}); });
}); });

View File

@ -21,36 +21,28 @@ const _ = require('lodash');
const supportedFormats = require('../../lib/shared/supported-formats'); const supportedFormats = require('../../lib/shared/supported-formats');
describe('Shared: SupportedFormats', function () { describe('Shared: SupportedFormats', function () {
describe('.getCompressedExtensions()', function () { describe('.getCompressedExtensions()', function () {
it('should return the supported compressed extensions', function () { it('should return the supported compressed extensions', function () {
const extensions = supportedFormats.getCompressedExtensions(); const extensions = supportedFormats.getCompressedExtensions();
m.chai.expect(extensions).to.deep.equal([ 'gz', 'bz2', 'xz' ]); m.chai.expect(extensions).to.deep.equal([ 'gz', 'bz2', 'xz' ]);
}); });
}); });
describe('.getNonCompressedExtensions()', function () { describe('.getNonCompressedExtensions()', function () {
it('should return the supported non compressed extensions', function () { it('should return the supported non compressed extensions', function () {
const extensions = supportedFormats.getNonCompressedExtensions(); const extensions = supportedFormats.getNonCompressedExtensions();
m.chai.expect(extensions).to.deep.equal([ 'img', 'iso', 'dsk', 'hddimg', 'raw', 'dmg', 'sdcard', 'rpi-sdimg' ]); m.chai.expect(extensions).to.deep.equal([ 'img', 'iso', 'dsk', 'hddimg', 'raw', 'dmg', 'sdcard', 'rpi-sdimg' ]);
}); });
}); });
describe('.getArchiveExtensions()', function () { describe('.getArchiveExtensions()', function () {
it('should return the supported archive extensions', function () { it('should return the supported archive extensions', function () {
const extensions = supportedFormats.getArchiveExtensions(); const extensions = supportedFormats.getArchiveExtensions();
m.chai.expect(extensions).to.deep.equal([ 'zip', 'etch' ]); m.chai.expect(extensions).to.deep.equal([ 'zip', 'etch' ]);
}); });
}); });
describe('.getAllExtensions()', function () { describe('.getAllExtensions()', function () {
it('should return the union of all compressed, uncompressed, and archive extensions', function () { it('should return the union of all compressed, uncompressed, and archive extensions', function () {
const archiveExtensions = supportedFormats.getArchiveExtensions(); const archiveExtensions = supportedFormats.getArchiveExtensions();
const compressedExtensions = supportedFormats.getCompressedExtensions(); const compressedExtensions = supportedFormats.getCompressedExtensions();
@ -59,11 +51,9 @@ describe('Shared: SupportedFormats', function() {
const extensions = supportedFormats.getAllExtensions(); const extensions = supportedFormats.getAllExtensions();
m.chai.expect(extensions).to.deep.equal(expected); m.chai.expect(extensions).to.deep.equal(expected);
}); });
}); });
describe('.isSupportedImage()', function () { describe('.isSupportedImage()', function () {
_.forEach([ _.forEach([
// Type: 'archive' // Type: 'archive'
@ -210,37 +200,29 @@ describe('Shared: SupportedFormats', function() {
const isSupported = supportedFormats.isSupportedImage(imagePath); const isSupported = supportedFormats.isSupportedImage(imagePath);
m.chai.expect(isSupported).to.be.false; m.chai.expect(isSupported).to.be.false;
}); });
}); });
describe('.looksLikeWindowsImage()', function () { describe('.looksLikeWindowsImage()', function () {
_.each([ _.each([
'C:\\path\\to\\en_windows_10_multiple_editions_version_1607_updated_jan_2017_x64_dvd_9714399.iso', 'C:\\path\\to\\en_windows_10_multiple_editions_version_1607_updated_jan_2017_x64_dvd_9714399.iso',
'/path/to/en_windows_10_multiple_editions_version_1607_updated_jan_2017_x64_dvd_9714399.iso', '/path/to/en_windows_10_multiple_editions_version_1607_updated_jan_2017_x64_dvd_9714399.iso',
'/path/to/Win10_1607_SingleLang_English_x32.iso', '/path/to/Win10_1607_SingleLang_English_x32.iso',
'/path/to/en_winxp_pro_x86_build2600_iso.img' '/path/to/en_winxp_pro_x86_build2600_iso.img'
], (imagePath) => { ], (imagePath) => {
it(`should return true if filename is ${imagePath}`, function () { it(`should return true if filename is ${imagePath}`, function () {
const looksLikeWindowsImage = supportedFormats.looksLikeWindowsImage(imagePath); const looksLikeWindowsImage = supportedFormats.looksLikeWindowsImage(imagePath);
m.chai.expect(looksLikeWindowsImage).to.be.true; m.chai.expect(looksLikeWindowsImage).to.be.true;
}); });
}); });
_.each([ _.each([
'C:\\path\\to\\2017-01-11-raspbian-jessie.img', 'C:\\path\\to\\2017-01-11-raspbian-jessie.img',
'/path/to/2017-01-11-raspbian-jessie.img' '/path/to/2017-01-11-raspbian-jessie.img'
], (imagePath) => { ], (imagePath) => {
it(`should return false if filename is ${imagePath}`, function () { it(`should return false if filename is ${imagePath}`, function () {
const looksLikeWindowsImage = supportedFormats.looksLikeWindowsImage(imagePath); const looksLikeWindowsImage = supportedFormats.looksLikeWindowsImage(imagePath);
m.chai.expect(looksLikeWindowsImage).to.be.false; m.chai.expect(looksLikeWindowsImage).to.be.false;
}); });
}); });
}); });
}); });

View File

@ -20,9 +20,7 @@ const m = require('mochainon');
const units = require('../../lib/shared/units'); const units = require('../../lib/shared/units');
describe('Shared: Units', function () { describe('Shared: Units', function () {
describe('.bytesToClosestUnit()', function () { describe('.bytesToClosestUnit()', function () {
it('should convert bytes to terabytes', function () { it('should convert bytes to terabytes', function () {
m.chai.expect(units.bytesToClosestUnit(1000000000000)).to.equal('1 TB'); m.chai.expect(units.bytesToClosestUnit(1000000000000)).to.equal('1 TB');
m.chai.expect(units.bytesToClosestUnit(2987801405440)).to.equal('2.99 TB'); m.chai.expect(units.bytesToClosestUnit(2987801405440)).to.equal('2.99 TB');
@ -52,16 +50,12 @@ describe('Shared: Units', function() {
m.chai.expect(units.bytesToClosestUnit(8)).to.equal('8 B'); m.chai.expect(units.bytesToClosestUnit(8)).to.equal('8 B');
m.chai.expect(units.bytesToClosestUnit(999)).to.equal('999 B'); m.chai.expect(units.bytesToClosestUnit(999)).to.equal('999 B');
}); });
}); });
describe('.bytesToMegabytes()', function () { describe('.bytesToMegabytes()', function () {
it('should convert bytes to megabytes', function () { it('should convert bytes to megabytes', function () {
m.chai.expect(units.bytesToMegabytes(1.2e+7)).to.equal(12); m.chai.expect(units.bytesToMegabytes(1.2e+7)).to.equal(12);
m.chai.expect(units.bytesToMegabytes(332000)).to.equal(0.332); m.chai.expect(units.bytesToMegabytes(332000)).to.equal(0.332);
}); });
}); });
}); });

View File

@ -20,9 +20,7 @@ const m = require('mochainon');
const utils = require('../../lib/shared/utils'); const utils = require('../../lib/shared/utils');
describe('Shared: Utils', function () { describe('Shared: Utils', function () {
describe('.isValidPercentage()', function () { describe('.isValidPercentage()', function () {
it('should return false if percentage is not a number', function () { it('should return false if percentage is not a number', function () {
m.chai.expect(utils.isValidPercentage('50')).to.be.false; m.chai.expect(utils.isValidPercentage('50')).to.be.false;
}); });
@ -66,11 +64,9 @@ describe('Shared: Utils', function() {
it('should return false if percentage is a float greater than 100', function () { it('should return false if percentage is a float greater than 100', function () {
m.chai.expect(utils.isValidPercentage(100.001)).to.be.false; m.chai.expect(utils.isValidPercentage(100.001)).to.be.false;
}); });
}); });
describe('.percentageToFloat()', function () { describe('.percentageToFloat()', function () {
it('should throw an error if given a string percentage', function () { it('should throw an error if given a string percentage', function () {
m.chai.expect(function () { m.chai.expect(function () {
utils.percentageToFloat('50'); utils.percentageToFloat('50');
@ -128,7 +124,5 @@ describe('Shared: Utils', function() {
utils.percentageToFloat(100.01); utils.percentageToFloat(100.01);
}).to.throw('Invalid percentage: 100.01'); }).to.throw('Invalid percentage: 100.01');
}); });
}); });
}); });