blob: 6f95fb0c568998984b4126f70967303298b6a38c [file] [log] [blame]
Paul Lewise441d1d2019-09-16 14:40:20 +00001#!/usr/bin/env python
2#
3# Copyright 2016 The Chromium Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7import os
8import re
9import subprocess
10import sys
11
Yang Guod8176982019-10-04 20:30:35 +000012import devtools_paths
Paul Lewise441d1d2019-09-16 14:40:20 +000013
14is_cygwin = sys.platform == "cygwin"
15chrome_binary = None
16
17if len(sys.argv) >= 2:
18 chrome_binary = re.sub(r"^\-\-chrome-binary=(.*)", "\\1", sys.argv[1])
19 is_executable = os.path.exists(chrome_binary) and os.path.isfile(chrome_binary) and os.access(chrome_binary, os.X_OK)
20 if not is_executable:
21 print("Unable to find a Chrome binary at \"%s\"" % chrome_binary)
22 sys.exit(1)
23
24
25def popen(arguments, cwd=None, env=None):
26 return subprocess.Popen(arguments, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
27
28
29def to_platform_path_exact(filepath):
30 if not is_cygwin:
31 return filepath
32 output, _ = popen(["cygpath", "-w", filepath]).communicate()
33 # pylint: disable=E1103
34 return output.strip().replace("\\", "\\\\")
35
36
37scripts_path = os.path.dirname(os.path.abspath(__file__))
38devtools_path = os.path.dirname(scripts_path)
39
40print("Running tests with Karma...")
41if (chrome_binary is not None):
42 print("Using custom Chrome Binary (%s)\n" % chrome_binary)
43else:
44 print("Using system Chrome")
45
46
47def run_tests():
48 karma_errors_found = False
49
50 karmaconfig_path = os.path.join(devtools_path, "karma.conf.js")
Yang Guod8176982019-10-04 20:30:35 +000051 exec_command = [devtools_paths.node_path(), devtools_paths.karma_path(), "start", to_platform_path_exact(karmaconfig_path)]
Paul Lewise441d1d2019-09-16 14:40:20 +000052
Yang Guod8176982019-10-04 20:30:35 +000053 env = {'NODE_PATH': devtools_paths.node_modules_path()}
Paul Lewise441d1d2019-09-16 14:40:20 +000054 if (chrome_binary is not None):
55 env['CHROME_BIN'] = chrome_binary
56
57 karma_proc = popen(exec_command, cwd=devtools_path, env=env)
58
59 (karma_proc_out, _) = karma_proc.communicate()
60 if karma_proc.returncode != 0:
61 karma_errors_found = True
62 else:
63 print("Karma exited successfully")
64
65 print(karma_proc_out)
66 return karma_errors_found
67
68
69errors_found = run_tests()
70
71if errors_found:
72 print("ERRORS DETECTED")
73 sys.exit(1)