Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
sync-1230993: Split out file mockCommands
Browse files Browse the repository at this point in the history
We don't want the mock commands that test the filesystem to be used in
the browser.

Signed-off-by: Joe Walker <jwalker@mozilla.com>
  • Loading branch information
joewalker committed Dec 7, 2015
1 parent 934ac88 commit c1c9ece
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 101 deletions.
12 changes: 12 additions & 0 deletions lib/gcli/commands/mocks.js
Expand Up @@ -18,9 +18,13 @@

var cli = require('../cli');
var mockCommands = require('../test/mockCommands');
var mockFileCommands = require('../test/mockFileCommands');
var mockSettings = require('../test/mockSettings');
var mockDocument = require('../test/mockDocument');

var isNode = (typeof(process) !== 'undefined' &&
process.title.indexOf('node') != -1);

exports.items = [
{
item: 'command',
Expand Down Expand Up @@ -48,12 +52,20 @@ exports.items = [
mockCommands.setup(requisition);
mockSettings.setup(requisition.system);
mockDocument.setup(requisition);

if (isNode) {
mockFileCommands.setup(requisition);
}
},

off: function(requisition) {
mockCommands.shutdown(requisition);
mockSettings.shutdown(requisition.system);
mockDocument.shutdown(requisition);

if (isNode) {
mockFileCommands.shutdown(requisition);
}
}
}
];
5 changes: 5 additions & 0 deletions lib/gcli/commands/server/firefox.js
Expand Up @@ -105,6 +105,11 @@ function buildFirefox(destDir) {
filter: commonJsToJsMockFilter,
dest: (destDir ? destDir + testDir : 'built/ff') + '/mockCommands.js'
});
copy({
source: 'lib/gcli/test/mockFileCommands.js',
filter: commonJsToJsMockFilter,
dest: (destDir ? destDir + testDir : 'built/ff') + '/mockFileCommands.js'
});

// Package the i18n strings
copy({
Expand Down
101 changes: 0 additions & 101 deletions lib/gcli/test/mockCommands.js
Expand Up @@ -582,107 +582,6 @@ mockCommands.items = [
return 'no error';
}
},
{
item: 'command',
name: 'tsfile',
description: 'test file params',
},
{
item: 'command',
name: 'tsfile open',
description: 'a file param in open mode',
params: [
{
name: 'p1',
type: {
name: 'file',
filetype: 'file',
existing: 'yes'
}
}
],
exec: createExec('tsfile open')
},
{
item: 'command',
name: 'tsfile saveas',
description: 'a file param in saveas mode',
params: [
{
name: 'p1',
type: {
name: 'file',
filetype: 'file',
existing: 'no'
}
}
],
exec: createExec('tsfile saveas')
},
{
item: 'command',
name: 'tsfile save',
description: 'a file param in save mode',
params: [
{
name: 'p1',
type: {
name: 'file',
filetype: 'file',
existing: 'maybe'
}
}
],
exec: createExec('tsfile save')
},
{
item: 'command',
name: 'tsfile cd',
description: 'a file param in cd mode',
params: [
{
name: 'p1',
type: {
name: 'file',
filetype: 'directory',
existing: 'yes'
}
}
],
exec: createExec('tsfile cd')
},
{
item: 'command',
name: 'tsfile mkdir',
description: 'a file param in mkdir mode',
params: [
{
name: 'p1',
type: {
name: 'file',
filetype: 'directory',
existing: 'no'
}
}
],
exec: createExec('tsfile mkdir')
},
{
item: 'command',
name: 'tsfile rm',
description: 'a file param in rm mode',
params: [
{
name: 'p1',
type: {
name: 'file',
filetype: 'any',
existing: 'yes'
}
}
],
exec: createExec('tsfile rm')
},
{
item: 'command',
name: 'tsslow',
Expand Down
170 changes: 170 additions & 0 deletions lib/gcli/test/mockFileCommands.js
@@ -0,0 +1,170 @@
/*
* Copyright 2012, Mozilla Foundation and contributors
*
* 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';

var mockCommands;
if (typeof exports !== 'undefined') {
// If we're being loaded via require();
mockCommands = exports;
}
else {
// If we're being loaded via loadScript in mochitest
mockCommands = {};
}

// We use an alias for exports here because this module is used in Firefox
// mochitests where we don't have define/require

/**
* Registration and de-registration.
*/
mockCommands.setup = function(requisition) {
requisition.system.addItems(mockCommands.items);
};

mockCommands.shutdown = function(requisition) {
requisition.system.removeItems(mockCommands.items);
};

function createExec(name) {
return function(args, context) {
var promises = [];

Object.keys(args).map(function(argName) {
var value = args[argName];
var type = this.getParameterByName(argName).type;
var promise = Promise.resolve(type.stringify(value, context));
promises.push(promise.then(function(str) {
return { name: argName, value: str };
}.bind(this)));
}.bind(this));

return Promise.all(promises).then(function(data) {
var argValues = {};
data.forEach(function(entry) { argValues[entry.name] = entry.value; });

return context.typedData('testCommandOutput', {
name: name,
args: argValues
});
}.bind(this));
};
}

mockCommands.items = [
{
item: 'command',
name: 'tsfile',
description: 'test file params',
},
{
item: 'command',
name: 'tsfile open',
description: 'a file param in open mode',
params: [
{
name: 'p1',
type: {
name: 'file',
filetype: 'file',
existing: 'yes'
}
}
],
exec: createExec('tsfile open')
},
{
item: 'command',
name: 'tsfile saveas',
description: 'a file param in saveas mode',
params: [
{
name: 'p1',
type: {
name: 'file',
filetype: 'file',
existing: 'no'
}
}
],
exec: createExec('tsfile saveas')
},
{
item: 'command',
name: 'tsfile save',
description: 'a file param in save mode',
params: [
{
name: 'p1',
type: {
name: 'file',
filetype: 'file',
existing: 'maybe'
}
}
],
exec: createExec('tsfile save')
},
{
item: 'command',
name: 'tsfile cd',
description: 'a file param in cd mode',
params: [
{
name: 'p1',
type: {
name: 'file',
filetype: 'directory',
existing: 'yes'
}
}
],
exec: createExec('tsfile cd')
},
{
item: 'command',
name: 'tsfile mkdir',
description: 'a file param in mkdir mode',
params: [
{
name: 'p1',
type: {
name: 'file',
filetype: 'directory',
existing: 'no'
}
}
],
exec: createExec('tsfile mkdir')
},
{
item: 'command',
name: 'tsfile rm',
description: 'a file param in rm mode',
params: [
{
name: 'p1',
type: {
name: 'file',
filetype: 'any',
existing: 'yes'
}
}
],
exec: createExec('tsfile rm')
},
];

0 comments on commit c1c9ece

Please sign in to comment.