mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-25 12:16:37 +00:00
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:
parent
064c741e3f
commit
5c19b70e83
@ -461,10 +461,10 @@ rules:
|
||||
- always
|
||||
operator-linebreak:
|
||||
- error
|
||||
- before
|
||||
- after
|
||||
padded-blocks:
|
||||
- error
|
||||
- classes: always
|
||||
- never
|
||||
quote-props:
|
||||
- error
|
||||
- as-needed
|
||||
@ -489,7 +489,9 @@ rules:
|
||||
- error
|
||||
space-before-function-paren:
|
||||
- error
|
||||
- never
|
||||
- anonymous: always
|
||||
named: always
|
||||
asyncArrow: never
|
||||
space-in-parens:
|
||||
- error
|
||||
- never
|
||||
|
@ -86,7 +86,6 @@ exports.write = (image, drive, options) => {
|
||||
* terminateServer();
|
||||
*/
|
||||
const terminateServer = () => {
|
||||
|
||||
// Turns out we need to destroy all sockets for
|
||||
// the server to actually close. Otherwise, it
|
||||
// just stops receiving any further connections,
|
||||
@ -137,7 +136,6 @@ exports.write = (image, drive, options) => {
|
||||
return robot.parseMessage(robot.buildMessage(robot.COMMAND.LOG, {
|
||||
message
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
if (_.isError(parsedMessage)) {
|
||||
@ -146,7 +144,6 @@ exports.write = (image, drive, options) => {
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
// These are lighweight accessor methods for
|
||||
// the properties of the parsed message
|
||||
const messageCommand = robot.getCommand(parsedMessage);
|
||||
@ -158,7 +155,6 @@ exports.write = (image, drive, options) => {
|
||||
if (messageCommand === robot.COMMAND.ERROR) {
|
||||
emitError(robot.recomposeErrorMessage(parsedMessage));
|
||||
} else if (messageCommand === robot.COMMAND.LOG) {
|
||||
|
||||
// If the message data is an object and it contains a
|
||||
// message string then log the message string only.
|
||||
if (_.isPlainObject(messageData) && _.isString(messageData.message)) {
|
||||
@ -166,11 +162,9 @@ exports.write = (image, drive, options) => {
|
||||
} else {
|
||||
console.log(messageData);
|
||||
}
|
||||
|
||||
} else {
|
||||
emitter.emit(messageCommand, messageData);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
emitError(error);
|
||||
}
|
||||
@ -194,7 +188,6 @@ exports.write = (image, drive, options) => {
|
||||
|
||||
// This function causes the `close` event to be emitted
|
||||
child.kill();
|
||||
|
||||
});
|
||||
|
||||
child.on('error', emitError);
|
||||
|
@ -47,5 +47,4 @@ exports.getApplicationEntryPoint = () => {
|
||||
// from `/root`, therefore we pass an absolute path,
|
||||
// in order to be on the safe side.
|
||||
return path.join(CONSTANTS.PROJECT_ROOT, relativeEntryPoint);
|
||||
|
||||
};
|
||||
|
@ -64,14 +64,12 @@ const OPTIONS_INDEX_START = 2;
|
||||
*/
|
||||
const etcherArguments = process.argv.slice(OPTIONS_INDEX_START);
|
||||
|
||||
return permissions.isElevated().then((elevated) => {
|
||||
|
||||
permissions.isElevated().then((elevated) => {
|
||||
if (!elevated) {
|
||||
console.log('Attempting to elevate');
|
||||
|
||||
const commandArguments = _.attempt(() => {
|
||||
if (os.platform() === 'linux' && process.env.APPIMAGE && process.env.APPDIR) {
|
||||
|
||||
// Translate the current arguments to point to the AppImage
|
||||
// Relative paths are resolved from `/tmp/.mount_XXXXXX/usr`
|
||||
const translatedArguments = _.chain(process.argv)
|
||||
@ -125,7 +123,6 @@ return permissions.isElevated().then((elevated) => {
|
||||
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('connect', () => {
|
||||
|
||||
const child = childProcess.spawn(executable, etcherArguments, {
|
||||
env: {
|
||||
|
||||
@ -160,7 +157,6 @@ return permissions.isElevated().then((elevated) => {
|
||||
* })));
|
||||
*/
|
||||
const emitMessage = (data) => {
|
||||
|
||||
// Output from stdout/stderr coming from the CLI might be buffered,
|
||||
// causing several progress lines to come up at once as single message.
|
||||
// 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) => {
|
||||
ipc.of[process.env.IPC_SERVER_ID].emit('message', object);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
child.stdout.on('data', emitMessage);
|
||||
|
@ -94,7 +94,6 @@ permissions.isElevated().then((elevated) => {
|
||||
unmountOnSuccess: options.unmount,
|
||||
validateWriteOnSuccess: options.check
|
||||
}, (state) => {
|
||||
|
||||
if (robot.isEnabled(process.env)) {
|
||||
robot.printMessage('progress', {
|
||||
type: state.type,
|
||||
@ -105,7 +104,6 @@ permissions.isElevated().then((elevated) => {
|
||||
} else {
|
||||
progressBars[state.type].update(state);
|
||||
}
|
||||
|
||||
}).then((results) => {
|
||||
return {
|
||||
imagePath,
|
||||
@ -115,7 +113,6 @@ permissions.isElevated().then((elevated) => {
|
||||
});
|
||||
});
|
||||
}).then((results) => {
|
||||
|
||||
return Bluebird.try(() => {
|
||||
if (robot.isEnabled(process.env)) {
|
||||
return robot.printMessage('done', {
|
||||
@ -136,9 +133,7 @@ permissions.isElevated().then((elevated) => {
|
||||
}).then(() => {
|
||||
process.exit(EXIT_CODES.SUCCESS);
|
||||
});
|
||||
|
||||
}).catch((error) => {
|
||||
|
||||
return Bluebird.try(() => {
|
||||
if (robot.isEnabled(process.env)) {
|
||||
return robot.printError(error);
|
||||
@ -153,5 +148,4 @@ permissions.isElevated().then((elevated) => {
|
||||
|
||||
process.exit(EXIT_CODES.GENERAL_ERROR);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -65,7 +65,6 @@ const UNMOUNT_ON_SUCCESS_TIMEOUT_MS = 2000;
|
||||
*/
|
||||
exports.writeImage = (imagePath, drive, options, onProgress) => {
|
||||
return Bluebird.try(() => {
|
||||
|
||||
// Unmounting a drive in Windows means we can't write to it anymore
|
||||
if (os.platform() === 'win32') {
|
||||
return Bluebird.resolve();
|
||||
@ -103,14 +102,12 @@ exports.writeImage = (imagePath, drive, options, onProgress) => {
|
||||
writer.on('done', resolve);
|
||||
});
|
||||
}).tap(() => {
|
||||
|
||||
// Make sure the device stream file descriptor is closed
|
||||
// before returning control the the caller. Not closing
|
||||
// the file descriptor (and waiting for it) results in
|
||||
// `EBUSY` errors when attempting to unmount the drive
|
||||
// right afterwards in some Windows 7 systems.
|
||||
return fs.closeAsync(driveFileDescriptor).then(() => {
|
||||
|
||||
if (!options.unmountOnSuccess) {
|
||||
return Bluebird.resolve();
|
||||
}
|
||||
@ -122,7 +119,6 @@ exports.writeImage = (imagePath, drive, options, onProgress) => {
|
||||
return Bluebird.delay(UNMOUNT_ON_SUCCESS_TIMEOUT_MS)
|
||||
.return(drive.device)
|
||||
.then(mountutils.unmountDiskAsync);
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -184,7 +184,6 @@ app.run(() => {
|
||||
|
||||
app.run(($timeout) => {
|
||||
driveScanner.on('drives', (drives) => {
|
||||
|
||||
// Safely trigger a digest cycle.
|
||||
// In some cases, AngularJS doesn't acknowledge that the
|
||||
// available drives list has changed, and incorrectly
|
||||
@ -195,7 +194,6 @@ app.run(($timeout) => {
|
||||
});
|
||||
|
||||
driveScanner.on('error', (error) => {
|
||||
|
||||
// Stop the drive scanning loop in case of errors,
|
||||
// otherwise we risk presenting the same error over
|
||||
// and over again to the user, while also heavily
|
||||
@ -241,7 +239,6 @@ app.run(($window) => {
|
||||
// This circumvents the 'beforeunload' event unlike
|
||||
// electron.remote.app.quit() which does not.
|
||||
electron.remote.process.exit(EXIT_CODES.SUCCESS);
|
||||
|
||||
}
|
||||
|
||||
analytics.logEvent('Close rejected while flashing');
|
||||
@ -252,7 +249,6 @@ app.run(($window) => {
|
||||
|
||||
app.run(($rootScope) => {
|
||||
$rootScope.$on('$stateChangeSuccess', (event, toState, toParams, fromState) => {
|
||||
|
||||
// Ignore first navigation
|
||||
if (!fromState.name) {
|
||||
return;
|
||||
@ -279,7 +275,6 @@ app.config(($provide) => {
|
||||
});
|
||||
|
||||
app.controller('HeaderController', function (OSOpenExternalService) {
|
||||
|
||||
/**
|
||||
* @summary Open help page
|
||||
* @function
|
||||
@ -297,7 +292,6 @@ app.controller('HeaderController', function(OSOpenExternalService) {
|
||||
const supportUrl = selectionState.getImageSupportUrl() || DEFAULT_SUPPORT_URL;
|
||||
OSOpenExternalService.open(supportUrl);
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
app.controller('StateController', function ($rootScope, $scope) {
|
||||
@ -335,5 +329,4 @@ app.controller('StateController', function($rootScope, $scope) {
|
||||
* }
|
||||
*/
|
||||
this.currentName = null;
|
||||
|
||||
});
|
||||
|
@ -29,7 +29,6 @@ module.exports = function(
|
||||
$uibModalInstance,
|
||||
WarningModalService
|
||||
) {
|
||||
|
||||
/**
|
||||
* @summary The drive selector state
|
||||
* @type {Object}
|
||||
@ -108,7 +107,6 @@ module.exports = function(
|
||||
* });
|
||||
*/
|
||||
this.toggleDrive = (drive) => {
|
||||
|
||||
analytics.logEvent('Toggle drive', {
|
||||
drive,
|
||||
previouslySelected: selectionState.isCurrentDrive(drive.device)
|
||||
@ -118,7 +116,6 @@ module.exports = function(
|
||||
if (canChangeDriveSelectionState) {
|
||||
selectionState.toggleSetDrive(drive.device);
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
@ -141,7 +138,6 @@ module.exports = function(
|
||||
} else {
|
||||
$uibModalInstance.close(selectedDrive);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@ -208,7 +204,6 @@ module.exports = function(
|
||||
areArgsInTuple = true;
|
||||
|
||||
if (angular.equals(state, oldState)) {
|
||||
|
||||
// Use the previously memoized state for this argument
|
||||
state = oldState;
|
||||
}
|
||||
@ -224,7 +219,6 @@ module.exports = function(
|
||||
// Add the state associated with these args to be memoized
|
||||
if (!areArgsInTuple) {
|
||||
previousTuples.push([ restArgs, state ]);
|
||||
|
||||
}
|
||||
|
||||
return state;
|
||||
@ -257,5 +251,4 @@ module.exports = function(
|
||||
this.getDriveStatuses = this.memoizeImmutableListReference((drive) => {
|
||||
return this.constraints.getDriveImageCompatibilityStatuses(drive, this.state.getImage());
|
||||
});
|
||||
|
||||
};
|
||||
|
@ -17,7 +17,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (ModalService, $q) {
|
||||
|
||||
let modal = null;
|
||||
|
||||
/**
|
||||
@ -55,7 +54,6 @@ module.exports = function(ModalService, $q) {
|
||||
* DriveSelectorService.close();
|
||||
*/
|
||||
this.close = () => {
|
||||
|
||||
if (modal) {
|
||||
return modal.close();
|
||||
}
|
||||
@ -63,7 +61,5 @@ module.exports = function(ModalService, $q) {
|
||||
// Resolve `undefined` if the modal
|
||||
// was already closed for consistency
|
||||
return $q.resolve();
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -21,7 +21,6 @@ const selectionState = require('../../../../shared/models/selection-state');
|
||||
const analytics = require('../../../modules/analytics');
|
||||
|
||||
module.exports = function (WarningModalService) {
|
||||
|
||||
/**
|
||||
* @summary Open the flash error modal
|
||||
* @function
|
||||
@ -47,5 +46,4 @@ module.exports = function(WarningModalService) {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -20,7 +20,6 @@ const _ = require('lodash');
|
||||
const analytics = require('../../../modules/analytics');
|
||||
|
||||
module.exports = function ($uibModal, $q) {
|
||||
|
||||
/**
|
||||
* @summary Open a modal
|
||||
* @function
|
||||
@ -40,7 +39,6 @@ module.exports = function($uibModal, $q) {
|
||||
* });
|
||||
*/
|
||||
this.open = (options = {}) => {
|
||||
|
||||
_.defaults(options, {
|
||||
size: 'sm'
|
||||
});
|
||||
@ -67,7 +65,6 @@ module.exports = function($uibModal, $q) {
|
||||
|
||||
resolve(value);
|
||||
}).catch((error) => {
|
||||
|
||||
// Bootstrap doesn't 'resolve' these but cancels the dialog
|
||||
if (error === 'escape key press' || error === 'backdrop click') {
|
||||
analytics.logEvent('Modal rejected', {
|
||||
@ -86,5 +83,4 @@ module.exports = function($uibModal, $q) {
|
||||
})
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -78,7 +78,6 @@ const API_VERSION = 1;
|
||||
* <safe-webview src="https://etcher.io/"></safe-webview>
|
||||
*/
|
||||
class SafeWebview extends react.PureComponent {
|
||||
|
||||
/**
|
||||
* @param {Object} props - React element properties
|
||||
*/
|
||||
@ -89,7 +88,7 @@ class SafeWebview extends react.PureComponent {
|
||||
shouldShow: true
|
||||
};
|
||||
|
||||
const url = new URL(props.src);
|
||||
const url = new window.URL(props.src);
|
||||
|
||||
// We set the version GET parameters here.
|
||||
url.searchParams.set(ETCHER_VERSION_PARAM, packageJSON.version);
|
||||
@ -134,7 +133,6 @@ class SafeWebview extends react.PureComponent {
|
||||
* @summary Add the Webview events
|
||||
*/
|
||||
componentDidMount () {
|
||||
|
||||
// Events React is unaware of have to be handled manually
|
||||
_.map(this.eventTuples, (tuple) => {
|
||||
this.refs.webview.addEventListener(...tuple);
|
||||
@ -152,7 +150,6 @@ class SafeWebview extends react.PureComponent {
|
||||
* @summary Remove the Webview events
|
||||
*/
|
||||
componentWillUnmount () {
|
||||
|
||||
// Events that React is unaware of have to be handled manually
|
||||
_.map(this.eventTuples, (tuple) => {
|
||||
this.refs.webview.removeEventListener(...tuple);
|
||||
@ -165,13 +162,11 @@ class SafeWebview extends react.PureComponent {
|
||||
*/
|
||||
componentWillReceiveProps (nextProps) {
|
||||
if (nextProps.refreshNow && !this.props.refreshNow) {
|
||||
|
||||
// Reload the page if it hasn't changed, otherwise reset the source URL,
|
||||
// because reload interferes with 'src' setting, resetting the 'src' attribute
|
||||
// to what it was was just prior.
|
||||
if (this.refs.webview.src === this.entryHref) {
|
||||
this.refs.webview.reload();
|
||||
|
||||
} else {
|
||||
this.refs.webview.src = this.entryHref;
|
||||
}
|
||||
@ -209,7 +204,7 @@ class SafeWebview extends react.PureComponent {
|
||||
* @param {Event} event - event object
|
||||
*/
|
||||
static newWindow (event) {
|
||||
const url = new URL(event.url);
|
||||
const url = new window.URL(event.url);
|
||||
|
||||
if (_.every([
|
||||
url.protocol === 'http:' || url.protocol === 'https:',
|
||||
@ -245,12 +240,10 @@ class SafeWebview extends react.PureComponent {
|
||||
|
||||
if (robot.getCommand(message) === robot.COMMAND.LOG) {
|
||||
analytics.logEvent(robot.getData(message));
|
||||
|
||||
} else if (robot.getCommand(message) === robot.COMMAND.ERROR) {
|
||||
analytics.logException(robot.getData(message));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SafeWebview.propTypes = {
|
||||
|
@ -41,13 +41,11 @@ const DEFAULT_SIZE = '40px';
|
||||
* @public
|
||||
*/
|
||||
class SVGIcon extends react.Component {
|
||||
|
||||
/**
|
||||
* @summary Render the SVG
|
||||
* @returns {react.Element}
|
||||
*/
|
||||
render () {
|
||||
|
||||
// This means the path to the icon should be
|
||||
// relative to *this directory*.
|
||||
// TODO: There might be a way to compute the path
|
||||
@ -58,7 +56,6 @@ class SVGIcon extends react.Component {
|
||||
|
||||
if (_.startsWith(this.props.path, '<')) {
|
||||
contents = this.props.path;
|
||||
|
||||
} else {
|
||||
contents = fs.readFileSync(imagePath, {
|
||||
encoding: 'utf8'
|
||||
@ -68,7 +65,7 @@ class SVGIcon extends react.Component {
|
||||
const width = this.props.width || 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 svg = doc.querySelector('svg');
|
||||
|
||||
@ -95,11 +92,9 @@ class SVGIcon extends react.Component {
|
||||
* @param {Object} nextProps - the new properties
|
||||
*/
|
||||
componentWillReceiveProps (nextProps) {
|
||||
|
||||
// This will update the element if the properties change
|
||||
this.setState(nextProps);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SVGIcon.propTypes = {
|
||||
|
@ -17,7 +17,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function ($uibModalInstance, tooltipData) {
|
||||
|
||||
/**
|
||||
* @summary Tooltip data
|
||||
* @type {Object}
|
||||
@ -36,5 +35,4 @@ module.exports = function($uibModalInstance, tooltipData) {
|
||||
this.closeModal = () => {
|
||||
$uibModalInstance.dismiss();
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -19,7 +19,6 @@
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = function (ModalService) {
|
||||
|
||||
/**
|
||||
* @summary Open the tooltip modal
|
||||
* @function
|
||||
@ -46,5 +45,4 @@ module.exports = function(ModalService) {
|
||||
}
|
||||
}).result;
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -125,7 +125,6 @@ exports.notify = (version, options = {}) => {
|
||||
});
|
||||
});
|
||||
}).tap((results) => {
|
||||
|
||||
// Only update the last slept update timestamp if the
|
||||
// user ticked the "Remind me again in ..." checkbox,
|
||||
// but didn't agree.
|
||||
|
@ -17,7 +17,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function ($uibModalInstance, options) {
|
||||
|
||||
/**
|
||||
* @summary Modal options
|
||||
* @type {Object}
|
||||
@ -48,5 +47,4 @@ module.exports = function($uibModalInstance, options) {
|
||||
this.accept = () => {
|
||||
$uibModalInstance.close(true);
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -19,7 +19,6 @@
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = function ($sce, ModalService) {
|
||||
|
||||
/**
|
||||
* @summary Display the warning modal
|
||||
* @function
|
||||
@ -49,5 +48,4 @@ module.exports = function($sce, ModalService) {
|
||||
}
|
||||
}).result;
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -39,7 +39,6 @@ electron.app.on('before-quit', () => {
|
||||
});
|
||||
|
||||
electron.app.on('ready', () => {
|
||||
|
||||
// No menu bar
|
||||
electron.Menu.setApplicationMenu(null);
|
||||
|
||||
@ -83,7 +82,6 @@ electron.app.on('ready', () => {
|
||||
// See: https://github.com/electron/electron/issues/8841
|
||||
electron.globalShortcut.register('CmdOrCtrl+R', _.noop);
|
||||
electron.globalShortcut.register('F5', _.noop);
|
||||
|
||||
});
|
||||
|
||||
mainWindow.on('blur', () => {
|
||||
@ -109,4 +107,3 @@ electron.app.on('ready', () => {
|
||||
|
||||
mainWindow.loadURL(`file://${path.join(__dirname, 'index.html')}`);
|
||||
});
|
||||
|
||||
|
@ -40,7 +40,7 @@ const LOCAL_STORAGE_SETTINGS_KEY = 'etcher-settings';
|
||||
*/
|
||||
exports.readAll = () => {
|
||||
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) => {
|
||||
const INDENTATION_SPACES = 2;
|
||||
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 = () => {
|
||||
return Bluebird.try(() => {
|
||||
localStorage.removeItem(LOCAL_STORAGE_SETTINGS_KEY);
|
||||
window.localStorage.removeItem(LOCAL_STORAGE_SETTINGS_KEY);
|
||||
});
|
||||
};
|
||||
|
@ -56,7 +56,6 @@ const setSettingsObject = (settings) => {
|
||||
data: settings
|
||||
});
|
||||
}).then(() => {
|
||||
|
||||
// Revert the application state if writing the data
|
||||
// to the local machine was not successful
|
||||
return localSettings.writeAll(settings).catch((error) => {
|
||||
@ -67,7 +66,6 @@ const setSettingsObject = (settings) => {
|
||||
|
||||
throw error;
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -33,7 +33,6 @@ const MODULE_NAME = 'Etcher.Modules.ImageWriter';
|
||||
const imageWriter = angular.module(MODULE_NAME, []);
|
||||
|
||||
imageWriter.service('ImageWriterService', function ($q, $rootScope) {
|
||||
|
||||
/**
|
||||
* @summary Perform write operation
|
||||
* @function
|
||||
@ -105,7 +104,6 @@ imageWriter.service('ImageWriterService', function($q, $rootScope) {
|
||||
analytics.logEvent('Flash', analyticsData);
|
||||
|
||||
return this.performWrite(image, drive, (state) => {
|
||||
|
||||
// Bring this value to the world of angular.
|
||||
// If we don't trigger a digest loop,
|
||||
// `.getFlashState()` will not return
|
||||
@ -113,7 +111,6 @@ imageWriter.service('ImageWriterService', function($q, $rootScope) {
|
||||
$rootScope.$apply(() => {
|
||||
flashState.setProgressState(state);
|
||||
});
|
||||
|
||||
}).then(flashState.unsetFlashingFlag).then(() => {
|
||||
if (flashState.wasLastFlashCancelled()) {
|
||||
analytics.logEvent('Elevation cancelled', analyticsData);
|
||||
@ -144,7 +141,6 @@ imageWriter.service('ImageWriterService', function($q, $rootScope) {
|
||||
windowProgress.clear();
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
module.exports = MODULE_NAME;
|
||||
|
@ -68,12 +68,10 @@ exports.selectImage = () => {
|
||||
}
|
||||
]
|
||||
}, (files) => {
|
||||
|
||||
// `_.first` is smart enough to not throw and return `undefined`
|
||||
// if we pass it an `undefined` value (e.g: when the selection
|
||||
// dialog was cancelled).
|
||||
return resolve(_.first(files));
|
||||
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -41,11 +41,10 @@ const electron = require('electron');
|
||||
* });
|
||||
*/
|
||||
exports.send = (title, options) => {
|
||||
|
||||
// `app.dock` is only defined in OS X
|
||||
if (electron.remote.app.dock) {
|
||||
electron.remote.app.dock.bounce();
|
||||
}
|
||||
|
||||
return new Notification(title, options);
|
||||
return new window.Notification(title, options);
|
||||
};
|
||||
|
@ -36,7 +36,6 @@ module.exports = (OSOpenExternalService) => {
|
||||
restrict: 'A',
|
||||
scope: false,
|
||||
link: (scope, element, attributes) => {
|
||||
|
||||
// This directive might be added to elements
|
||||
// other than buttons.
|
||||
element.css('cursor', 'pointer');
|
||||
|
@ -32,9 +32,10 @@ OSOpenExternal.run((OSOpenExternalService) => {
|
||||
document.addEventListener('click', (event) => {
|
||||
const target = event.target;
|
||||
if (target.tagName === 'A' && angular.isDefined(target.href)) {
|
||||
|
||||
// Electron interprets relative URLs as being relative to the 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.
|
||||
// Electron interprets relative URLs as being relative to the
|
||||
// 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.
|
||||
if (url.parse(target.href).protocol !== 'file:') {
|
||||
OSOpenExternalService.open(target.href);
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ const electron = require('electron');
|
||||
const analytics = require('../../../modules/analytics');
|
||||
|
||||
module.exports = function () {
|
||||
|
||||
/**
|
||||
* @summary Open an external resource
|
||||
* @function
|
||||
@ -40,5 +39,4 @@ module.exports = function() {
|
||||
electron.shell.openExternal(url);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -55,7 +55,6 @@ exports.set = (percentage) => {
|
||||
* windowProgress.clear();
|
||||
*/
|
||||
exports.clear = () => {
|
||||
|
||||
// Passing 0 or null/undefined doesn't work.
|
||||
const ELECTRON_PROGRESS_BAR_RESET_VALUE = -1;
|
||||
|
||||
|
@ -22,7 +22,6 @@ const selectionState = require('../../../../shared/models/selection-state');
|
||||
const analytics = require('../../../modules/analytics');
|
||||
|
||||
module.exports = function ($state) {
|
||||
|
||||
/**
|
||||
* @summary Settings model
|
||||
* @type {Object}
|
||||
@ -53,5 +52,4 @@ module.exports = function($state) {
|
||||
analytics.logEvent('Restart', options);
|
||||
$state.go('main');
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -22,7 +22,6 @@ const analytics = require('../../../modules/analytics');
|
||||
const exceptionReporter = require('../../../modules/exception-reporter');
|
||||
|
||||
module.exports = function (DriveSelectorService) {
|
||||
|
||||
/**
|
||||
* @summary Open drive selector
|
||||
* @function
|
||||
@ -58,5 +57,4 @@ module.exports = function(DriveSelectorService) {
|
||||
this.openDriveSelector();
|
||||
analytics.logEvent('Reselect drive');
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -30,7 +30,6 @@ module.exports = function(
|
||||
ImageWriterService,
|
||||
FlashErrorModalService
|
||||
) {
|
||||
|
||||
/**
|
||||
* @summary Flash image to a drive
|
||||
* @function
|
||||
@ -98,9 +97,7 @@ module.exports = function(
|
||||
FlashErrorModalService.show(messages.error.genericFlashError());
|
||||
exceptionReporter.report(error);
|
||||
}
|
||||
|
||||
})
|
||||
.finally(() => {
|
||||
}).finally(() => {
|
||||
driveScanner.start();
|
||||
});
|
||||
};
|
||||
@ -135,5 +132,4 @@ module.exports = function(
|
||||
|
||||
return `${currentFlashState.percentage}%`;
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -32,7 +32,6 @@ module.exports = function(
|
||||
$timeout,
|
||||
WarningModalService
|
||||
) {
|
||||
|
||||
/**
|
||||
* @summary Main supported extensions
|
||||
* @constant
|
||||
@ -103,9 +102,7 @@ module.exports = function(
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}).then((shouldChange) => {
|
||||
|
||||
if (shouldChange) {
|
||||
return this.reselectImage();
|
||||
}
|
||||
@ -164,7 +161,6 @@ module.exports = function(
|
||||
analytics.logEvent('Open image selector');
|
||||
|
||||
osDialog.selectImage().then((imagePath) => {
|
||||
|
||||
// Avoid analytics and selection state changes
|
||||
// if no file was resolved from the dialog.
|
||||
if (!imagePath) {
|
||||
@ -209,5 +205,4 @@ module.exports = function(
|
||||
|
||||
return path.basename(selectionState.getImagePath());
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -27,7 +27,6 @@ module.exports = function(
|
||||
TooltipModalService,
|
||||
OSOpenExternalService
|
||||
) {
|
||||
|
||||
// Expose several modules to the template for convenience
|
||||
this.selection = selectionState;
|
||||
this.drives = availableDrives;
|
||||
@ -87,5 +86,4 @@ module.exports = function(
|
||||
message: selectionState.getImagePath()
|
||||
}).catch(exceptionReporter.report);
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -23,7 +23,6 @@ const analytics = require('../../../modules/analytics');
|
||||
const exceptionReporter = require('../../../modules/exception-reporter');
|
||||
|
||||
module.exports = function (WarningModalService) {
|
||||
|
||||
/**
|
||||
* @summary Client platform
|
||||
* @type {String}
|
||||
@ -82,7 +81,6 @@ module.exports = function(WarningModalService) {
|
||||
* });
|
||||
*/
|
||||
this.toggle = (setting, options) => {
|
||||
|
||||
const value = this.currentData[setting];
|
||||
const dangerous = !_.isUndefined(options);
|
||||
|
||||
@ -106,5 +104,4 @@ module.exports = function(WarningModalService) {
|
||||
}
|
||||
}).catch(exceptionReporter.report);
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -19,7 +19,6 @@
|
||||
const units = require('../../../shared/units');
|
||||
|
||||
module.exports = () => {
|
||||
|
||||
/**
|
||||
* @summary Convert bytes to the closest unit
|
||||
* @function
|
||||
@ -32,5 +31,4 @@ module.exports = () => {
|
||||
* {{ 7801405440 | closestUnit }}
|
||||
*/
|
||||
return units.bytesToClosestUnit;
|
||||
|
||||
};
|
||||
|
@ -20,7 +20,6 @@ const _ = require('lodash');
|
||||
const packageJSON = require('../../../../../package.json');
|
||||
|
||||
module.exports = function () {
|
||||
|
||||
/**
|
||||
* @summary Get a package.json property
|
||||
* @function
|
||||
@ -35,5 +34,4 @@ module.exports = function() {
|
||||
this.get = (attribute) => {
|
||||
return _.get(packageJSON, attribute);
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -172,7 +172,6 @@ const extractArchiveMetadata = (archive, basePath, options) => {
|
||||
*/
|
||||
exports.extractImage = (archive, hooks) => {
|
||||
return hooks.getEntries(archive).then((entries) => {
|
||||
|
||||
const imageEntries = _.filter(entries, (entry) => {
|
||||
return _.includes(IMAGE_EXTENSIONS, fileExtensions.getLastFileExtension(entry.name));
|
||||
});
|
||||
|
@ -186,9 +186,9 @@ module.exports = {
|
||||
if (/invalid footer/i.test(error.message)) {
|
||||
throw errors.createUserError({
|
||||
title: 'Invalid image',
|
||||
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'
|
||||
+ `Error: ${error.description || error.message}`
|
||||
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' +
|
||||
`Error: ${error.description || error.message}`
|
||||
});
|
||||
}
|
||||
throw error;
|
||||
|
@ -66,7 +66,6 @@ const MAX_BLOCK_SIZE = 4096;
|
||||
* }
|
||||
*/
|
||||
const detectGPT = (buffer) => {
|
||||
|
||||
let blockSize = INITIAL_BLOCK_SIZE;
|
||||
let gpt = null;
|
||||
|
||||
@ -83,7 +82,6 @@ const detectGPT = (buffer) => {
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@ -102,7 +100,6 @@ const detectGPT = (buffer) => {
|
||||
* }
|
||||
*/
|
||||
const parsePartitionTables = (image, buffer) => {
|
||||
|
||||
const mbr = _.attempt(MBR.parse, buffer);
|
||||
let gpt = null;
|
||||
|
||||
@ -138,7 +135,6 @@ const parsePartitionTables = (image, buffer) => {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@ -163,7 +159,6 @@ const parsePartitionTables = (image, buffer) => {
|
||||
*/
|
||||
module.exports = (image) => {
|
||||
return new Bluebird((resolve, reject) => {
|
||||
|
||||
const chunks = [];
|
||||
let length = INITIAL_LENGTH;
|
||||
let destroyed = false;
|
||||
@ -184,7 +179,6 @@ module.exports = (image) => {
|
||||
|
||||
// Once we've read enough bytes, terminate the stream
|
||||
if (length >= MAX_STREAM_BYTES && !destroyed) {
|
||||
|
||||
// Prefer close() over destroy(), as some streams
|
||||
// from dependencies exhibit quirky behavior when destroyed
|
||||
if (image.stream.close) {
|
||||
@ -202,10 +196,7 @@ module.exports = (image) => {
|
||||
// Parse the MBR, GPT and partitions from the obtained buffer
|
||||
parsePartitionTables(image, Buffer.concat(chunks));
|
||||
resolve(image);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
};
|
||||
|
@ -145,7 +145,6 @@ exports.isDriveLargeEnough = (drive, image) => {
|
||||
const driveSize = _.get(drive, [ 'size' ], UNKNOWN_SIZE);
|
||||
|
||||
if (_.get(image, [ 'size', 'final', 'estimation' ])) {
|
||||
|
||||
// If the drive size is smaller than the original image size, and
|
||||
// the final image size is just an estimation, then we stop right
|
||||
// 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
|
||||
// at all, when the estimation may be wrong.
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return driveSize >= _.get(image, [
|
||||
@ -349,21 +347,17 @@ exports.getDriveImageCompatibilityStatuses = (drive, image) => {
|
||||
type: exports.COMPATIBILITY_STATUS_TYPES.ERROR,
|
||||
message: exports.COMPATIBILITY_STATUS_MESSAGES.CONTAINS_IMAGE
|
||||
});
|
||||
|
||||
} else if (exports.isDriveLocked(drive)) {
|
||||
statusList.push({
|
||||
type: exports.COMPATIBILITY_STATUS_TYPES.ERROR,
|
||||
message: exports.COMPATIBILITY_STATUS_MESSAGES.LOCKED
|
||||
});
|
||||
|
||||
} else if (!_.isNil(drive) && !exports.isDriveLargeEnough(drive, image)) {
|
||||
statusList.push({
|
||||
type: exports.COMPATIBILITY_STATUS_TYPES.ERROR,
|
||||
message: exports.COMPATIBILITY_STATUS_MESSAGES.TOO_SMALL
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
if (exports.isSystemDrive(drive)) {
|
||||
statusList.push({
|
||||
type: exports.COMPATIBILITY_STATUS_TYPES.WARNING,
|
||||
|
@ -326,7 +326,6 @@ exports.isUserError = (error) => {
|
||||
* > 'foo'
|
||||
*/
|
||||
exports.toJSON = (error) => {
|
||||
|
||||
// Handle string error objects to be on the safe side
|
||||
const isErrorLike = _.isError(error) || _.isPlainObject(error);
|
||||
const errorObject = isErrorLike ? error : new Error(error);
|
||||
|
@ -123,11 +123,9 @@ exports.setProgressState = (state) => {
|
||||
|
||||
speed: _.attempt(() => {
|
||||
if (_.isNumber(state.speed) && !_.isNaN(state.speed)) {
|
||||
|
||||
// Preserve only two decimal places
|
||||
const PRECISION = 2;
|
||||
return _.round(units.bytesToMegabytes(state.speed), PRECISION);
|
||||
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@ -57,7 +57,6 @@ const UNIX_SUPERUSER_USER_ID = 0;
|
||||
*/
|
||||
exports.isElevated = () => {
|
||||
if (os.platform() === 'win32') {
|
||||
|
||||
// `fltmc` is available on WinPE, XP, Vista, 7, 8, and 10
|
||||
// Works even when the "Server" service is disabled
|
||||
// See http://stackoverflow.com/a/28268802
|
||||
@ -66,7 +65,6 @@ exports.isElevated = () => {
|
||||
.catch({
|
||||
code: os.constants.errno.EPERM
|
||||
}, _.constant(false));
|
||||
|
||||
}
|
||||
|
||||
return Bluebird.resolve(process.geteuid() === UNIX_SUPERUSER_USER_ID);
|
||||
@ -108,11 +106,9 @@ exports.getEnvironmentCommandPrefix = (environment) => {
|
||||
});
|
||||
|
||||
if (isWindows) {
|
||||
|
||||
// This is a trick to make the binary afterwards catch
|
||||
// the environment variables set just previously.
|
||||
return _.concat(argv, [ 'call' ]);
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
// for now, we should make sure we double check if the error messages
|
||||
// have changed every time we upgrade `sudo-prompt`.
|
||||
|
||||
}).catch((error) => {
|
||||
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'
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
|
@ -187,7 +187,6 @@ exports.getRemoteVersions = _.memoize((bucketUrl) => {
|
||||
* }
|
||||
*/
|
||||
const semverSatisfies = (version, range) => {
|
||||
|
||||
// The `semver` module refuses to apply ranges to prerelease versions
|
||||
// As a workaround, we drop the prerelease tags, if any, apply the range
|
||||
// on that, and keep using the prerelease tag from then on.
|
||||
@ -218,7 +217,6 @@ const semverSatisfies = (version, range) => {
|
||||
* });
|
||||
*/
|
||||
exports.getLatestVersion = (releaseType, options = {}) => {
|
||||
|
||||
// For manual testing purposes
|
||||
const ETCHER_FAKE_S3_LATEST_VERSION = process.env.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 */
|
||||
|
||||
return exports.getRemoteVersions(bucketUrl).filter((version) => {
|
||||
|
||||
/* eslint-enable lodash/prefer-lodash-method */
|
||||
|
||||
if (_.some([
|
||||
|
||||
// This check allows us to ignore snapshot builds in production
|
||||
|
@ -88,7 +88,6 @@ const ACTIONS = _.fromPairs(_.map([
|
||||
* const drive = findDrive(state, '/dev/disk2');
|
||||
*/
|
||||
const findDrive = (state, device) => {
|
||||
|
||||
/* eslint-disable lodash/prefer-lodash-method */
|
||||
|
||||
return state.get('availableDrives').find((drive) => {
|
||||
@ -96,7 +95,6 @@ const findDrive = (state, device) => {
|
||||
});
|
||||
|
||||
/* eslint-enable lodash/prefer-lodash-method */
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@ -115,7 +113,6 @@ const findDrive = (state, device) => {
|
||||
*/
|
||||
const storeReducer = (state = DEFAULT_STATE, action) => {
|
||||
switch (action.type) {
|
||||
|
||||
case ACTIONS.SET_AVAILABLE_DRIVES: {
|
||||
if (!action.data) {
|
||||
throw errors.createError({
|
||||
@ -134,7 +131,6 @@ const storeReducer = (state = DEFAULT_STATE, action) => {
|
||||
const AUTOSELECT_DRIVE_COUNT = 1;
|
||||
const numberOfDrives = action.data.length;
|
||||
if (numberOfDrives === AUTOSELECT_DRIVE_COUNT) {
|
||||
|
||||
const drive = _.first(action.data);
|
||||
|
||||
// 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
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const selectedDevice = newState.getIn([ 'selection', 'drive' ]);
|
||||
@ -482,7 +477,6 @@ const storeReducer = (state = DEFAULT_STATE, action) => {
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -32,7 +32,6 @@ process.env.DEBUG = '*';
|
||||
// using `child_process.fork()`.
|
||||
if (process.env.ELECTRON_RUN_AS_NODE || process.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE) {
|
||||
require('./cli/etcher');
|
||||
|
||||
} else {
|
||||
require('./gui/etcher');
|
||||
}
|
||||
|
@ -42,4 +42,3 @@ _.each([
|
||||
const filename = path.join(currentDirectory, `Dockerfile-${options.architecture}`);
|
||||
fs.writeFileSync(filename, result);
|
||||
});
|
||||
|
||||
|
@ -113,11 +113,9 @@ const getShrinkwrapDependencyManifest = (shrinkwrapPath) => {
|
||||
.value();
|
||||
|
||||
try {
|
||||
|
||||
// For example
|
||||
// ./node_modules/drivelist/node_modules/lodash/package.json
|
||||
return require(`.${path.sep}${manifestPath}`);
|
||||
|
||||
} catch (error) {
|
||||
if (error.code === 'MODULE_NOT_FOUND') {
|
||||
return null;
|
||||
|
@ -47,7 +47,6 @@ angularValidate.validate(
|
||||
}
|
||||
).then((result) => {
|
||||
_.each(result.failed, (failure) => {
|
||||
|
||||
// The module has a typo in the "numbers" property
|
||||
console.error(chalk.red(`${failure.numerrs} errors at ${path.relative(PROJECT_ROOT, failure.filepath)}`));
|
||||
|
||||
@ -77,9 +76,7 @@ angularValidate.validate(
|
||||
setTimeout(() => {
|
||||
process.exit(EXIT_CODES.GENERAL_ERROR);
|
||||
}, EXIT_TIMEOUT_MS);
|
||||
|
||||
}
|
||||
|
||||
}, (error) => {
|
||||
console.error(error);
|
||||
process.exit(EXIT_CODES.GENERAL_ERROR);
|
||||
|
@ -20,9 +20,7 @@ const m = require('mochainon');
|
||||
const cli = require('../../lib/child-writer/cli');
|
||||
|
||||
describe('ChildWriter CLI', function () {
|
||||
|
||||
describe('.getBooleanArgumentForm()', 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');
|
||||
});
|
||||
@ -38,11 +36,9 @@ describe('ChildWriter CLI', function() {
|
||||
it('should prepend - if the value is true and option is short', function () {
|
||||
m.chai.expect(cli.getBooleanArgumentForm('x', true)).to.equal('-x');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getArguments()', function () {
|
||||
|
||||
it('should return a list of arguments given validate = false, unmount = false', function () {
|
||||
m.chai.expect(cli.getArguments({
|
||||
image: 'path/to/image.img',
|
||||
@ -110,7 +106,5 @@ describe('ChildWriter CLI', function() {
|
||||
'--check'
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -20,9 +20,7 @@ const m = require('mochainon');
|
||||
const utils = require('../../lib/child-writer/utils');
|
||||
|
||||
describe('ChildWriter Utils', function () {
|
||||
|
||||
describe('.splitObjectLines()', function () {
|
||||
|
||||
it('should split multiple object lines', function () {
|
||||
const input = '{"id":"foo"}\n{"id":"bar"}\n{"id":"baz"}';
|
||||
m.chai.expect(utils.splitObjectLines(input)).to.deep.equal([
|
||||
@ -75,7 +73,5 @@ describe('ChildWriter Utils', function() {
|
||||
'{"id":"baz"}'
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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';
|
||||
|
||||
const _ = require('lodash');
|
||||
@ -6,13 +22,11 @@ const angular = require('angular');
|
||||
require('angular-mocks');
|
||||
|
||||
describe('Browser: DriveSelector', function () {
|
||||
|
||||
beforeEach(angular.mock.module(
|
||||
require('../../../lib/gui/components/drive-selector/drive-selector')
|
||||
));
|
||||
|
||||
describe('DriveSelectorController', function () {
|
||||
|
||||
let $controller;
|
||||
let $rootScope;
|
||||
let $q;
|
||||
@ -44,7 +58,6 @@ describe('Browser: DriveSelector', function() {
|
||||
});
|
||||
|
||||
describe('.memoizeImmutableListReference()', function () {
|
||||
|
||||
it('constant true should return memoized true', function () {
|
||||
const memoizedConstTrue = controller.memoizeImmutableListReference(_.constant(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(angularObjectB)).to.equal(angularObjectA);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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';
|
||||
|
||||
const m = require('mochainon');
|
||||
@ -8,20 +24,17 @@ const angular = require('angular');
|
||||
require('angular-mocks');
|
||||
|
||||
describe('Browser: SVGIcon', function () {
|
||||
|
||||
beforeEach(angular.mock.module(
|
||||
require('../../../lib/gui/components/svg-icon')
|
||||
));
|
||||
|
||||
describe('svgIcon', function () {
|
||||
|
||||
let $compile;
|
||||
let $rootScope;
|
||||
|
||||
beforeEach(angular.mock.inject(function (_$compile_, _$rootScope_) {
|
||||
$compile = _$compile_;
|
||||
$rootScope = _$rootScope_;
|
||||
|
||||
}));
|
||||
|
||||
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('height')).to.equal('20px');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -22,9 +22,7 @@ const units = require('../../../lib/shared/units');
|
||||
const updateNotifier = require('../../../lib/gui/components/update-notifier');
|
||||
|
||||
describe('Browser: updateNotifier', function () {
|
||||
|
||||
describe('.UPDATE_NOTIFIER_SLEEP_DAYS', function () {
|
||||
|
||||
it('should be an integer', function () {
|
||||
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 () {
|
||||
m.chai.expect(updateNotifier.UPDATE_NOTIFIER_SLEEP_DAYS > 0).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.shouldCheckForUpdates()', function () {
|
||||
|
||||
const UPDATE_NOTIFIER_SLEEP_MS = units.daysToMilliseconds(updateNotifier.UPDATE_NOTIFIER_SLEEP_DAYS);
|
||||
|
||||
_.each([
|
||||
@ -441,7 +437,6 @@ describe('Browser: updateNotifier', function() {
|
||||
}
|
||||
|
||||
], (testCase) => {
|
||||
|
||||
it(_.join([
|
||||
`should return ${testCase.expected} if`,
|
||||
`lastSleptUpdateNotifier=${testCase.options.lastSleptUpdateNotifier},`,
|
||||
@ -450,9 +445,6 @@ describe('Browser: updateNotifier', function() {
|
||||
], ' '), function () {
|
||||
m.chai.expect(updateNotifier.shouldCheckForUpdates(testCase.options)).to.equal(testCase.expected);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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';
|
||||
|
||||
const m = require('mochainon');
|
||||
@ -8,7 +24,6 @@ const settings = require('../../../lib/gui/models/settings');
|
||||
const localSettings = require('../../../lib/gui/models/local-settings');
|
||||
|
||||
describe('Browser: settings', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
return settings.reset();
|
||||
});
|
||||
@ -26,7 +41,6 @@ describe('Browser: settings', function() {
|
||||
});
|
||||
|
||||
describe('.reset()', function () {
|
||||
|
||||
it('should reset the settings to their default values', function () {
|
||||
m.chai.expect(settings.getAll()).to.deep.equal(DEFAULT_SETTINGS);
|
||||
return settings.set('foo', 1234).then(() => {
|
||||
@ -47,7 +61,6 @@ describe('Browser: settings', function() {
|
||||
});
|
||||
|
||||
describe('given the local settings are cleared', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
return localSettings.clear();
|
||||
});
|
||||
@ -57,13 +70,10 @@ describe('Browser: settings', function() {
|
||||
m.chai.expect(data).to.deep.equal(DEFAULT_SETTINGS);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.assign()', function () {
|
||||
|
||||
it('should throw if no settings', function (done) {
|
||||
settings.assign().asCallback((error) => {
|
||||
m.chai.expect(error).to.be.an.instanceof(Error);
|
||||
@ -146,11 +156,9 @@ describe('Browser: settings', function() {
|
||||
});
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.load()', function () {
|
||||
|
||||
it('should extend the application state with the local settings content', function () {
|
||||
const object = {
|
||||
foo: 'bar'
|
||||
@ -172,11 +180,9 @@ describe('Browser: settings', function() {
|
||||
m.chai.expect(settings.getAll()).to.deep.equal(DEFAULT_SETTINGS);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.set()', function () {
|
||||
|
||||
it('should set an unknown key', function () {
|
||||
m.chai.expect(settings.get('foobar')).to.be.undefined;
|
||||
return settings.set('foobar', true).then(() => {
|
||||
@ -268,15 +274,11 @@ describe('Browser: settings', function() {
|
||||
});
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getAll()', function () {
|
||||
|
||||
it('should initial return all default values', function () {
|
||||
m.chai.expect(settings.getAll()).to.deep.equal(DEFAULT_SETTINGS);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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';
|
||||
|
||||
const m = require('mochainon');
|
||||
@ -6,9 +22,7 @@ const drivelist = require('drivelist');
|
||||
const driveScanner = require('../../../lib/gui/modules/drive-scanner');
|
||||
|
||||
describe('Browser: driveScanner', function () {
|
||||
|
||||
describe('given no available drives', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.drivelistStub = m.sinon.stub(drivelist, 'list');
|
||||
this.drivelistStub.yields(null, []);
|
||||
@ -27,11 +41,9 @@ describe('Browser: driveScanner', function() {
|
||||
|
||||
driveScanner.start();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given only system available drives', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.drivelistStub = m.sinon.stub(drivelist, 'list');
|
||||
this.drivelistStub.yields(null, [ {
|
||||
@ -60,11 +72,9 @@ describe('Browser: driveScanner', function() {
|
||||
|
||||
driveScanner.start();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given linux', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.osPlatformStub = m.sinon.stub(os, 'platform');
|
||||
this.osPlatformStub.returns('linux');
|
||||
@ -75,7 +85,6 @@ describe('Browser: driveScanner', function() {
|
||||
});
|
||||
|
||||
describe('given available drives', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.drivelistStub = m.sinon.stub(drivelist, 'list');
|
||||
this.drivelistStub.yields(null, [
|
||||
@ -157,13 +166,10 @@ describe('Browser: driveScanner', function() {
|
||||
|
||||
driveScanner.start();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given windows', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.osPlatformStub = m.sinon.stub(os, 'platform');
|
||||
this.osPlatformStub.returns('win32');
|
||||
@ -174,7 +180,6 @@ describe('Browser: driveScanner', function() {
|
||||
});
|
||||
|
||||
describe('given available drives', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.drivelistStub = m.sinon.stub(drivelist, 'list');
|
||||
this.drivelistStub.yields(null, [
|
||||
@ -248,11 +253,9 @@ describe('Browser: driveScanner', function() {
|
||||
|
||||
driveScanner.start();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a drive with a single drive letters', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.drivelistStub = m.sinon.stub(drivelist, 'list');
|
||||
this.drivelistStub.yields(null, [
|
||||
@ -285,11 +288,9 @@ describe('Browser: driveScanner', function() {
|
||||
|
||||
driveScanner.start();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a drive with multiple drive letters', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.drivesListStub = m.sinon.stub(drivelist, 'list');
|
||||
this.drivesListStub.yields(null, [
|
||||
@ -328,13 +329,10 @@ describe('Browser: driveScanner', function() {
|
||||
|
||||
driveScanner.start();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given an error when listing the drives', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.drivesListStub = m.sinon.stub(drivelist, 'list');
|
||||
this.drivesListStub.yields(new Error('scan error'));
|
||||
@ -354,7 +352,5 @@ describe('Browser: driveScanner', function() {
|
||||
|
||||
driveScanner.start();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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';
|
||||
|
||||
const m = require('mochainon');
|
||||
@ -6,13 +22,11 @@ const flashState = require('../../../lib/shared/models/flash-state');
|
||||
require('angular-mocks');
|
||||
|
||||
describe('Browser: ImageWriter', function () {
|
||||
|
||||
beforeEach(angular.mock.module(
|
||||
require('../../../lib/gui/modules/image-writer')
|
||||
));
|
||||
|
||||
describe('ImageWriterService', function () {
|
||||
|
||||
let $q;
|
||||
let $rootScope;
|
||||
let ImageWriterService;
|
||||
@ -24,9 +38,7 @@ describe('Browser: ImageWriter', function() {
|
||||
}));
|
||||
|
||||
describe('.flash()', function () {
|
||||
|
||||
describe('given a successful write', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.performWriteStub = m.sinon.stub(ImageWriterService, 'performWrite');
|
||||
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.message).to.equal('There is already a flash in progress');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given an unsuccessful write', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.performWriteStub = m.sinon.stub(ImageWriterService, 'performWrite');
|
||||
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.message).to.equal('write error');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -21,13 +21,11 @@ const angular = require('angular');
|
||||
require('angular-mocks');
|
||||
|
||||
describe('Browser: OSDropzone', function () {
|
||||
|
||||
beforeEach(angular.mock.module(
|
||||
require('../../../lib/gui/os/dropzone/dropzone')
|
||||
));
|
||||
|
||||
describe('osDropzone', function () {
|
||||
|
||||
let $compile;
|
||||
let $rootScope;
|
||||
let $timeout;
|
||||
@ -85,7 +83,5 @@ describe('Browser: OSDropzone', function() {
|
||||
$rootScope.$digest();
|
||||
$timeout.flush();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -22,13 +22,11 @@ const electron = require('electron');
|
||||
require('angular-mocks');
|
||||
|
||||
describe('Browser: OSOpenExternal', function () {
|
||||
|
||||
beforeEach(angular.mock.module(
|
||||
require('../../../lib/gui/os/open-external/open-external')
|
||||
));
|
||||
|
||||
describe('osOpenExternal', function () {
|
||||
|
||||
let $compile;
|
||||
let $rootScope;
|
||||
|
||||
@ -60,7 +58,5 @@ describe('Browser: OSOpenExternal', function() {
|
||||
m.chai.expect(shellExternalStub).to.not.have.been.called;
|
||||
shellExternalStub.restore();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -20,11 +20,8 @@ const m = require('mochainon');
|
||||
const windowProgress = require('../../../lib/gui/os/window-progress');
|
||||
|
||||
describe('Browser: WindowProgress', function () {
|
||||
|
||||
describe('windowProgress', function () {
|
||||
|
||||
describe('given a stubbed current window', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.setProgressBarSpy = m.sinon.spy();
|
||||
|
||||
@ -34,7 +31,6 @@ describe('Browser: WindowProgress', function() {
|
||||
});
|
||||
|
||||
describe('.set()', function () {
|
||||
|
||||
it('should translate 0-100 percentages to 0-1 ranges', function () {
|
||||
windowProgress.set(85);
|
||||
m.chai.expect(this.setProgressBarSpy).to.have.been.calledWith(0.85);
|
||||
@ -61,20 +57,14 @@ describe('Browser: WindowProgress', function() {
|
||||
windowProgress.set(-1);
|
||||
}).to.throw('Invalid percentage: -1');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.clear()', function () {
|
||||
|
||||
it('should set -1', function () {
|
||||
windowProgress.clear();
|
||||
m.chai.expect(this.setProgressBarSpy).to.have.been.calledWith(-1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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';
|
||||
|
||||
const m = require('mochainon');
|
||||
@ -12,13 +28,11 @@ const selectionState = require('../../../lib/shared/models/selection-state');
|
||||
require('angular-mocks');
|
||||
|
||||
describe('Browser: MainPage', function () {
|
||||
|
||||
beforeEach(angular.mock.module(
|
||||
require('../../../lib/gui/pages/main/main')
|
||||
));
|
||||
|
||||
describe('MainController', function () {
|
||||
|
||||
let $controller;
|
||||
|
||||
beforeEach(angular.mock.inject(function (_$controller_) {
|
||||
@ -26,7 +40,6 @@ describe('Browser: MainPage', function() {
|
||||
}));
|
||||
|
||||
describe('.shouldDriveStepBeDisabled()', function () {
|
||||
|
||||
it('should return true if there is no drive', function () {
|
||||
const controller = $controller('MainController', {
|
||||
$scope: {}
|
||||
@ -56,11 +69,9 @@ describe('Browser: MainPage', function() {
|
||||
|
||||
m.chai.expect(controller.shouldDriveStepBeDisabled()).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.shouldFlashStepBeDisabled()', function () {
|
||||
|
||||
it('should return true if there is no selected drive nor image', function () {
|
||||
const controller = $controller('MainController', {
|
||||
$scope: {}
|
||||
@ -145,13 +156,10 @@ describe('Browser: MainPage', function() {
|
||||
|
||||
m.chai.expect(controller.shouldFlashStepBeDisabled()).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('ImageSelectionController', function () {
|
||||
|
||||
let $controller;
|
||||
|
||||
beforeEach(angular.mock.inject(function (_$controller_) {
|
||||
@ -169,7 +177,6 @@ describe('Browser: MainPage', function() {
|
||||
});
|
||||
|
||||
describe('.getImageBasename()', function () {
|
||||
|
||||
it('should return the basename of the selected image', function () {
|
||||
const controller = $controller('ImageSelectionController', {
|
||||
$scope: {}
|
||||
@ -199,13 +206,10 @@ describe('Browser: MainPage', function() {
|
||||
selectionState.removeImage();
|
||||
m.chai.expect(controller.getImageBasename()).to.equal('');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('FlashController', function () {
|
||||
|
||||
let $controller;
|
||||
|
||||
beforeEach(angular.mock.inject(function (_$controller_) {
|
||||
@ -213,7 +217,6 @@ describe('Browser: MainPage', function() {
|
||||
}));
|
||||
|
||||
describe('.getProgressButtonLabel()', function () {
|
||||
|
||||
it('should return "Flash!" given a clean state', function () {
|
||||
const controller = $controller('FlashController', {
|
||||
$scope: {}
|
||||
@ -224,7 +227,6 @@ describe('Browser: MainPage', function() {
|
||||
});
|
||||
|
||||
describe('given there is a flash in progress', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
flashState.setFlashingFlag();
|
||||
});
|
||||
@ -449,11 +451,7 @@ describe('Browser: MainPage', function() {
|
||||
m.chai.expect(controller.getProgressButtonLabel()).to.equal('Finishing...');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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';
|
||||
|
||||
const m = require('mochainon');
|
||||
@ -6,13 +22,11 @@ require('angular-mocks');
|
||||
const units = require('../../../lib/shared/units');
|
||||
|
||||
describe('Browser: ByteSize', function () {
|
||||
|
||||
beforeEach(angular.mock.module(
|
||||
require('../../../lib/gui/utils/byte-size/byte-size')
|
||||
));
|
||||
|
||||
describe('ClosestUnitFilter', function () {
|
||||
|
||||
let closestUnitFilter;
|
||||
|
||||
beforeEach(angular.mock.inject(function (_closestUnitFilter_) {
|
||||
@ -22,6 +36,5 @@ describe('Browser: ByteSize', function() {
|
||||
it('should expose lib/shared/units.js bytesToGigabytes()', function () {
|
||||
m.chai.expect(closestUnitFilter).to.equal(units.bytesToClosestUnit);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
@ -22,7 +22,6 @@ const packageJSON = require('../../../package.json');
|
||||
require('angular-mocks');
|
||||
|
||||
describe('Browser: ManifestBind', function () {
|
||||
|
||||
beforeEach(angular.mock.module(
|
||||
require('../../../lib/gui/utils/manifest-bind/manifest-bind')
|
||||
));
|
||||
@ -36,7 +35,6 @@ describe('Browser: ManifestBind', function() {
|
||||
}));
|
||||
|
||||
describe('ManifestBindService', function () {
|
||||
|
||||
let ManifestBindService;
|
||||
|
||||
beforeEach(angular.mock.inject(function (_ManifestBindService_) {
|
||||
@ -57,11 +55,9 @@ describe('Browser: ManifestBind', function() {
|
||||
const value = ManifestBindService.get('foo.bar');
|
||||
m.chai.expect(value).to.be.undefined;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('manifestBind', function () {
|
||||
|
||||
it('should bind to top level properties', function () {
|
||||
const element = $compile('<span manifest-bind="version"></span>')($rootScope);
|
||||
$rootScope.$digest();
|
||||
@ -79,7 +75,5 @@ describe('Browser: ManifestBind', function() {
|
||||
$compile('<span manifest-bind="foo.bar"></span>')($rootScope);
|
||||
}).to.throw('ManifestBind: Unknown property `foo.bar`');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -24,13 +24,10 @@ const tester = require('../tester');
|
||||
const ZIP_PATH = path.join(__dirname, '..', 'data', 'zip');
|
||||
|
||||
describe('ImageStream: Archive hooks: ZIP', function () {
|
||||
|
||||
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
|
||||
|
||||
describe('.getEntries()', function () {
|
||||
|
||||
describe('given an empty zip', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
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([]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a zip with multiple files in it', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
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 () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.zip = path.join(ZIP_PATH, 'zip-directory-nested-misc.zip');
|
||||
});
|
||||
@ -86,13 +79,10 @@ describe('ImageStream: Archive hooks: ZIP', function() {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.extractFile()', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
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}`);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -26,11 +26,9 @@ const imageStream = require('../../lib/image-stream/index');
|
||||
const tester = require('./tester');
|
||||
|
||||
describe('ImageStream: BZ2', function () {
|
||||
|
||||
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
|
||||
|
||||
describe('compression method', function () {
|
||||
|
||||
describe('bzip2 level 9', function () {
|
||||
tester.extractFromFilePath(
|
||||
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(IMAGES_PATH, 'etcher-test.img'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageMetadata()', function () {
|
||||
|
||||
it('should return the correct metadata', function () {
|
||||
const image = path.join(BZ2_PATH, 'etcher-test.img.bz2');
|
||||
const expectedSize = fs.statSync(image).size;
|
||||
@ -69,7 +65,5 @@ describe('ImageStream: BZ2', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -24,11 +24,8 @@ const errors = require('../../lib/shared/errors');
|
||||
const imageStream = require('../../lib/image-stream/index');
|
||||
|
||||
describe('ImageStream: Directory', function () {
|
||||
|
||||
describe('.getFromFilePath()', function () {
|
||||
|
||||
describe('given a directory', function () {
|
||||
|
||||
it('should be rejected with an error', function (done) {
|
||||
imageStream.getFromFilePath(IMAGES_PATH).catch((error) => {
|
||||
m.chai.expect(error).to.be.an.instanceof(Error);
|
||||
@ -38,13 +35,10 @@ describe('ImageStream: Directory', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageMetadata()', function () {
|
||||
|
||||
it('should be rejected with an error', function (done) {
|
||||
imageStream.getImageMetadata(IMAGES_PATH).catch((error) => {
|
||||
m.chai.expect(error).to.be.an.instanceof(Error);
|
||||
@ -54,7 +48,5 @@ describe('ImageStream: Directory', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -26,11 +26,9 @@ const imageStream = require('../../lib/image-stream/index');
|
||||
const tester = require('./tester');
|
||||
|
||||
describe('ImageStream: DMG', function () {
|
||||
|
||||
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
|
||||
|
||||
describe('compression method', function () {
|
||||
|
||||
describe('NONE', function () {
|
||||
tester.extractFromFilePath(
|
||||
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(IMAGES_PATH, 'etcher-test.img'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
context('zlib compressed', function () {
|
||||
|
||||
describe('.getFromFilePath()', function () {
|
||||
|
||||
describe('given an dmg image', function () {
|
||||
tester.extractFromFilePath(
|
||||
path.join(DMG_PATH, 'etcher-test-zlib.dmg'),
|
||||
path.join(IMAGES_PATH, 'etcher-test.img'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageMetadata()', function () {
|
||||
|
||||
it('should return the correct metadata', function () {
|
||||
const image = path.join(DMG_PATH, 'etcher-test-zlib.dmg');
|
||||
const uncompressedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size;
|
||||
@ -99,25 +92,19 @@ describe('ImageStream: DMG', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
context('uncompressed', function () {
|
||||
|
||||
describe('.getFromFilePath()', function () {
|
||||
|
||||
describe('given an dmg image', function () {
|
||||
tester.extractFromFilePath(
|
||||
path.join(DMG_PATH, 'etcher-test-raw.dmg'),
|
||||
path.join(IMAGES_PATH, 'etcher-test.img'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageMetadata()', function () {
|
||||
|
||||
it('should return the correct metadata', function () {
|
||||
const image = path.join(DMG_PATH, 'etcher-test-raw.dmg');
|
||||
const uncompressedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size;
|
||||
@ -139,19 +126,14 @@ describe('ImageStream: DMG', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
context('invalid', function () {
|
||||
|
||||
describe('given an invalid dmg file', function () {
|
||||
tester.expectError(
|
||||
path.join(DATA_PATH, 'unrecognized', 'invalid.dmg'),
|
||||
'Invalid image', 'Invalid footer');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -26,21 +26,17 @@ const imageStream = require('../../lib/image-stream/index');
|
||||
const tester = require('./tester');
|
||||
|
||||
describe('ImageStream: GZ', function () {
|
||||
|
||||
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
|
||||
|
||||
describe('.getFromFilePath()', function () {
|
||||
|
||||
describe('given a gz image', function () {
|
||||
tester.extractFromFilePath(
|
||||
path.join(GZ_PATH, 'etcher-test.img.gz'),
|
||||
path.join(IMAGES_PATH, 'etcher-test.img'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageMetadata()', function () {
|
||||
|
||||
it('should return the correct metadata', function () {
|
||||
const image = path.join(GZ_PATH, 'etcher-test.img.gz');
|
||||
const uncompressedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size;
|
||||
@ -64,7 +60,5 @@ describe('ImageStream: GZ', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -25,23 +25,18 @@ const imageStream = require('../../lib/image-stream/index');
|
||||
const tester = require('./tester');
|
||||
|
||||
describe('ImageStream: IMG', function () {
|
||||
|
||||
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
|
||||
|
||||
describe('.getFromFilePath()', function () {
|
||||
|
||||
describe('given an img image', function () {
|
||||
tester.extractFromFilePath(
|
||||
path.join(IMAGES_PATH, 'etcher-test.img'),
|
||||
path.join(IMAGES_PATH, 'etcher-test.img'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageMetadata()', function () {
|
||||
|
||||
context('Master Boot Record', function () {
|
||||
|
||||
it('should return the correct metadata', function () {
|
||||
const image = path.join(IMAGES_PATH, 'etcher-test.img');
|
||||
const expectedSize = fs.statSync(image).size;
|
||||
@ -63,11 +58,9 @@ describe('ImageStream: IMG', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
context('GUID Partition Table', function () {
|
||||
|
||||
it('should return the correct metadata', function () {
|
||||
const image = path.join(IMAGES_PATH, 'etcher-gpt-test.img.gz');
|
||||
const uncompressedSize = 134217728;
|
||||
@ -91,9 +84,6 @@ describe('ImageStream: IMG', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -21,9 +21,7 @@ const _ = require('lodash');
|
||||
const imageStream = require('../../lib/image-stream/index');
|
||||
|
||||
describe('ImageStream', function () {
|
||||
|
||||
describe('.supportedFileTypes', function () {
|
||||
|
||||
it('should be an array', function () {
|
||||
m.chai.expect(_.isArray(imageStream.supportedFileTypes)).to.be.true;
|
||||
});
|
||||
@ -49,7 +47,5 @@ describe('ImageStream', function() {
|
||||
return _.first(fileType.extension) !== '.';
|
||||
}))).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -25,21 +25,17 @@ const imageStream = require('../../lib/image-stream/index');
|
||||
const tester = require('./tester');
|
||||
|
||||
describe('ImageStream: ISO', function () {
|
||||
|
||||
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
|
||||
|
||||
describe('.getFromFilePath()', function () {
|
||||
|
||||
describe('given an iso image', function () {
|
||||
tester.extractFromFilePath(
|
||||
path.join(IMAGES_PATH, 'etcher-test.iso'),
|
||||
path.join(IMAGES_PATH, 'etcher-test.iso'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageMetadata()', function () {
|
||||
|
||||
it('should return the correct metadata', function () {
|
||||
const image = path.join(IMAGES_PATH, 'etcher-test.iso');
|
||||
const expectedSize = fs.statSync(image).size;
|
||||
@ -61,7 +57,5 @@ describe('ImageStream: ISO', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -35,17 +35,14 @@ const testMetadataProperty = (archivePath, propertyName, expectedValue) => {
|
||||
};
|
||||
|
||||
describe('ImageStream: Metadata ZIP', function () {
|
||||
|
||||
this.timeout(10000);
|
||||
|
||||
describe('given an archive with an invalid `manifest.json`', function () {
|
||||
|
||||
tester.expectError(
|
||||
path.join(ZIP_PATH, 'etcher-test-invalid-manifest.zip'),
|
||||
'Invalid archive manifest.json');
|
||||
|
||||
describe('.getImageMetadata()', function () {
|
||||
|
||||
it('should be rejected with an error', function () {
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given an archive with a `manifest.json`', function () {
|
||||
|
||||
const archive = path.join(ZIP_PATH, 'etcher-test-with-manifest.zip');
|
||||
|
||||
tester.extractFromFilePath(
|
||||
@ -104,11 +98,9 @@ describe('ImageStream: Metadata ZIP', function() {
|
||||
it('should read the manifest recommendedDriveSize property', function () {
|
||||
return testMetadataProperty(archive, 'recommendedDriveSize', 4294967296);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given an archive with a `logo.svg`', function () {
|
||||
|
||||
const archive = path.join(ZIP_PATH, 'etcher-test-with-logo.zip');
|
||||
|
||||
const logo = [
|
||||
@ -121,11 +113,9 @@ describe('ImageStream: Metadata ZIP', function() {
|
||||
it('should read the logo contents', function () {
|
||||
return testMetadataProperty(archive, 'logo', logo);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given an archive with a bmap file', function () {
|
||||
|
||||
const archive = path.join(ZIP_PATH, 'etcher-test-with-bmap.zip');
|
||||
|
||||
const bmap = [
|
||||
@ -146,11 +136,9 @@ describe('ImageStream: Metadata ZIP', function() {
|
||||
it('should read the bmap contents', function () {
|
||||
return testMetadataProperty(archive, 'bmap', bmap);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given an archive with instructions', function () {
|
||||
|
||||
const archive = path.join(ZIP_PATH, 'etcher-test-with-instructions.zip');
|
||||
|
||||
const instructions = [
|
||||
@ -163,7 +151,5 @@ describe('ImageStream: Metadata ZIP', function() {
|
||||
it('should read the instruction contents', function () {
|
||||
return testMetadataProperty(archive, 'instructions', instructions);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -22,9 +22,7 @@ const DATA_PATH = path.join(__dirname, 'data');
|
||||
const mime = require('../../lib/image-stream/mime');
|
||||
|
||||
describe('ImageStream: MIME', function () {
|
||||
|
||||
describe('.getMimeTypeFromFileName()', function () {
|
||||
|
||||
it('should resolve application/x-bzip2 for a bz2 archive', function () {
|
||||
const file = path.join(DATA_PATH, 'bz2', 'etcher-test.img.bz2');
|
||||
return mime.getMimeTypeFromFileName(file).then((type) => {
|
||||
@ -101,7 +99,5 @@ describe('ImageStream: MIME', function() {
|
||||
m.chai.expect(type).to.equal('application/x-xz');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -21,20 +21,14 @@ const StreamReadable = require('stream').Readable;
|
||||
const utils = require('../../lib/image-stream/utils');
|
||||
|
||||
describe('ImageStream: Utils', function () {
|
||||
|
||||
describe('.extractStream()', function () {
|
||||
|
||||
describe('given a stream that emits data', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.stream = new StreamReadable();
|
||||
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
this.stream._read = function () {
|
||||
|
||||
/* eslint-enable no-underscore-dangle */
|
||||
|
||||
this.push(Buffer.from('Hello', 'utf8'));
|
||||
this.push(Buffer.from(' ', 'utf8'));
|
||||
this.push(Buffer.from('World', 'utf8'));
|
||||
@ -47,20 +41,15 @@ describe('ImageStream: Utils', function() {
|
||||
m.chai.expect(data.toString()).to.equal('Hello World');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a stream that throws an error', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.stream = new StreamReadable();
|
||||
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
|
||||
this.stream._read = function () {
|
||||
|
||||
/* eslint-enable no-underscore-dangle */
|
||||
|
||||
this.emit('error', new Error('stream error'));
|
||||
};
|
||||
});
|
||||
@ -71,9 +60,6 @@ describe('ImageStream: Utils', function() {
|
||||
m.chai.expect(error.message).to.equal('stream error');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -26,21 +26,17 @@ const imageStream = require('../../lib/image-stream/index');
|
||||
const tester = require('./tester');
|
||||
|
||||
describe('ImageStream: XZ', function () {
|
||||
|
||||
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
|
||||
|
||||
describe('.getFromFilePath()', function () {
|
||||
|
||||
describe('given a xz image', function () {
|
||||
tester.extractFromFilePath(
|
||||
path.join(XZ_PATH, 'etcher-test.img.xz'),
|
||||
path.join(IMAGES_PATH, 'etcher-test.img'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageMetadata()', function () {
|
||||
|
||||
it('should return the correct metadata', function () {
|
||||
const image = path.join(XZ_PATH, 'etcher-test.img.xz');
|
||||
const compressedSize = fs.statSync(image).size;
|
||||
@ -64,7 +60,5 @@ describe('ImageStream: XZ', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -26,11 +26,9 @@ const imageStream = require('../../lib/image-stream/index');
|
||||
const tester = require('./tester');
|
||||
|
||||
describe('ImageStream: ZIP', function () {
|
||||
|
||||
this.timeout(tester.DEFAULT_IMAGE_TESTS_TIMEOUT);
|
||||
|
||||
describe('.getFromFilePath()', function () {
|
||||
|
||||
describe('given an empty zip directory', function () {
|
||||
tester.expectError(
|
||||
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(IMAGES_PATH, 'etcher-test.img'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('compression method', function () {
|
||||
|
||||
context('DEFLATE', function () {
|
||||
tester.extractFromFilePath(
|
||||
path.join(ZIP_PATH, 'zip-deflate.zip'),
|
||||
@ -102,11 +98,9 @@ describe('ImageStream: ZIP', function() {
|
||||
path.join(ZIP_PATH, 'zip-lzma.zip'),
|
||||
path.join(IMAGES_PATH, 'etcher-test.img'));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageMetadata()', function () {
|
||||
|
||||
it('should return the correct metadata', function () {
|
||||
const image = path.join(ZIP_PATH, 'zip-directory-etcher-test-only.zip');
|
||||
const expectedSize = fs.statSync(path.join(IMAGES_PATH, 'etcher-test.img')).size;
|
||||
@ -129,7 +123,5 @@ describe('ImageStream: ZIP', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -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';
|
||||
|
||||
const m = require('mochainon');
|
||||
@ -6,9 +22,7 @@ const path = require('path');
|
||||
const constraints = require('../../lib/shared/drive-constraints');
|
||||
|
||||
describe('Shared: DriveConstraints', function () {
|
||||
|
||||
describe('.isDriveLocked()', function () {
|
||||
|
||||
it('should return true if the drive is protected', function () {
|
||||
const result = constraints.isDriveLocked({
|
||||
device: '/dev/disk2',
|
||||
@ -46,11 +60,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
m.chai.expect(result).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.isSystemDrive()', function () {
|
||||
|
||||
it('should return true if the drive is a system drive', function () {
|
||||
const result = constraints.isSystemDrive({
|
||||
device: '/dev/disk2',
|
||||
@ -91,11 +103,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
m.chai.expect(result).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.isSourceDrive()', function () {
|
||||
|
||||
it('should return false if no image', function () {
|
||||
const result = constraints.isSourceDrive({
|
||||
device: '/dev/disk2',
|
||||
@ -131,7 +141,6 @@ describe('Shared: DriveConstraints', function() {
|
||||
});
|
||||
|
||||
describe('given Windows paths', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.separator = path.sep;
|
||||
path.sep = '\\';
|
||||
@ -205,11 +214,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
m.chai.expect(result).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given UNIX paths', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.separator = path.sep;
|
||||
path.sep = '/';
|
||||
@ -297,13 +304,10 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
m.chai.expect(result).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.isDriveLargeEnough()', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.drive = {
|
||||
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 original size is less than the drive size', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.image = {
|
||||
path: path.join(__dirname, 'rpi.img'),
|
||||
@ -343,11 +345,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
this.image.size.final.value = this.drive.size + 1;
|
||||
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the original size is equal to the drive size', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.image = {
|
||||
path: path.join(__dirname, 'rpi.img'),
|
||||
@ -374,11 +374,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
this.image.size.final.value = this.drive.size + 1;
|
||||
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the original size is greater than the drive size', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.image = {
|
||||
path: path.join(__dirname, 'rpi.img'),
|
||||
@ -405,15 +403,11 @@ describe('Shared: DriveConstraints', function() {
|
||||
this.image.size.final.value = this.drive.size + 1;
|
||||
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 original size is less than the drive size', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.image = {
|
||||
path: path.join(__dirname, 'rpi.img'),
|
||||
@ -440,11 +434,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
this.image.size.final.value = this.drive.size + 1;
|
||||
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the original size is equal to the drive size', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.image = {
|
||||
path: path.join(__dirname, 'rpi.img'),
|
||||
@ -471,11 +463,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
this.image.size.final.value = this.drive.size + 1;
|
||||
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the original size is greater than the drive size', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.image = {
|
||||
path: path.join(__dirname, 'rpi.img'),
|
||||
@ -502,9 +492,7 @@ describe('Shared: DriveConstraints', function() {
|
||||
this.image.size.final.value = this.drive.size + 1;
|
||||
m.chai.expect(constraints.isDriveLargeEnough(this.drive, this.image)).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should return false if the drive is undefined', function () {
|
||||
@ -537,11 +525,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
const result = constraints.isDriveLargeEnough(undefined, undefined);
|
||||
m.chai.expect(result).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.isDriveSizeRecommended()', function () {
|
||||
|
||||
it('should return true if the drive size is greater than the recommended size ', function () {
|
||||
const result = constraints.isDriveSizeRecommended({
|
||||
device: '/dev/disk1',
|
||||
@ -626,11 +612,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
const result = constraints.isDriveSizeRecommended(undefined, undefined);
|
||||
m.chai.expect(result).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.isDriveValid()', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
if (process.platform === 'win32') {
|
||||
this.mountpoint = 'E:\\foo';
|
||||
@ -651,7 +635,6 @@ describe('Shared: DriveConstraints', function() {
|
||||
});
|
||||
|
||||
describe('given the drive is locked', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.drive.protected = true;
|
||||
});
|
||||
@ -707,11 +690,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
}
|
||||
})).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the drive is not locked', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.drive.protected = false;
|
||||
});
|
||||
@ -767,13 +748,10 @@ describe('Shared: DriveConstraints', function() {
|
||||
}
|
||||
})).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getDriveImageCompatibilityStatuses', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
if (process.platform === 'win32') {
|
||||
this.mountpoint = 'E:';
|
||||
@ -808,7 +786,6 @@ describe('Shared: DriveConstraints', function() {
|
||||
});
|
||||
|
||||
const expectStatusTypesAndMessagesToBe = (resultList, expectedTuples) => {
|
||||
|
||||
// Sort so that order doesn't matter
|
||||
const expectedTuplesSorted = _.sortBy(_.map(expectedTuples, (tuple) => {
|
||||
return {
|
||||
@ -822,7 +799,6 @@ describe('Shared: DriveConstraints', function() {
|
||||
};
|
||||
|
||||
describe('given there are no errors or warnings', () => {
|
||||
|
||||
it('should return an empty list', function () {
|
||||
const result = constraints.getDriveImageCompatibilityStatuses(this.drive, {
|
||||
path: '/mnt/disk2/rpi.img',
|
||||
@ -831,11 +807,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
m.chai.expect(result).to.deep.equal([]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the drive contains the image', () => {
|
||||
|
||||
it('should return the contains-image error', function () {
|
||||
this.image.path = path.join(this.mountpoint, 'rpi.img');
|
||||
|
||||
@ -844,11 +818,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
expectStatusTypesAndMessagesToBe(result, expectedTuples);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the drive is a system drive', () => {
|
||||
|
||||
it('should return the system drive warning', function () {
|
||||
this.drive.system = true;
|
||||
|
||||
@ -857,11 +829,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
expectStatusTypesAndMessagesToBe(result, expectedTuples);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the drive is too small', () => {
|
||||
|
||||
it('should return the too small error', function () {
|
||||
this.image.size.final.value = this.drive.size + 1;
|
||||
|
||||
@ -870,11 +840,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
expectStatusTypesAndMessagesToBe(result, expectedTuples);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the drive is locked', () => {
|
||||
|
||||
it('should return the locked drive error', function () {
|
||||
this.drive.protected = true;
|
||||
|
||||
@ -883,11 +851,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
expectStatusTypesAndMessagesToBe(result, expectedTuples);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the drive is smaller than the recommended size', () => {
|
||||
|
||||
it('should return the smaller than recommended size warning', function () {
|
||||
this.image.recommendedDriveSize = this.drive.size + 1;
|
||||
|
||||
@ -896,31 +862,25 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
expectStatusTypesAndMessagesToBe(result, expectedTuples);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the image is null', () => {
|
||||
|
||||
it('should return an empty list', function () {
|
||||
const result = constraints.getDriveImageCompatibilityStatuses(this.drive, null);
|
||||
|
||||
m.chai.expect(result).to.deep.equal([]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the drive is null', () => {
|
||||
|
||||
it('should return an empty list', function () {
|
||||
const result = constraints.getDriveImageCompatibilityStatuses(null, this.image);
|
||||
|
||||
m.chai.expect(result).to.deep.equal([]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a locked drive and image is null', () => {
|
||||
|
||||
it('should return locked drive error', function () {
|
||||
this.drive.protected = true;
|
||||
|
||||
@ -929,11 +889,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
expectStatusTypesAndMessagesToBe(result, expectedTuples);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a system drive and image is null', () => {
|
||||
|
||||
it('should return system drive warning', function () {
|
||||
this.drive.system = true;
|
||||
|
||||
@ -942,11 +900,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
expectStatusTypesAndMessagesToBe(result, expectedTuples);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the drive contains the image and the drive is locked', () => {
|
||||
|
||||
it('should return the contains-image drive error by precedence', function () {
|
||||
this.drive.protected = true;
|
||||
this.image.path = path.join(this.mountpoint, 'rpi.img');
|
||||
@ -956,11 +912,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
expectStatusTypesAndMessagesToBe(result, expectedTuples);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a locked and too small drive', () => {
|
||||
|
||||
it('should return the locked error by precedence', function () {
|
||||
this.drive.protected = true;
|
||||
|
||||
@ -969,11 +923,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
expectStatusTypesAndMessagesToBe(result, expectedTuples);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a too small and system drive', () => {
|
||||
|
||||
it('should return the too small drive error by precedence', function () {
|
||||
this.image.size.final.value = this.drive.size + 1;
|
||||
this.drive.system = true;
|
||||
@ -983,11 +935,9 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
expectStatusTypesAndMessagesToBe(result, expectedTuples);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a system drive and not recommended drive size', () => {
|
||||
|
||||
it('should return both warnings', function () {
|
||||
this.drive.system = true;
|
||||
this.image.recommendedDriveSize = this.drive.size + 1;
|
||||
@ -997,8 +947,6 @@ describe('Shared: DriveConstraints', function() {
|
||||
|
||||
expectStatusTypesAndMessagesToBe(result, expectedTuples);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -21,9 +21,7 @@ const _ = require('lodash');
|
||||
const errors = require('../../lib/shared/errors');
|
||||
|
||||
describe('Shared: Errors', function () {
|
||||
|
||||
describe('.HUMAN_FRIENDLY', function () {
|
||||
|
||||
it('should be a plain object', function () {
|
||||
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);
|
||||
}))).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getTitle()', function () {
|
||||
|
||||
it('should accept a string', function () {
|
||||
const error = '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';
|
||||
m.chai.expect(errors.getTitle(error)).to.equal('Your system ran out of memory');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getDescription()', function () {
|
||||
|
||||
it('should return an empty string if the error is a string', function () {
|
||||
const error = 'My error';
|
||||
m.chai.expect(errors.getDescription(error)).to.equal('');
|
||||
@ -332,7 +326,6 @@ describe('Shared: Errors', function() {
|
||||
});
|
||||
|
||||
describe('given userFriendlyDescriptionsOnly is false', function () {
|
||||
|
||||
it('should return the stack for a basic error', function () {
|
||||
const error = new Error('Foo');
|
||||
m.chai.expect(errors.getDescription(error, {
|
||||
@ -355,11 +348,9 @@ describe('Shared: Errors', function() {
|
||||
userFriendlyDescriptionsOnly: false
|
||||
})).to.equal(error.stack);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given userFriendlyDescriptionsOnly is true', function () {
|
||||
|
||||
it('should return an empty string for a basic error', function () {
|
||||
const error = new Error('Foo');
|
||||
m.chai.expect(errors.getDescription(error, {
|
||||
@ -382,13 +373,10 @@ describe('Shared: Errors', function() {
|
||||
userFriendlyDescriptionsOnly: true
|
||||
})).to.equal('');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.createError()', function () {
|
||||
|
||||
it('should not be a user error', function () {
|
||||
const error = errors.createError({
|
||||
title: 'Foo',
|
||||
@ -513,11 +501,9 @@ describe('Shared: Errors', function() {
|
||||
});
|
||||
}).to.throw('Invalid error title: ');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.createUserError()', function () {
|
||||
|
||||
it('should be a user error', function () {
|
||||
const error = errors.createUserError({
|
||||
title: 'Foo',
|
||||
@ -602,23 +588,19 @@ describe('Shared: Errors', function() {
|
||||
});
|
||||
}).to.throw('Invalid error title: ');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.isUserError()', function () {
|
||||
|
||||
_.each([
|
||||
0,
|
||||
'',
|
||||
false
|
||||
], (value) => {
|
||||
|
||||
it(`should return true if report equals ${value}`, function () {
|
||||
const error = new Error('foo bar');
|
||||
error.report = value;
|
||||
m.chai.expect(errors.isUserError(error)).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
_.each([
|
||||
@ -629,19 +611,15 @@ describe('Shared: Errors', function() {
|
||||
3,
|
||||
'foo'
|
||||
], (value) => {
|
||||
|
||||
it(`should return false if report equals ${value}`, function () {
|
||||
const error = new Error('foo bar');
|
||||
error.report = value;
|
||||
m.chai.expect(errors.isUserError(error)).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.toJSON()', function () {
|
||||
|
||||
it('should convert a simple error', function () {
|
||||
const error = new Error('My error');
|
||||
m.chai.expect(errors.toJSON(error)).to.deep.equal({
|
||||
@ -717,11 +695,9 @@ describe('Shared: Errors', function() {
|
||||
report: undefined
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.fromJSON()', function () {
|
||||
|
||||
it('should return an Error object', function () {
|
||||
const error = new Error('My 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.report).to.equal(error.report);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -21,9 +21,7 @@ const _ = require('lodash');
|
||||
const fileExtensions = require('../../lib/shared/file-extensions');
|
||||
|
||||
describe('Shared: fileExtensions', function () {
|
||||
|
||||
describe('.getFileExtensions()', function () {
|
||||
|
||||
_.forEach([
|
||||
|
||||
// No extension
|
||||
@ -99,11 +97,9 @@ describe('Shared: fileExtensions', function() {
|
||||
'gz'
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getLastFileExtension()', function () {
|
||||
|
||||
it('should return undefined if the file path has no extension', function () {
|
||||
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 () {
|
||||
m.chai.expect(fileExtensions.getLastFileExtension('foo.bar.img.gz')).to.equal('gz');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getPenultimateFileExtension()', function () {
|
||||
|
||||
it('should return undefined in the file path has no extension', function () {
|
||||
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 () {
|
||||
m.chai.expect(fileExtensions.getPenultimateFileExtension('foo.bar.img.gz')).to.equal('img');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -21,7 +21,6 @@ const _ = require('lodash');
|
||||
const messages = require('../../lib/shared/messages');
|
||||
|
||||
describe('Shared: Messages', function () {
|
||||
|
||||
it('should contain object properties', function () {
|
||||
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;
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -22,15 +22,12 @@ const availableDrives = require('../../../lib/shared/models/available-drives');
|
||||
const selectionState = require('../../../lib/shared/models/selection-state');
|
||||
|
||||
describe('Model: availableDrives', function () {
|
||||
|
||||
describe('availableDrives', function () {
|
||||
|
||||
it('should have no drives by default', function () {
|
||||
m.chai.expect(availableDrives.getDrives()).to.deep.equal([]);
|
||||
});
|
||||
|
||||
describe('.setDrives()', function () {
|
||||
|
||||
it('should throw if no drives', function () {
|
||||
m.chai.expect(function () {
|
||||
availableDrives.setDrives();
|
||||
@ -52,21 +49,16 @@ describe('Model: availableDrives', function() {
|
||||
]);
|
||||
}).to.throw('Invalid drives: 123,123,123');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given no drives', function () {
|
||||
|
||||
describe('.hasAvailableDrives()', function () {
|
||||
|
||||
it('should return false', function () {
|
||||
m.chai.expect(availableDrives.hasAvailableDrives()).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.setDrives()', function () {
|
||||
|
||||
it('should be able to set drives', function () {
|
||||
const drives = [
|
||||
{
|
||||
@ -83,7 +75,6 @@ describe('Model: availableDrives', function() {
|
||||
});
|
||||
|
||||
describe('given no selected image and no selected drive', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
selectionState.removeDrive();
|
||||
selectionState.removeImage();
|
||||
@ -106,11 +97,9 @@ describe('Model: availableDrives', function() {
|
||||
m.chai.expect(selectionState.hasDrive()).to.be.true;
|
||||
m.chai.expect(selectionState.getDrive().device).to.equal('/dev/sdb');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a selected image and no selected drive', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
if (process.platform === 'win32') {
|
||||
this.imagePath = 'E:\\bar\\foo.img';
|
||||
@ -274,15 +263,11 @@ describe('Model: availableDrives', function() {
|
||||
|
||||
m.chai.expect(selectionState.hasDrive()).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given drives', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.drives = [
|
||||
{
|
||||
@ -307,7 +292,6 @@ describe('Model: availableDrives', function() {
|
||||
});
|
||||
|
||||
describe('given one of the drives was selected', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
availableDrives.setDrives([
|
||||
{
|
||||
@ -354,20 +338,16 @@ describe('Model: availableDrives', function() {
|
||||
|
||||
m.chai.expect(selectionState.hasDrive()).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.hasAvailableDrives()', function () {
|
||||
|
||||
it('should return true', function () {
|
||||
const hasDrives = availableDrives.hasAvailableDrives();
|
||||
m.chai.expect(hasDrives).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.setDrives()', function () {
|
||||
|
||||
it('should keep the same drives if equal', function () {
|
||||
availableDrives.setDrives(this.drives);
|
||||
m.chai.expect(availableDrives.getDrives()).to.deep.equal(this.drives);
|
||||
@ -383,10 +363,7 @@ describe('Model: availableDrives', function() {
|
||||
availableDrives.setDrives(this.drives);
|
||||
m.chai.expect(availableDrives.getDrives()).to.deep.equal(this.drives);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -20,15 +20,12 @@ const m = require('mochainon');
|
||||
const flashState = require('../../../lib/shared/models/flash-state');
|
||||
|
||||
describe('Model: flashState', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
flashState.resetState();
|
||||
});
|
||||
|
||||
describe('flashState', function () {
|
||||
|
||||
describe('.resetState()', function () {
|
||||
|
||||
it('should be able to reset the progress state', function () {
|
||||
flashState.setFlashingFlag();
|
||||
flashState.setProgressState({
|
||||
@ -67,11 +64,9 @@ describe('Model: flashState', function() {
|
||||
flashState.resetState();
|
||||
m.chai.expect(flashState.getFlashUuid()).to.be.undefined;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.isFlashing()', function () {
|
||||
|
||||
it('should return false by default', function () {
|
||||
m.chai.expect(flashState.isFlashing()).to.be.false;
|
||||
});
|
||||
@ -80,11 +75,9 @@ describe('Model: flashState', function() {
|
||||
flashState.setFlashingFlag();
|
||||
m.chai.expect(flashState.isFlashing()).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.setProgressState()', function () {
|
||||
|
||||
it('should not allow setting the state if flashing is false', function () {
|
||||
flashState.unsetFlashingFlag({
|
||||
cancelled: false,
|
||||
@ -240,11 +233,9 @@ describe('Model: flashState', function() {
|
||||
});
|
||||
}).to.not.throw('Missing state speed');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getFlashResults()', function () {
|
||||
|
||||
it('should get the flash results', function () {
|
||||
flashState.setFlashingFlag();
|
||||
|
||||
@ -257,11 +248,9 @@ describe('Model: flashState', function() {
|
||||
const results = flashState.getFlashResults();
|
||||
m.chai.expect(results).to.deep.equal(expectedResults);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getFlashState()', function () {
|
||||
|
||||
it('should initially return an empty state', function () {
|
||||
flashState.resetState();
|
||||
const currentFlashState = flashState.getFlashState();
|
||||
@ -284,11 +273,9 @@ describe('Model: flashState', function() {
|
||||
const currentFlashState = flashState.getFlashState();
|
||||
m.chai.expect(currentFlashState).to.deep.equal(state);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.unsetFlashingFlag()', function () {
|
||||
|
||||
it('should throw if no flashing results', function () {
|
||||
m.chai.expect(function () {
|
||||
flashState.unsetFlashingFlag();
|
||||
@ -405,11 +392,9 @@ describe('Model: flashState', function() {
|
||||
const uuidAfterUnset = flashState.getFlashUuid();
|
||||
m.chai.expect(uuidBeforeUnset).to.equal(uuidAfterUnset);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.setFlashingFlag()', function () {
|
||||
|
||||
it('should be able to set flashing to true', function () {
|
||||
flashState.setFlashingFlag();
|
||||
m.chai.expect(flashState.isFlashing()).to.be.true;
|
||||
@ -427,11 +412,9 @@ describe('Model: flashState', function() {
|
||||
flashState.setFlashingFlag();
|
||||
m.chai.expect(flashState.getFlashResults()).to.deep.equal({});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.wasLastFlashCancelled()', function () {
|
||||
|
||||
it('should return false given a pristine state', function () {
|
||||
flashState.resetState();
|
||||
m.chai.expect(flashState.wasLastFlashCancelled()).to.be.false;
|
||||
@ -453,11 +436,9 @@ describe('Model: flashState', function() {
|
||||
|
||||
m.chai.expect(flashState.wasLastFlashCancelled()).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getLastFlashSourceChecksum()', function () {
|
||||
|
||||
it('should return undefined given a pristine state', function () {
|
||||
flashState.resetState();
|
||||
m.chai.expect(flashState.getLastFlashSourceChecksum()).to.be.undefined;
|
||||
@ -479,11 +460,9 @@ describe('Model: flashState', function() {
|
||||
|
||||
m.chai.expect(flashState.getLastFlashSourceChecksum()).to.be.undefined;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getLastFlashErrorCode()', function () {
|
||||
|
||||
it('should return undefined given a pristine state', function () {
|
||||
flashState.resetState();
|
||||
m.chai.expect(flashState.getLastFlashErrorCode()).to.be.undefined;
|
||||
@ -507,11 +486,9 @@ describe('Model: flashState', function() {
|
||||
|
||||
m.chai.expect(flashState.getLastFlashErrorCode()).to.be.undefined;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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}$/;
|
||||
|
||||
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(uuid3).to.not.equal(uuid1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -23,9 +23,7 @@ const availableDrives = require('../../../lib/shared/models/available-drives');
|
||||
const selectionState = require('../../../lib/shared/models/selection-state');
|
||||
|
||||
describe('Model: selectionState', function () {
|
||||
|
||||
describe('given a clean state', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
selectionState.clear();
|
||||
});
|
||||
@ -76,11 +74,9 @@ describe('Model: selectionState', function() {
|
||||
const hasImage = selectionState.hasImage();
|
||||
m.chai.expect(hasImage).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a drive', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
availableDrives.setDrives([
|
||||
{
|
||||
@ -101,7 +97,6 @@ describe('Model: selectionState', function() {
|
||||
});
|
||||
|
||||
describe('.getDrive()', function () {
|
||||
|
||||
it('should return the drive', function () {
|
||||
const drive = selectionState.getDrive();
|
||||
m.chai.expect(drive).to.deep.equal({
|
||||
@ -111,20 +106,16 @@ describe('Model: selectionState', function() {
|
||||
protected: false
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.hasDrive()', function () {
|
||||
|
||||
it('should return true', function () {
|
||||
const hasDrive = selectionState.hasDrive();
|
||||
m.chai.expect(hasDrive).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.setDrive()', function () {
|
||||
|
||||
it('should override the drive', function () {
|
||||
selectionState.setDrive('/dev/disk5');
|
||||
const drive = selectionState.getDrive();
|
||||
@ -135,25 +126,19 @@ describe('Model: selectionState', function() {
|
||||
protected: false
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.removeDrive()', function () {
|
||||
|
||||
it('should clear the drive', function () {
|
||||
selectionState.removeDrive();
|
||||
const drive = selectionState.getDrive();
|
||||
m.chai.expect(drive).to.be.undefined;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given no drive', function () {
|
||||
|
||||
describe('.setDrive()', function () {
|
||||
|
||||
it('should be able to set a drive', function () {
|
||||
availableDrives.setDrives([
|
||||
{
|
||||
@ -209,13 +194,10 @@ describe('Model: selectionState', function() {
|
||||
selectionState.setDrive(123);
|
||||
}).to.throw('Invalid drive: 123');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given an image', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.image = {
|
||||
path: 'foo.img',
|
||||
@ -238,7 +220,6 @@ describe('Model: selectionState', function() {
|
||||
});
|
||||
|
||||
describe('.setDrive()', function () {
|
||||
|
||||
it('should throw if drive is not large enough', function () {
|
||||
availableDrives.setDrives([
|
||||
{
|
||||
@ -253,91 +234,71 @@ describe('Model: selectionState', function() {
|
||||
selectionState.setDrive('/dev/disk2');
|
||||
}).to.throw('The drive is not large enough');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImage()', function () {
|
||||
|
||||
it('should return the image', function () {
|
||||
m.chai.expect(selectionState.getImage()).to.deep.equal(this.image);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImagePath()', function () {
|
||||
|
||||
it('should return the image path', function () {
|
||||
const imagePath = selectionState.getImagePath();
|
||||
m.chai.expect(imagePath).to.equal('foo.img');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageSize()', function () {
|
||||
|
||||
it('should return the image size', function () {
|
||||
const imageSize = selectionState.getImageSize();
|
||||
m.chai.expect(imageSize).to.equal(999999999);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageUrl()', function () {
|
||||
|
||||
it('should return the image url', function () {
|
||||
const imageUrl = selectionState.getImageUrl();
|
||||
m.chai.expect(imageUrl).to.equal('https://www.raspbian.org');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageName()', function () {
|
||||
|
||||
it('should return the image name', function () {
|
||||
const imageName = selectionState.getImageName();
|
||||
m.chai.expect(imageName).to.equal('Raspbian');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageLogo()', function () {
|
||||
|
||||
it('should return the image logo', function () {
|
||||
const imageLogo = selectionState.getImageLogo();
|
||||
m.chai.expect(imageLogo).to.equal('<svg><text fill="red">Raspbian</text></svg>');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageSupportUrl()', function () {
|
||||
|
||||
it('should return the image support url', function () {
|
||||
const imageSupportUrl = selectionState.getImageSupportUrl();
|
||||
m.chai.expect(imageSupportUrl).to.equal('https://www.raspbian.org/forums/');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getImageRecommendedDriveSize()', function () {
|
||||
|
||||
it('should return the image recommended drive size', function () {
|
||||
const imageRecommendedDriveSize = selectionState.getImageRecommendedDriveSize();
|
||||
m.chai.expect(imageRecommendedDriveSize).to.equal(1000000000);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.hasImage()', function () {
|
||||
|
||||
it('should return true', function () {
|
||||
const hasImage = selectionState.hasImage();
|
||||
m.chai.expect(hasImage).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.setImage()', function () {
|
||||
|
||||
it('should override the image', function () {
|
||||
selectionState.setImage({
|
||||
path: 'bar.img',
|
||||
@ -356,11 +317,9 @@ describe('Model: selectionState', function() {
|
||||
const imageSize = selectionState.getImageSize();
|
||||
m.chai.expect(imageSize).to.equal(999999999);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.removeImage()', function () {
|
||||
|
||||
it('should clear the image', function () {
|
||||
selectionState.removeImage();
|
||||
|
||||
@ -369,15 +328,11 @@ describe('Model: selectionState', function() {
|
||||
const imageSize = selectionState.getImageSize();
|
||||
m.chai.expect(imageSize).to.be.undefined;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given no image', function () {
|
||||
|
||||
describe('.setImage()', function () {
|
||||
|
||||
it('should be able to set an image', function () {
|
||||
selectionState.setImage({
|
||||
path: 'foo.img',
|
||||
@ -859,13 +814,10 @@ describe('Model: selectionState', function() {
|
||||
m.chai.expect(selectionState.hasDrive()).to.be.false;
|
||||
selectionState.removeImage();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a drive', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
availableDrives.setDrives([
|
||||
{
|
||||
@ -892,7 +844,6 @@ describe('Model: selectionState', function() {
|
||||
});
|
||||
|
||||
describe('.clear()', function () {
|
||||
|
||||
it('should clear all selections', function () {
|
||||
m.chai.expect(selectionState.hasDrive()).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.hasImage()).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the preserveImage option', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
selectionState.clear({
|
||||
preserveImage: true
|
||||
@ -937,15 +886,11 @@ describe('Model: selectionState', function() {
|
||||
const hasImage = selectionState.hasImage();
|
||||
m.chai.expect(hasImage).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.isCurrentDrive()', function () {
|
||||
|
||||
describe('given a selected drive', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
availableDrives.setDrives([
|
||||
{
|
||||
@ -973,11 +918,9 @@ describe('Model: selectionState', function() {
|
||||
it('should return false if it is not the current drive', function () {
|
||||
m.chai.expect(selectionState.isCurrentDrive('/dev/sdc')).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given no selected drive', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
selectionState.removeDrive();
|
||||
});
|
||||
@ -989,15 +932,11 @@ describe('Model: selectionState', function() {
|
||||
it('should return false for anything', function () {
|
||||
m.chai.expect(selectionState.isCurrentDrive('/dev/sdb')).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.toggleSetDrive()', function () {
|
||||
|
||||
describe('given a selected drive', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.drive = {
|
||||
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.not.deep.equal(this.drive);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given no selected drive', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
selectionState.removeDrive();
|
||||
});
|
||||
@ -1062,9 +999,6 @@ describe('Model: selectionState', function() {
|
||||
selectionState.toggleSetDrive(drive.device);
|
||||
m.chai.expect(selectionState.getDrive()).to.deep.equal(drive);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -21,11 +21,8 @@ const os = require('os');
|
||||
const permissions = require('../../lib/shared/permissions');
|
||||
|
||||
describe('Shared: permissions', function () {
|
||||
|
||||
describe('.getEnvironmentCommandPrefix()', function () {
|
||||
|
||||
describe('given windows', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.osPlatformStub = m.sinon.stub(os, 'platform');
|
||||
this.osPlatformStub.returns('win32');
|
||||
@ -104,11 +101,9 @@ describe('Shared: permissions', function() {
|
||||
'call'
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given linux', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.osPlatformStub = m.sinon.stub(os, 'platform');
|
||||
this.osPlatformStub.returns('linux');
|
||||
@ -171,11 +166,9 @@ describe('Shared: permissions', function() {
|
||||
'BAZ=-1'
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given darwin', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.osPlatformStub = m.sinon.stub(os, 'platform');
|
||||
this.osPlatformStub.returns('darwin');
|
||||
@ -238,9 +231,6 @@ describe('Shared: permissions', function() {
|
||||
'BAZ=-1'
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -21,9 +21,7 @@ const _ = require('lodash');
|
||||
const release = require('../../lib/shared/release');
|
||||
|
||||
describe('Shared: Release', function () {
|
||||
|
||||
describe('.RELEASE_TYPE', function () {
|
||||
|
||||
it('should be a plain object', function () {
|
||||
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));
|
||||
m.chai.expect(_.size(keys)).to.equal(_.size(uniqueValues));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getReleaseType()', function () {
|
||||
|
||||
it('should return the unknown release type if the version is not valid semver', function () {
|
||||
const releaseType = release.getReleaseType('foo.bar');
|
||||
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.UNKNOWN);
|
||||
});
|
||||
|
||||
describe('given the version has a short git commit hash build number', function () {
|
||||
|
||||
it('should return the snapshot release type', function () {
|
||||
const releaseType = release.getReleaseType('1.0.0+6374412');
|
||||
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');
|
||||
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the version has a long git commit hash build number', function () {
|
||||
|
||||
it('should return the snapshot release type', function () {
|
||||
const releaseType = release.getReleaseType('1.0.0+6374412554b034799bfc6e13b4e39c3f5e6386e6');
|
||||
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');
|
||||
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.SNAPSHOT);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given the version has no build number', function () {
|
||||
|
||||
it('should return the production release type', function () {
|
||||
const releaseType = release.getReleaseType('1.0.0');
|
||||
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');
|
||||
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.PRODUCTION);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a build number that is not a git commit hash', function () {
|
||||
|
||||
it('should return the unknown release type', function () {
|
||||
const releaseType = release.getReleaseType('1.0.0+foo');
|
||||
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');
|
||||
m.chai.expect(releaseType).to.equal(release.RELEASE_TYPE.UNKNOWN);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.isStableRelease()', function () {
|
||||
|
||||
it('should return true if given a production stable version', function () {
|
||||
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 () {
|
||||
m.chai.expect(release.isStableRelease('1.0.0-beta.1+6374412')).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -21,9 +21,7 @@ const _ = require('lodash');
|
||||
const robot = require('../../lib/shared/robot');
|
||||
|
||||
describe('Shared: Robot', function () {
|
||||
|
||||
describe('.COMMAND', function () {
|
||||
|
||||
it('should be a plain object', function () {
|
||||
m.chai.expect(_.isPlainObject(robot.COMMAND)).to.be.true;
|
||||
});
|
||||
@ -36,11 +34,9 @@ describe('Shared: Robot', function() {
|
||||
const numberOfKeys = _.size(_.keys(robot.COMMAND));
|
||||
m.chai.expect(_.size(_.uniq(_.values(robot.COMMAND)))).to.equal(numberOfKeys);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.isEnabled()', function () {
|
||||
|
||||
it('should return false if ETCHER_CLI_ROBOT is not set', function () {
|
||||
m.chai.expect(robot.isEnabled({})).to.be.false;
|
||||
});
|
||||
@ -80,11 +76,9 @@ describe('Shared: Robot', function() {
|
||||
ETCHER_CLI_ROBOT: false
|
||||
})).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.buildMessage()', function () {
|
||||
|
||||
it('should build a message without data', function () {
|
||||
const message = robot.buildMessage('hello');
|
||||
const result = '{"command":"hello","data":{}}';
|
||||
@ -105,11 +99,9 @@ describe('Shared: Robot', function() {
|
||||
robot.buildMessage('hello', 'world');
|
||||
}).to.throw('Invalid data: world');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.isMessage()', function () {
|
||||
|
||||
it('should return true if message is an empty object', function () {
|
||||
m.chai.expect(robot.isMessage('{}')).to.be.true;
|
||||
});
|
||||
@ -200,11 +192,9 @@ describe('Shared: Robot', function() {
|
||||
const error = new Error('foo');
|
||||
m.chai.expect(robot.isMessage(robot.buildErrorMessage(error))).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.buildErrorMessage()', function () {
|
||||
|
||||
it('should build a message from a simple error', function () {
|
||||
const error = new Error('foo');
|
||||
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(_.isEmpty(message.data.stack)).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.parseMessage()', function () {
|
||||
|
||||
it('should parse a valid message', function () {
|
||||
const message = robot.buildMessage('foo', {
|
||||
bar: 1
|
||||
@ -297,11 +285,9 @@ describe('Shared: Robot', function() {
|
||||
robot.parseMessage('{"command":"foo"}');
|
||||
}).to.throw('Invalid message');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getCommand()', function () {
|
||||
|
||||
it('should get the command of a message', function () {
|
||||
const message = robot.parseMessage(robot.buildMessage('hello', {
|
||||
foo: 1,
|
||||
@ -310,11 +296,9 @@ describe('Shared: Robot', function() {
|
||||
|
||||
m.chai.expect(robot.getCommand(message)).to.equal('hello');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getData()', function () {
|
||||
|
||||
it('should get the data of a message', function () {
|
||||
const message = robot.parseMessage(robot.buildMessage('hello', {
|
||||
foo: 1,
|
||||
@ -332,11 +316,9 @@ describe('Shared: Robot', function() {
|
||||
command: 'foo'
|
||||
})).to.deep.equal({});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.recomposeErrorMessage()', function () {
|
||||
|
||||
it('should return an instance of Error', function () {
|
||||
const error = new Error('Foo bar');
|
||||
const message = robot.parseMessage(robot.buildErrorMessage(error));
|
||||
@ -362,7 +344,5 @@ describe('Shared: Robot', function() {
|
||||
const message = robot.parseMessage(robot.buildErrorMessage(error));
|
||||
m.chai.expect(robot.recomposeErrorMessage(message)).to.deep.equal(error);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -24,9 +24,7 @@ const s3Packages = require('../../lib/shared/s3-packages');
|
||||
const release = require('../../lib/shared/release');
|
||||
|
||||
describe('Shared: s3Packages', function () {
|
||||
|
||||
describe('.getBucketUrlFromReleaseType()', function () {
|
||||
|
||||
it('should return the production URL if given a production release type', function () {
|
||||
const bucketUrl = s3Packages.getBucketUrlFromReleaseType(release.RELEASE_TYPE.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);
|
||||
m.chai.expect(bucketUrl).to.be.null;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getRemoteVersions()', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
s3Packages.getRemoteVersions.cache.clear();
|
||||
});
|
||||
@ -59,7 +55,6 @@ describe('Shared: s3Packages', function() {
|
||||
});
|
||||
|
||||
describe('given an empty bucket', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, `
|
||||
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
@ -82,11 +77,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given many versions', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, `
|
||||
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
@ -224,11 +217,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a version is being uploaded', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, `
|
||||
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
@ -358,11 +349,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given other programs in the bucket', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, `
|
||||
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
@ -499,11 +488,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given only other programs in the bucket', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(200, `
|
||||
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
||||
@ -575,11 +562,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given an unsuccessful request', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
nock(s3Packages.BUCKET_URL.PRODUCTION).get('/').reply(500);
|
||||
});
|
||||
@ -594,11 +579,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given ENOTFOUND', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
const error = new Error('ENOTFOUND');
|
||||
error.code = 'ENOTFOUND';
|
||||
@ -617,11 +600,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given ETIMEDOUT', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
const error = new Error('ETIMEDOUT');
|
||||
error.code = 'ETIMEDOUT';
|
||||
@ -640,11 +621,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given EHOSTDOWN', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
const error = new Error('EHOSTDOWN');
|
||||
error.code = 'EHOSTDOWN';
|
||||
@ -663,11 +642,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given ECONNRESET', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
const error = new Error('ECONNRESET');
|
||||
error.code = 'ECONNRESET';
|
||||
@ -686,11 +663,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given ECONNREFUSED', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
const error = new Error('ECONNREFUSED');
|
||||
error.code = 'ECONNREFUSED';
|
||||
@ -709,11 +684,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given EACCES', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
const error = new Error('EACCES');
|
||||
error.code = 'EACCES';
|
||||
@ -732,11 +705,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given UNABLE_TO_VERIFY_LEAF_SIGNATURE', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
const error = new Error('UNABLE_TO_VERIFY_LEAF_SIGNATURE');
|
||||
error.code = 'UNABLE_TO_VERIFY_LEAF_SIGNATURE';
|
||||
@ -755,15 +726,11 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getLatestVersion()', function () {
|
||||
|
||||
describe('given a valid production ETCHER_FAKE_S3_LATEST_VERSION environment variable', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
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 () {
|
||||
|
||||
it('should resolve the variable', function (done) {
|
||||
s3Packages.getLatestVersion(release.RELEASE_TYPE.PRODUCTION).then((latestVersion) => {
|
||||
m.chai.expect(latestVersion).to.equal('9.9.9');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a snapshot release type', function () {
|
||||
|
||||
it('should resolve undefined', function (done) {
|
||||
s3Packages.getLatestVersion(release.RELEASE_TYPE.SNAPSHOT).then((latestVersion) => {
|
||||
m.chai.expect(latestVersion).to.be.undefined;
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a valid snapshot ETCHER_FAKE_S3_LATEST_VERSION environment variable', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
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 () {
|
||||
|
||||
it('should resolve the variable', function (done) {
|
||||
s3Packages.getLatestVersion(release.RELEASE_TYPE.SNAPSHOT).then((latestVersion) => {
|
||||
m.chai.expect(latestVersion).to.equal('9.9.9+7b47334');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a production release type', function () {
|
||||
|
||||
it('should resolve undefined', function (done) {
|
||||
s3Packages.getLatestVersion(release.RELEASE_TYPE.PRODUCTION).then((latestVersion) => {
|
||||
m.chai.expect(latestVersion).to.be.undefined;
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given an invalid ETCHER_FAKE_S3_LATEST_VERSION environment variable', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
process.env.ETCHER_FAKE_S3_LATEST_VERSION = 'foo';
|
||||
});
|
||||
@ -846,11 +801,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given an invalid release type', function () {
|
||||
|
||||
it('should be rejected with an error', function (done) {
|
||||
s3Packages.getLatestVersion('foobar').catch((error) => {
|
||||
m.chai.expect(error).to.be.an.instanceof(Error);
|
||||
@ -858,11 +811,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given no remote versions', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
|
||||
this.getRemoteVersionsStub.returns(Bluebird.resolve([]));
|
||||
@ -878,11 +829,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a single version', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
|
||||
this.getRemoteVersionsStub.returns(Bluebird.resolve([ '0.5.0' ]));
|
||||
@ -898,11 +847,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given multiple versions', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
|
||||
this.getRemoteVersionsStub.returns(Bluebird.resolve([
|
||||
@ -923,11 +870,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a greater production version in a snapshot bucket', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
|
||||
this.getRemoteVersionsStub.returns(Bluebird.resolve([
|
||||
@ -946,11 +891,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given a greater snapshot version in a production bucket', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
|
||||
this.getRemoteVersionsStub.returns(Bluebird.resolve([
|
||||
@ -969,11 +912,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given production v1, v2, and v3 remote versions', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
|
||||
this.getRemoteVersionsStub.returns(Bluebird.resolve([
|
||||
@ -1038,11 +979,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given unstable and stable versions where the last version is stable', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
|
||||
this.getRemoteVersionsStub.returns(Bluebird.resolve([
|
||||
@ -1076,11 +1015,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given unstable and stable versions where the last version is unstable', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
|
||||
this.getRemoteVersionsStub.returns(Bluebird.resolve([
|
||||
@ -1115,11 +1052,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given pre-release production remote versions', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
|
||||
this.getRemoteVersionsStub.returns(Bluebird.resolve([
|
||||
@ -1156,11 +1091,9 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('given pre-release snapshot remote versions', function () {
|
||||
|
||||
beforeEach(function () {
|
||||
this.getRemoteVersionsStub = m.sinon.stub(s3Packages, 'getRemoteVersions');
|
||||
this.getRemoteVersionsStub.returns(Bluebird.resolve([
|
||||
@ -1197,9 +1130,6 @@ describe('Shared: s3Packages', function() {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -21,36 +21,28 @@ const _ = require('lodash');
|
||||
const supportedFormats = require('../../lib/shared/supported-formats');
|
||||
|
||||
describe('Shared: SupportedFormats', function () {
|
||||
|
||||
describe('.getCompressedExtensions()', function () {
|
||||
|
||||
it('should return the supported compressed extensions', function () {
|
||||
const extensions = supportedFormats.getCompressedExtensions();
|
||||
m.chai.expect(extensions).to.deep.equal([ 'gz', 'bz2', 'xz' ]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getNonCompressedExtensions()', function () {
|
||||
|
||||
it('should return the supported non compressed extensions', function () {
|
||||
const extensions = supportedFormats.getNonCompressedExtensions();
|
||||
m.chai.expect(extensions).to.deep.equal([ 'img', 'iso', 'dsk', 'hddimg', 'raw', 'dmg', 'sdcard', 'rpi-sdimg' ]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getArchiveExtensions()', function () {
|
||||
|
||||
it('should return the supported archive extensions', function () {
|
||||
const extensions = supportedFormats.getArchiveExtensions();
|
||||
m.chai.expect(extensions).to.deep.equal([ 'zip', 'etch' ]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.getAllExtensions()', function () {
|
||||
|
||||
it('should return the union of all compressed, uncompressed, and archive extensions', function () {
|
||||
const archiveExtensions = supportedFormats.getArchiveExtensions();
|
||||
const compressedExtensions = supportedFormats.getCompressedExtensions();
|
||||
@ -59,11 +51,9 @@ describe('Shared: SupportedFormats', function() {
|
||||
const extensions = supportedFormats.getAllExtensions();
|
||||
m.chai.expect(extensions).to.deep.equal(expected);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.isSupportedImage()', function () {
|
||||
|
||||
_.forEach([
|
||||
|
||||
// Type: 'archive'
|
||||
@ -210,37 +200,29 @@ describe('Shared: SupportedFormats', function() {
|
||||
const isSupported = supportedFormats.isSupportedImage(imagePath);
|
||||
m.chai.expect(isSupported).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.looksLikeWindowsImage()', function () {
|
||||
|
||||
_.each([
|
||||
'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/Win10_1607_SingleLang_English_x32.iso',
|
||||
'/path/to/en_winxp_pro_x86_build2600_iso.img'
|
||||
], (imagePath) => {
|
||||
|
||||
it(`should return true if filename is ${imagePath}`, function () {
|
||||
const looksLikeWindowsImage = supportedFormats.looksLikeWindowsImage(imagePath);
|
||||
m.chai.expect(looksLikeWindowsImage).to.be.true;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
_.each([
|
||||
'C:\\path\\to\\2017-01-11-raspbian-jessie.img',
|
||||
'/path/to/2017-01-11-raspbian-jessie.img'
|
||||
], (imagePath) => {
|
||||
|
||||
it(`should return false if filename is ${imagePath}`, function () {
|
||||
const looksLikeWindowsImage = supportedFormats.looksLikeWindowsImage(imagePath);
|
||||
m.chai.expect(looksLikeWindowsImage).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -20,9 +20,7 @@ const m = require('mochainon');
|
||||
const units = require('../../lib/shared/units');
|
||||
|
||||
describe('Shared: Units', function () {
|
||||
|
||||
describe('.bytesToClosestUnit()', function () {
|
||||
|
||||
it('should convert bytes to terabytes', function () {
|
||||
m.chai.expect(units.bytesToClosestUnit(1000000000000)).to.equal('1 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(999)).to.equal('999 B');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.bytesToMegabytes()', function () {
|
||||
|
||||
it('should convert bytes to megabytes', function () {
|
||||
m.chai.expect(units.bytesToMegabytes(1.2e+7)).to.equal(12);
|
||||
m.chai.expect(units.bytesToMegabytes(332000)).to.equal(0.332);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -20,9 +20,7 @@ const m = require('mochainon');
|
||||
const utils = require('../../lib/shared/utils');
|
||||
|
||||
describe('Shared: Utils', function () {
|
||||
|
||||
describe('.isValidPercentage()', function () {
|
||||
|
||||
it('should return false if percentage is not a number', function () {
|
||||
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 () {
|
||||
m.chai.expect(utils.isValidPercentage(100.001)).to.be.false;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('.percentageToFloat()', function () {
|
||||
|
||||
it('should throw an error if given a string percentage', function () {
|
||||
m.chai.expect(function () {
|
||||
utils.percentageToFloat('50');
|
||||
@ -128,7 +124,5 @@ describe('Shared: Utils', function() {
|
||||
utils.percentageToFloat(100.01);
|
||||
}).to.throw('Invalid percentage: 100.01');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user