Added grunt-tests command
bzr revid: nicolas.vanhoren@openerp.com-20130729150553-ps7w9g6fuqx4qxes
This commit is contained in:
parent
ff8af0b04d
commit
f1b47a3e0e
|
@ -19,9 +19,10 @@ from . import scaffold
|
|||
from . import uninstall
|
||||
from . import update
|
||||
from . import web
|
||||
from . import grunt_tests
|
||||
|
||||
command_list_server = (conf, cron, drop, initialize, model, module, read, run_tests,
|
||||
scaffold, uninstall, update, web, )
|
||||
scaffold, uninstall, update, web, grunt_tests, )
|
||||
|
||||
command_list_client = (Call, Open, Show, ConsumeNothing, ConsumeMemory,
|
||||
LeakMemory, ConsumeCPU, Bench, BenchRead,
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
"""
|
||||
Search for Gruntfile.js files in all the addons and launch them using the 'grunt test' command.
|
||||
"""
|
||||
|
||||
import common
|
||||
import fnmatch
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
def grunt_tester(directories, log = sys.stdout):
|
||||
result = 0
|
||||
|
||||
matches = []
|
||||
for direc in directories:
|
||||
for root, dirnames, filenames in os.walk(direc):
|
||||
for filename in fnmatch.filter(filenames, 'Gruntfile.js'):
|
||||
full = os.path.join(root, filename)
|
||||
if re.match(r"(^.*?/node_modules/.*$)|(^.*?/lib/.*$)", full):
|
||||
continue
|
||||
matches.append(full)
|
||||
|
||||
for file_ in matches:
|
||||
folder = os.path.dirname(file_)
|
||||
p = subprocess.Popen(['npm', 'install'], cwd=folder)
|
||||
if p.wait() != 0:
|
||||
raise Exception("Failed to install dependencies for Gruntfile located in folder %s" % folder)
|
||||
|
||||
p = subprocess.Popen(['grunt', 'test', '--no-color'], cwd=folder, stdout=log, stderr=log)
|
||||
if p.wait() != 0:
|
||||
result = 1
|
||||
|
||||
return result
|
||||
|
||||
def run(args):
|
||||
if args.addons:
|
||||
args.addons = args.addons.split(':')
|
||||
else:
|
||||
args.addons = []
|
||||
result = grunt_tester(args.addons)
|
||||
if result != 0:
|
||||
sys.exit(result)
|
||||
|
||||
def add_parser(subparsers):
|
||||
parser = subparsers.add_parser('grunt-tests',
|
||||
description='Run the tests contained in Gruntfile.js files.')
|
||||
common.add_addons_argument(parser)
|
||||
|
||||
parser.set_defaults(run=run)
|
Loading…
Reference in New Issue