Commit a163f802 authored by Paul Lewis's avatar Paul Lewis Committed by Commit Bot

[DevTools] Adds support for Karma tests

Change-Id: I1ea19eee040360d3a73ffaa72ccf15bceff80317
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1806858
Auto-Submit: Paul Lewis <aerotwist@google.com>
Reviewed-by: default avatarYang Guo <yangguo@chromium.org>
Commit-Queue: Paul Lewis <aerotwist@google.com>
Cr-Commit-Position: refs/heads/master@{#696789}
parent c1fe633f
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module.exports = function(config) {
const options = {
basePath: "",
files: [{
pattern: 'front_end/**/*.js',
included: false,
served: true
},{
pattern: 'tests/**/*.ts',
type: 'module'
}],
reporters: ["dots"],
preprocessors: {
'./tests/**/*.ts': ['karma-typescript']
},
browsers: ["ChromeHeadless"],
frameworks: ["mocha", "chai", "karma-typescript"],
karmaTypescriptConfig: {
compilerOptions: {
target: "esnext",
module: "esnext",
typeRoots: ["./third_party/devtools-node-modules/third_party/node_modules/@types"]
},
coverageOptions: {
instrumentation: false
},
bundlerOptions: {
resolve: {
directories: ["./third_party/devtools-node-modules/third_party/node_modules"]
}
}
},
proxies: {
'/front_end': '/base/front_end',
},
plugins: [
"karma-chrome-launcher",
"karma-mocha",
"karma-chai",
"karma-typescript"
],
singleRun: true
};
config.set(options);
};
......@@ -127,3 +127,17 @@ npm test -- --target=Default
[@ChromeDevTools]: http://twitter.com/ChromeDevTools
[@DevToolsCommits]: http://twitter.com/DevToolsCommits
[all open DevTools tickets]: https://bugs.chromium.org/p/chromium/issues/list?can=2&q=component%3APlatform%3EDevTools&sort=&groupby=&colspec=ID+Stars+Owner+Summary+Modified+Opened
### Tests
The tests are run through Karma.
```
python scripts/run_tests.py
```
You can also specify with which Chrome binary to run tests by setting the
`chrome-binary` variable.
```
python scripts/run_tests.py --chrome-binary=/path/to/chromium/build/chromium
```
......@@ -12,6 +12,8 @@ SCRIPTS_PATH = path.dirname(path.abspath(__file__))
THIRD_PARTY_PATH = path.join(SCRIPTS_PATH, '..', '..', '..', '..')
NODE_PATH = path.join(THIRD_PARTY_PATH, 'node')
ESLINT_PATH = path.join(THIRD_PARTY_PATH, 'devtools-node-modules', 'third_party', 'node_modules', 'eslint', 'bin', 'eslint.js')
KARMA_PATH = path.join(THIRD_PARTY_PATH, 'devtools-node-modules', 'third_party', 'node_modules', 'karma', 'bin', 'karma')
NODE_MODULES_PATH = path.join(THIRD_PARTY_PATH, 'devtools-node-modules', 'third_party', 'node_modules')
try:
old_sys_path = sys.path[:]
......@@ -27,3 +29,11 @@ def node_path():
def eslint_path():
return ESLINT_PATH
def karma_path():
return KARMA_PATH
def node_modules_path():
return NODE_MODULES_PATH
#!/usr/bin/env python
#
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import re
import subprocess
import sys
import local_node
is_cygwin = sys.platform == "cygwin"
chrome_binary = None
if len(sys.argv) >= 2:
chrome_binary = re.sub(r"^\-\-chrome-binary=(.*)", "\\1", sys.argv[1])
is_executable = os.path.exists(chrome_binary) and os.path.isfile(chrome_binary) and os.access(chrome_binary, os.X_OK)
if not is_executable:
print("Unable to find a Chrome binary at \"%s\"" % chrome_binary)
sys.exit(1)
def popen(arguments, cwd=None, env=None):
return subprocess.Popen(arguments, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
def to_platform_path_exact(filepath):
if not is_cygwin:
return filepath
output, _ = popen(["cygpath", "-w", filepath]).communicate()
# pylint: disable=E1103
return output.strip().replace("\\", "\\\\")
scripts_path = os.path.dirname(os.path.abspath(__file__))
devtools_path = os.path.dirname(scripts_path)
print("Running tests with Karma...")
if (chrome_binary is not None):
print("Using custom Chrome Binary (%s)\n" % chrome_binary)
else:
print("Using system Chrome")
def run_tests():
karma_errors_found = False
karmaconfig_path = os.path.join(devtools_path, "karma.conf.js")
exec_command = [local_node.node_path(), local_node.karma_path(), "start", to_platform_path_exact(karmaconfig_path)]
env = {'NODE_PATH': local_node.node_modules_path()}
if (chrome_binary is not None):
env['CHROME_BIN'] = chrome_binary
karma_proc = popen(exec_command, cwd=devtools_path, env=env)
(karma_proc_out, _) = karma_proc.communicate()
if karma_proc.returncode != 0:
karma_errors_found = True
else:
print("Karma exited successfully")
print(karma_proc_out)
return karma_errors_found
errors_found = run_tests()
if errors_found:
print("ERRORS DETECTED")
sys.exit(1)
{
"compilerOptions": {
"typeRoots": ["../../../devtools-node-modules/third_party/node_modules/@types"]
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment