mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-26 15:24:05 +02:00
Add --vagrant switch to the javascript test-runner
Added -V|--vagrant switch to the javascript test-runner to run the tests in the Vagrant VM refs #4264
This commit is contained in:
parent
a7a8836b5b
commit
d7ebe7fa08
110
test/js/runtests
110
test/js/runtests
@ -3,12 +3,14 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from pipes import quote
|
||||||
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
|
from optparse import OptionParser, BadOptionError, AmbiguousOptionError
|
||||||
|
|
||||||
|
|
||||||
APPLICATION = 'mocha'
|
APPLICATION = 'mocha'
|
||||||
DEFAULT_ARGS = ['--recursive', '--require', 'should']
|
DEFAULT_ARGS = ['--recursive', '--require', 'should']
|
||||||
|
|
||||||
|
VAGRANT_SCRIPT = '/vagrant/test/js/runtests'
|
||||||
REPORT_DIRECTORY = '../../build/log'
|
REPORT_DIRECTORY = '../../build/log'
|
||||||
|
|
||||||
|
|
||||||
@ -69,62 +71,78 @@ def parse_commandline():
|
|||||||
parser.add_option('-e', '--exclude', metavar='PATTERN', action='append',
|
parser.add_option('-e', '--exclude', metavar='PATTERN', action='append',
|
||||||
help='Exclude specific files/test cases. '
|
help='Exclude specific files/test cases. '
|
||||||
'(Can be supplied multiple times.)')
|
'(Can be supplied multiple times.)')
|
||||||
|
parser.add_option('-V', '--vagrant', action='store_true',
|
||||||
|
help='Run in vagrant VM')
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
options, arguments = parse_commandline()
|
options, arguments = parse_commandline()
|
||||||
|
|
||||||
# Environment preparation and verification
|
if options.vagrant and os.environ['USER'] != 'vagrant':
|
||||||
os.chdir(get_script_directory())
|
# Check if vagrant is installed
|
||||||
application_path = execute_command('which {0}'.format(APPLICATION),
|
vagrant_path = execute_command('which vagrant', True, True).strip()
|
||||||
True, True).strip()
|
if not vagrant_path:
|
||||||
if not application_path:
|
print 'ERROR: vagrant not found!'
|
||||||
print 'ERROR: {0} not found!'.format(APPLICATION)
|
return 2
|
||||||
return 2
|
|
||||||
os.environ['NODE_PATH'] = os.environ.get('NODE_PATH', '') + \
|
|
||||||
':/usr/local/lib/node_modules' \
|
|
||||||
':/usr/local/share/npm/lib/node_modules' \
|
|
||||||
':/usr/lib/node_modules:./testlib'
|
|
||||||
|
|
||||||
# Commandline preparation
|
# Call the script in the Vagrant VM with the same parameters
|
||||||
command_options, more_command_options = [], None
|
commandline = ' '.join(quote(p) for p in sys.argv[1:])
|
||||||
if options.include or options.exclude:
|
return execute_command('vagrant ssh -c "{0} {1}"'
|
||||||
for pattern in (options.include or options.exclude):
|
''.format(VAGRANT_SCRIPT, commandline),
|
||||||
command_options.append('--grep')
|
shell=True)
|
||||||
command_options.append(pattern)
|
|
||||||
if options.exclude:
|
|
||||||
command_options.append('--invert')
|
|
||||||
if options.build:
|
|
||||||
more_command_options = command_options[:len(command_options)] + \
|
|
||||||
['--reporter', 'mocha-cobertura-reporter']
|
|
||||||
command_options.extend(['--reporter', 'xunit'])
|
|
||||||
elif options.verbose:
|
|
||||||
command_options.extend(['--reporter', 'spec'])
|
|
||||||
else:
|
else:
|
||||||
command_options.extend(['--reporter', 'nyan'])
|
# Environment preparation and verification
|
||||||
if not any(os.path.isfile(a) or os.path.isdir(a) for a in arguments):
|
os.chdir(get_script_directory())
|
||||||
arguments.append('.')
|
application_path = execute_command('which {0}'.format(APPLICATION),
|
||||||
|
True, True).strip()
|
||||||
|
if not application_path:
|
||||||
|
print 'ERROR: {0} not found!'.format(APPLICATION)
|
||||||
|
return 2
|
||||||
|
os.environ['NODE_PATH'] = os.environ.get('NODE_PATH', '') + \
|
||||||
|
':/usr/local/lib/node_modules' \
|
||||||
|
':/usr/local/share/npm/lib/node_modules' \
|
||||||
|
':/usr/lib/node_modules:./testlib'
|
||||||
|
|
||||||
# Application invocation..
|
# Commandline preparation
|
||||||
if more_command_options is None:
|
command_options, more_command_options = [], None
|
||||||
execute_command([application_path] + DEFAULT_ARGS +
|
if options.include or options.exclude:
|
||||||
command_options + arguments)
|
for pattern in (options.include or options.exclude):
|
||||||
else:
|
command_options.append('--grep')
|
||||||
result_data = execute_command([application_path] + DEFAULT_ARGS +
|
command_options.append(pattern)
|
||||||
command_options + arguments, True)
|
if options.exclude:
|
||||||
coverage_data = execute_command([application_path] + DEFAULT_ARGS +
|
command_options.append('--invert')
|
||||||
more_command_options + arguments, True)
|
if options.build:
|
||||||
# Result storage
|
more_command_options = command_options[:len(command_options)] + \
|
||||||
report_directory = get_report_directory()
|
['--reporter', 'mocha-cobertura-reporter']
|
||||||
result_path = os.path.join(report_directory, 'mocha_results.xml')
|
command_options.extend(['--reporter', 'xunit'])
|
||||||
coverage_path = os.path.join(report_directory, 'mocha_coverage.xml')
|
elif options.verbose:
|
||||||
with open(result_path, 'w') as result_file:
|
command_options.extend(['--reporter', 'spec'])
|
||||||
result_file.write(result_data)
|
else:
|
||||||
with open(coverage_path, 'w') as coverage_file:
|
command_options.extend(['--reporter', 'nyan'])
|
||||||
coverage_file.write(coverage_data)
|
if not any(os.path.isfile(a) or os.path.isdir(a) for a in arguments):
|
||||||
|
arguments.append('.')
|
||||||
|
|
||||||
return 0
|
# Application invocation..
|
||||||
|
if more_command_options is None:
|
||||||
|
execute_command([application_path] + DEFAULT_ARGS +
|
||||||
|
command_options + arguments)
|
||||||
|
else:
|
||||||
|
result_data = execute_command([application_path] + DEFAULT_ARGS +
|
||||||
|
command_options + arguments, True)
|
||||||
|
coverage_data = execute_command([application_path] + DEFAULT_ARGS +
|
||||||
|
more_command_options + arguments,
|
||||||
|
return_output=True)
|
||||||
|
# Result storage
|
||||||
|
report_directory = get_report_directory()
|
||||||
|
result_path = os.path.join(report_directory, 'mocha_results.xml')
|
||||||
|
coverage_path = os.path.join(report_directory, 'mocha_coverage.xml')
|
||||||
|
with open(result_path, 'w') as result_file:
|
||||||
|
result_file.write(result_data)
|
||||||
|
with open(coverage_path, 'w') as coverage_file:
|
||||||
|
coverage_file.write(coverage_data)
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user