Skip to content

Instantly share code, notes, and snippets.

@joewalker
Last active December 11, 2015 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joewalker/4625035 to your computer and use it in GitHub Desktop.
Save joewalker/4625035 to your computer and use it in GitHub Desktop.
An example of the new way to write GCLI tests
/**
* An example of the new way to write GCLI tests
*/
var promise = helpers.audit([ // Tests can be async. They're done when the promise resolves
{
name: 'a test', // Optional test name, we'll use the 'setup' string if there is no name
setup: 'help search', // A string to type (which can include control chars like <TAB>),
// or a function to do custom setup. return a promise to be async
skipIf: function() { ... }, // If you need to skip tests in some cases e.g. private browsing
check: { // Some stuff to check ...
hints: ' [search]', // Here's what the hints should look like
markup: 'VVVV', // Each char in the input has a status Valid, Incomplete, Error
// This is a map which proves we know where the error lies
status: 'VALID', // What is the overall status? VALID or ERROR
error: '', // If there is an error, what is the error message
args: { // An map of expected values, and how we interpret them
search: { // This is how we expect the 'search' arg to be interpreted
value: undefined, // The value passed to the command's exec function
arg: '', // What the user typed to get to the value
status: 'VALID', // Do we think this argument is a VALID or an ERROR
message: '' // If an error, what's the error message?
} // Other checks are available, see helpers.js for details
} // helpers.js can be used to generate test cases too. See source for details
},
exec: { // Optional: If there's an 'exec', then we execute what was typed above
output: '', // What output are we expecting. This can be a string for an exact match
// or a regexp or an array of regexps which must match
completed: true, // Do we expect the command to complete sync or async
},
post: function() { // Optional tests to run after all the above has happened
return promise; // Return a promise if the tests run async
}
},
{
name: 'the next test', // You can string as many of these together as you like
// ...
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment