Skip to content

Instantly share code, notes, and snippets.

@salzhrani
Created November 18, 2015 12:04
Show Gist options
  • Select an option

  • Save salzhrani/6303cfd3ddd3d432127f to your computer and use it in GitHub Desktop.

Select an option

Save salzhrani/6303cfd3ddd3d432127f to your computer and use it in GitHub Desktop.
Create sublime text completions for nightwatch.js from the console
var methods = document.querySelectorAll('.assertions .apimethod');
methods = Array.from(methods);
var assertions = methods.map(function(method){
var args = Array.from(method.querySelectorAll('table code'));
return {
name: method.querySelector('h3 code').textContent,
args: args.map(function(table){ return table.textContent}),
};
});
assertions = assertions
.map(function(assertion){
return {trigger: '.' + assertion.name, contents: '.assert.' + assertion.name + '(' + assertion.args.map(function(arg, idx) { return '${' + (idx + 1) + ':' + (idx === 0 ? '' : ', ') + arg + '}'}).join('') + ')'}
});
var commands = Array.from(document.querySelectorAll('.commands .apimethod, .protocolcommands .apimethod'))
.map(function(method){
var args = Array.from(method.querySelectorAll('table code'));
return {
name: method.querySelector('h3 code').textContent,
args: args.map(function(table){ return table.textContent}),
};
})
.map(function(command) {
return {trigger: '.' + command.name, contents: '.' + command.name + '(' + command.args.map(function(arg, idx) { return '${' + (idx + 1) + ':' + (idx === 0 ? '' : ', ') + arg + '}'}).join('') + ')'}
});
copy( JSON.stringify({ scope: 'source.js', completions: assertions.concat(commands)}, null, '\t'))
@salzhrani

Copy link
Copy Markdown
Author

Note, the formatted will be in the clipboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment