Created
November 18, 2015 12:04
-
-
Save salzhrani/6303cfd3ddd3d432127f to your computer and use it in GitHub Desktop.
Create sublime text completions for nightwatch.js from the console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note, the formatted will be in the clipboard