Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

marionette-file-manager

Package Overview
Dependencies
Maintainers
6
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

marionette-file-manager - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.travis.yml

2

index.js

@@ -10,3 +10,3 @@ var fileManagerFactory = require('./lib/file_manager_factory'),

* @param {Marionette.Client} client marionette client to use.
* @param {Object} [options] setup the file manager.
* @param {Object} options setup the file manager.
*/

@@ -13,0 +13,0 @@ function MarionetteFileManager(client, options) {

@@ -45,3 +45,2 @@ const TESTING_DIRECTORY = 'device-storage-testing';

getDeviceStoragePath: function() {
console.log('this._getTemporaryPath():' + this._getTemporaryPath());
return path.join(this._getTemporaryPath(), TESTING_DIRECTORY);

@@ -48,0 +47,0 @@ },

@@ -7,2 +7,3 @@ var fs = require('fs'),

*
* @constructor
* @param {DeviceStorageFactory.DeviceStorage} deviceStorage

@@ -77,3 +78,11 @@ * the implementation of the device storage.

removeAllFiles: function() {
this._removeFile(this.deviceStorage.getDeviceStoragePath());
var deviceStoragePath = this.deviceStorage.getDeviceStoragePath(),
fileList = [];
if (fs.existsSync(deviceStoragePath)) {
fileList = fs.readdirSync(deviceStoragePath);
fileList.forEach(function(item) {
this._removeFile(path.join(deviceStoragePath, item));
}.bind(this));
}
},

@@ -80,0 +89,0 @@

@@ -9,2 +9,7 @@ /**

var DeviceStorageFactory = {
/**
* Generate a instance of device storage.
*
* @return {Object} instance of device storage.
*/
generate: function(client, type) {

@@ -19,2 +24,3 @@ return DeviceStorageFactory[type](client);

* @param {Object} client the marionette client.
* @return {Object} instance of DesktopClientDeviceStorage.
*/

@@ -21,0 +27,0 @@ DeviceStorageFactory.DesktopClient = function(client) {

@@ -9,2 +9,7 @@ /**

var FileManagerFactory = {
/**
* Generate a instance of file manager.
*
* @return {Object} instance of file manager.
*/
generate: function(deviceStorage, type) {

@@ -19,2 +24,3 @@ return FileManagerFactory[type](deviceStorage);

* @param {Object} deviceStorage desktop client deviceStorage.
* @return {Object} instance of DesktopClientFileManager.
*/

@@ -21,0 +27,0 @@ FileManagerFactory.DesktopClient = function(deviceStorage) {

{
"name": "marionette-file-manager",
"version": "0.0.1",
"version": "0.0.2",
"author": {

@@ -10,3 +10,3 @@ "name": "Evan Tseng",

"main": "index.js",
"script": {
"scripts": {
"test": "make"

@@ -13,0 +13,0 @@ },

@@ -1,12 +0,28 @@

#marionette-file-manager
# marionette-file-manager
A marionette plugin to manage(add, remove) files in device storage.
#Usage
# Usage
### Setup
```
var clinet; // A marionette client.
client.plugin('fileManager', require('marionette-file-manager'));
/**
* For Gaia usage, please setup the plugin in
* https://github.com/mozilla-b2g/gaia/blob/master/shared/test/integration/setup.js.
*/
marionette.plugin('fileManager', require('marionette-file-manager'));
```
// Add two files into the pictures directory.
### Add files into the specified directory
```
/**
* The marionette-file-manager plugin will handle the directory things,
* we do not need to create or remove the directort manually.
*
* After do the below script,
* we will have the two files in the path/to/device-storage/pictures directory.
*
* And we could just use { type: 'other-directory', filePath: 'path/to/file1' } to
* add files into the "other-directory" directory.
*/
client.fileManager.add([

@@ -16,3 +32,6 @@ { type: 'pictures', filePath: 'path/to/file1' },

]);
```
### Remove files
```
// Remove the filename2 file from pictures directory.

@@ -19,0 +38,0 @@ client.fileManager.remove({ type: 'pictures', filename: 'filename2' });

@@ -1,7 +0,1 @@

const TEST_FILES_PATH = '../test_files',
TEXT_FILE_NAME = 'hello_world.json',
IMAGE_FILE_NAME = 'fxos.png',
PICTURES_TYPE = 'pictures',
TEXT_TYPE = 'text';
var assert = require('assert'),

@@ -13,2 +7,11 @@ fs = require('fs'),

const TEST_FILES_PATH = '../test_files',
TEXT_FILE_NAME = 'hello_world.json',
IMAGE_FILE_NAME = 'fxos.png',
PICTURES_TYPE = 'pictures',
TEXT_TYPE = 'text',
DS_FILE_PATH = path.join(TEXT_TYPE, TEXT_FILE_NAME),
TEST_FILE_PATH =
path.join(__dirname, TEST_FILES_PATH, TEXT_FILE_NAME);
suite('MarionetteFileManager', function() {

@@ -44,6 +47,2 @@ var testFilePath =

test('should get the file from device storage', function() {
const DS_FILE_PATH = path.join(TEXT_TYPE, TEXT_FILE_NAME),
TEST_FILE_PATH =
path.join(__dirname, TEST_FILES_PATH, TEXT_FILE_NAME);
client.fileManager.add({

@@ -99,2 +98,19 @@ type: TEXT_TYPE,

});
test('could add file after do removeAllFiles', function() {
client.fileManager.removeAllFiles();
client.fileManager.add({
type: TEXT_TYPE,
filePath: path.join(__dirname, TEST_FILES_PATH, TEXT_FILE_NAME)
});
client.executeAsyncScript(
getFileFromDeviceStorage,
[DS_FILE_PATH],
function(error, value) {
var expectedContent = fs.readFileSync(TEST_FILE_PATH).toString();
assert.deepEqual(value.file.toString(), expectedContent);
}
);
});
});

@@ -101,0 +117,0 @@

@@ -24,4 +24,4 @@ var fs = require('fs'),

fileList.forEach(function(item) {
this.removeFile(filePath + '/' + item);
}.bind(this));
TestHelper.removeFile(filePath + '/' + item);
});
} else {

@@ -28,0 +28,0 @@ fs.unlinkSync(filePath);

@@ -81,4 +81,4 @@ const DEVICE_STORAGE_PATH = __dirname + '/devicestorage',

fileList = fs.readdirSync(deviceStorage.getMediaFilePath(PICTURES_TYPE));
assert.deepEqual(TEST_FILE_1, fileList[0]);
assert.deepEqual(TEST_FILE_2, fileList[1]);
assert.ok(fileList.indexOf(TEST_FILE_1) !== -1);
assert.ok(fileList.indexOf(TEST_FILE_2) !== -1);
});

@@ -108,3 +108,13 @@ });

suite('#removeAllFiles', function() {
setup(function() {
test('should have device storage directory', function() {
subject.removeAllFiles();
assert.ok(fs.existsSync(DEVICE_STORAGE_PATH));
});
test('should work when no file in device storage', function() {
subject.removeAllFiles();
assert.ok(fs.readdirSync(DEVICE_STORAGE_PATH).length === 0);
});
test('should remove all files in device storage', function() {
subject.add({

@@ -114,8 +124,4 @@ type: PICTURES_TYPE,

});
});
test('should remove all files in device storage', function() {
subject.removeAllFiles();
// XXX: Could not be passed by the below assert.
// assert.ok(!fs.existsSync(DEVICE_STORAGE_PATH));
assert.ok(fs.readdirSync(DEVICE_STORAGE_PATH).length === 0);

@@ -122,0 +128,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc