Skip to content
This repository was archived by the owner on Jun 28, 2022. It is now read-only.

Commit 2cc420c

Browse files
committed
Merge branch 'remotetest-874821' into landing
2 parents 2ed4d3b + 5997649 commit 2cc420c

24 files changed

Lines changed: 886 additions & 322 deletions

File tree

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11

22
language: node_js
33
node_js:
4+
- "0.10"
45
- "0.8"
6+
before_script:
7+
- "node gcli.js server start --allowexec --websocket &"
58
script:
6-
- "node gcli.js test && phantomjs ./phantom-test.js"
9+
- "node gcli.js test && phantomjs ./phantom-test.js && phantomjs ./phantom-test.js --http"
10+
after_script:
11+
- "phantomjs ./phantom-test.js --shutdown"
712

lib/demo/commands/basic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ var sleep = {
100100
description: 'How long to wait (s)'
101101
}
102102
],
103-
returnType: 'html',
103+
returnType: 'string',
104104
exec: function(args, context) {
105105
var deferred = context.defer();
106106
window.setTimeout(function() {
107-
deferred.resolve('done');
107+
deferred.resolve('Done');
108108
}, args.length * 1000);
109109
return deferred.promise;
110110
}

lib/gcli/canon.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ Canon.prototype.addProxyCommands = function(prefix, commandSpecs, remoter, to) {
453453
names.forEach(function(name) {
454454
var commandSpec = commandSpecs[name];
455455

456+
if (commandSpec.noRemote) {
457+
return;
458+
}
459+
456460
if (!commandSpec.isParent) {
457461
commandSpec.exec = function(args, context) {
458462
context.commandName = name;

lib/gcli/cli.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ Requisition.prototype.complete = function(cursor, predictionChoice) {
887887
outstanding.push(promise);
888888
}
889889

890-
return util.all(outstanding).then(function() {
890+
return Promise.all(outstanding).then(function() {
891891
this.onTextChange();
892892
this.onTextChange.resumeFire();
893893
}.bind(this));
@@ -1704,19 +1704,19 @@ Requisition.prototype._assign = function(args) {
17041704

17051705
if (!this.commandAssignment.value) {
17061706
this._addUnassignedArgs(args);
1707-
return util.all(outstanding);
1707+
return Promise.all(outstanding);
17081708
}
17091709

17101710
if (args.length === 0) {
17111711
this.setBlankArguments();
1712-
return util.all(outstanding);
1712+
return Promise.all(outstanding);
17131713
}
17141714

17151715
// Create an error if the command does not take parameters, but we have
17161716
// been given them ...
17171717
if (this.assignmentCount === 0) {
17181718
this._addUnassignedArgs(args);
1719-
return util.all(outstanding);
1719+
return Promise.all(outstanding);
17201720
}
17211721

17221722
// Special case: if there is only 1 parameter, and that's of type
@@ -1726,7 +1726,7 @@ Requisition.prototype._assign = function(args) {
17261726
if (assignment.param.type.name === 'string') {
17271727
var arg = (args.length === 1) ? args[0] : new MergedArgument(args);
17281728
outstanding.push(this.setAssignment(assignment, arg, noArgUp));
1729-
return util.all(outstanding);
1729+
return Promise.all(outstanding);
17301730
}
17311731
}
17321732

@@ -1833,7 +1833,7 @@ Requisition.prototype._assign = function(args) {
18331833
// What's left is can't be assigned, but we need to extract
18341834
this._addUnassignedArgs(args);
18351835

1836-
return util.all(outstanding);
1836+
return Promise.all(outstanding);
18371837
};
18381838

18391839
exports.Requisition = Requisition;

lib/gcli/commands/connect.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ var connect = {
8585
createRemoter: function(prefix, connection) {
8686
return function(cmdArgs, context) {
8787
var typed = context.typed;
88-
if (typed.indexOf(prefix) !== 0) {
89-
throw new Error("Missing prefix");
88+
89+
// If we've been called using a 'context' then there will be no prefix
90+
// otherwise we need to remove it
91+
if (typed.indexOf(prefix) === 0) {
92+
typed = typed.substring(prefix.length).replace(/^ */, "");
9093
}
91-
typed = typed.substring(prefix.length).replace(/^ */, "");
9294

9395
return connection.execute(typed, cmdArgs).then(function(reply) {
9496
var typedData = context.typedData(reply.type, reply.data);
@@ -128,12 +130,19 @@ var disconnect = {
128130
name: 'prefix',
129131
type: 'connection',
130132
description: l10n.lookup('disconnectPrefixDesc'),
133+
},
134+
{
135+
name: 'force',
136+
type: 'boolean',
137+
description: l10n.lookup('disconnectForceDesc'),
138+
hidden: connector.disconnectSupportsForce,
139+
option: true
131140
}
132141
],
133142
returnType: 'string',
134143

135144
exec: function(args, context) {
136-
return args.prefix.disconnect().then(function() {
145+
return args.prefix.disconnect(args.force).then(function() {
137146
var removed = canon.removeProxyCommands(args.prefix.prefix);
138147
delete connections[args.prefix.prefix];
139148
return l10n.lookupFormat('disconnectReply', [ removed.length ]);

lib/gcli/commands/context.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var contextCmdSpec = {
3737
}
3838
],
3939
returnType: 'string',
40+
noRemote: true,
4041
exec: function echo(args, context) {
4142
// Do not copy this code
4243
var requisition = context.__dlhjshfw;

lib/gcli/converters.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ var terminalDomConverter = {
110110
}
111111
};
112112

113+
/**
114+
* Convert a terminal object to a string
115+
*/
116+
var terminalStringConverter = {
117+
from: 'terminal',
118+
to: 'string',
119+
exec: function(data, context) {
120+
return Array.isArray(data) ? data.join('') : '' + data;
121+
}
122+
};
123+
113124
/**
114125
* Several converters are just data.toString inside a 'p' element
115126
*/
@@ -289,6 +300,7 @@ exports.convert = function(data, from, to, conversionContext) {
289300
exports.addConverter(viewDomConverter);
290301
exports.addConverter(viewStringConverter);
291302
exports.addConverter(terminalDomConverter);
303+
exports.addConverter(terminalStringConverter);
292304
exports.addConverter(stringDomConverter);
293305
exports.addConverter(numberDomConverter);
294306
exports.addConverter(booleanDomConverter);

lib/gcli/nls/strings.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,19 @@ var i18n = {
272272
// which is why it should be as short as possible.
273273
disconnectPrefixDesc: 'Parent prefix for imported commands',
274274

275+
// A short description of the 'force' parameter to the 'disconnect' command.
276+
// This string is designed to be shown in a dialog with restricted space,
277+
// which is why it should be as short as possible.
278+
disconnectForceDesc: 'Ignore outstanding requests',
279+
275280
// The output of the 'disconnect' command, telling the user what it's done.
276281
disconnectReply: 'Removed %S commands.',
277282

283+
// An error message displayed when the user attempts to disconnect before
284+
// all requests have completed.
285+
// %1$S is a list of commands which are incomplete
286+
disconnectOutstanding: 'Outstanding requests (%1$S)',
287+
278288
// A very short description of the 'cd' command.
279289
// This string is designed to be shown in a menu alongside the command name,
280290
// which is why it should be as short as possible.

lib/gcli/types/basic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ ArrayType.prototype.parse = function(arg, context) {
449449
}.bind(this);
450450

451451
var conversionPromises = arg.getArguments().map(subArgParse);
452-
return util.all(conversionPromises).then(function(conversions) {
452+
return Promise.all(conversionPromises).then(function(conversions) {
453453
return new ArrayConversion(conversions, arg);
454454
});
455455
};

lib/gclitest/helpers.js

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ helpers._actual = {
226226
.replace(/ $/, '');
227227
};
228228

229-
var promisedJoin = util.promised(join);
229+
var promisedJoin = Promise.promised(join);
230230
return promisedJoin(templateData.directTabText,
231231
templateData.emptyParameters,
232232
templateData.arrowTabText);
@@ -314,12 +314,12 @@ helpers._createDebugCheck = function(options) {
314314
var hintsPromise = helpers._actual.hints(options);
315315
var predictionsPromise = helpers._actual.predictions(options);
316316

317-
return util.all(hintsPromise, predictionsPromise).then(function(values) {
317+
return Promise.all(hintsPromise, predictionsPromise).then(function(values) {
318318
var hints = values[0];
319319
var predictions = values[1];
320320
var output = '';
321321

322-
output += 'helpers.audit(options, [\n';
322+
output += 'return helpers.audit(options, [\n';
323323
output += ' {\n';
324324

325325
if (cursor === input.length) {
@@ -627,13 +627,14 @@ helpers._check = function(options, name, checks) {
627627
Object.keys(checks.args).forEach(function(paramName) {
628628
var check = checks.args[paramName];
629629

630-
var assignment;
631-
if (paramName === 'command') {
630+
// We allow an 'argument' called 'command' to be the command itself, but
631+
// what if the command has a parameter called 'command' (for example, an
632+
// 'exec' command)? We default to using the parameter because checking
633+
// the command value is less useful
634+
var assignment = requisition.getAssignment(paramName);
635+
if (assignment == null && paramName === 'command') {
632636
assignment = requisition.commandAssignment;
633637
}
634-
else {
635-
assignment = requisition.getAssignment(paramName);
636-
}
637638

638639
if (assignment == null) {
639640
assert.ok(false, 'Unknown arg: ' + paramName + suffix);
@@ -699,7 +700,7 @@ helpers._check = function(options, name, checks) {
699700
});
700701
}
701702

702-
return util.all(outstanding).then(function() {
703+
return Promise.all(outstanding).then(function() {
703704
// Ensure the promise resolves to nothing
704705
return undefined;
705706
});
@@ -717,7 +718,16 @@ helpers._exec = function(options, name, expected) {
717718
return Promise.resolve({});
718719
}
719720

720-
var output = options.display.requisition.exec({ hidden: true });
721+
var output;
722+
try {
723+
output = options.display.requisition.exec({ hidden: true });
724+
}
725+
catch (ex) {
726+
assert.ok(false, 'Failure executing \'' + name + '\': ' + ex);
727+
util.errorHandler(ex);
728+
729+
return Promise.resolve({});
730+
}
721731

722732
if ('completed' in expected) {
723733
assert.is(output.completed,
@@ -735,9 +745,6 @@ helpers._exec = function(options, name, expected) {
735745
}
736746

737747
var checkOutput = function() {
738-
var div = options.window.document.createElement('div');
739-
var conversionContext = options.display.requisition.conversionContext;
740-
741748
if ('type' in expected) {
742749
assert.is(output.type,
743750
expected.type,
@@ -750,20 +757,20 @@ helpers._exec = function(options, name, expected) {
750757
'output.error for: ' + name);
751758
}
752759

760+
var conversionContext = options.display.requisition.conversionContext;
753761
var convertPromise = converters.convert(output.data, output.type, 'dom',
754762
conversionContext);
755763
return convertPromise.then(function(node) {
756-
div.appendChild(node);
757-
var actualOutput = div.textContent.trim();
764+
var actualOutput = node.textContent.trim();
758765

759766
var doTest = function(match, against) {
760767
if (match.test(against)) {
761-
assert.ok(true, 'html output for ' + name + ' should match ' +
762-
match.source);
768+
assert.ok(true, 'html output for ' + name + ' should match /' +
769+
match.source + '/');
763770
} else {
764-
assert.ok(false, 'html output for ' + name + ' should match ' +
771+
assert.ok(false, 'html output for ' + name + ' should match /' +
765772
match.source +
766-
'. Actual textContent: "' + against + '"');
773+
'/. Actual textContent: "' + against + '"');
767774
}
768775
};
769776

@@ -820,11 +827,13 @@ var totalResponseTime = 0;
820827
var averageOver = 0;
821828
var maxResponseTime = 0;
822829
var maxResponseCulprit = undefined;
830+
var start = undefined;
823831

824832
/**
825833
* Restart the stats collection process
826834
*/
827835
helpers.resetResponseTimes = function() {
836+
start = new Date().getTime();
828837
totalResponseTime = 0;
829838
averageOver = 0;
830839
maxResponseTime = 0;
@@ -859,6 +868,20 @@ Object.defineProperty(helpers, 'maxResponseCulprit', {
859868
enumerable: true
860869
});
861870

871+
/**
872+
* Quick summary of the times
873+
*/
874+
Object.defineProperty(helpers, 'timingSummary', {
875+
get: function() {
876+
var elapsed = (new Date().getTime() - start) / 1000;
877+
return 'Total ' + elapsed + 's, ' +
878+
'ave response ' + helpers.averageResponseTime + 'ms, ' +
879+
'max response ' + helpers.maxResponseTime + 'ms ' +
880+
'from \'' + helpers.maxResponseCulprit + '\'';
881+
},
882+
enumerable: true
883+
});
884+
862885
/**
863886
* A way of turning a set of tests into something more declarative, this helps
864887
* to allow tests to be asynchronous.

0 commit comments

Comments
 (0)