mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-02 18:11:04 +08:00
The e2e-tests now use the build output in resources/inspector in the out directory. This allows us to introduce TypeScript-authored files in the source directory `front_end`, which will get compiled into resourc/inspector. After to making a change to a e2e-test or the front_end, you need to rebuild Devtools, after which you can run `npm run e2etest` as normal. Since we now use the build output, this also means that you can run the e2e-tests on the release build. In other words, if you build DevTools with build optimizations (such as Rollup), the e2e-tests will now use the output (and thus provide test coverage). DISABLE_THIRD_PARTY_CHECK=Node fixes R=aerotwist@chromium.org,jacktfranklin@chromium.org Fixed: 1088463 Change-Id: I02ec3c2476bc3647158fede9e1d347963b3a720a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2224809 Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Jose Leal <joselea@microsoft.com> Reviewed-by: Paul Lewis <aerotwist@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
132 lines
4.0 KiB
Python
132 lines
4.0 KiB
Python
#!/usr/bin/env python
|
|
#
|
|
# Copyright 2020 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.
|
|
"""
|
|
Run tests on a pinned version of chrome.
|
|
"""
|
|
|
|
import argparse
|
|
import os
|
|
import re
|
|
from subprocess import Popen
|
|
import sys
|
|
import signal
|
|
|
|
ROOT_DIRECTORY = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..')
|
|
scripts_path = os.path.join(ROOT_DIRECTORY, 'scripts')
|
|
sys.path.append(scripts_path)
|
|
|
|
import devtools_paths
|
|
import test_helpers
|
|
|
|
|
|
def parse_options(cli_args):
|
|
parser = argparse.ArgumentParser(description='Run tests')
|
|
parser.add_argument('--chrome-binary', dest='chrome_binary', help='path to Chromium binary')
|
|
parser.add_argument('--test-suite', dest='test_suite', help='path to test suite')
|
|
parser.add_argument('--test-file', dest='test_file', help='an absolute path for the file to test')
|
|
parser.add_argument(
|
|
'--target',
|
|
'-t',
|
|
default='Default',
|
|
dest='target',
|
|
help='The name of the Ninja output directory. Defaults to "Default"')
|
|
parser.add_argument(
|
|
'--chrome-features',
|
|
dest='chrome_features',
|
|
help='comma separated list of strings passed to --enable-features on the chromium commandline')
|
|
return parser.parse_args(cli_args)
|
|
|
|
|
|
def run_tests(chrome_binary,
|
|
chrome_features,
|
|
test_suite_path,
|
|
test_suite,
|
|
test_file=None):
|
|
env = os.environ.copy()
|
|
env['CHROME_BIN'] = chrome_binary
|
|
if chrome_features:
|
|
env['CHROME_FEATURES'] = chrome_features
|
|
|
|
if test_file is not None:
|
|
env['TEST_FILE'] = test_file
|
|
|
|
cwd = devtools_paths.devtools_root_path()
|
|
exec_command = [
|
|
devtools_paths.node_path(),
|
|
devtools_paths.mocha_path(),
|
|
'--config',
|
|
os.path.join(test_suite_path, '.mocharc.js'),
|
|
]
|
|
|
|
exit_code = test_helpers.popen(exec_command, cwd=cwd, env=env)
|
|
if exit_code != 0:
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
def run_test():
|
|
OPTIONS = parse_options(sys.argv[1:])
|
|
is_cygwin = sys.platform == 'cygwin'
|
|
chrome_binary = None
|
|
test_suite = None
|
|
chrome_features = None
|
|
|
|
# Default to the downloaded / pinned Chromium binary
|
|
downloaded_chrome_binary = devtools_paths.downloaded_chrome_binary_path()
|
|
if test_helpers.check_chrome_binary(downloaded_chrome_binary):
|
|
chrome_binary = downloaded_chrome_binary
|
|
|
|
# Override with the arg value if provided.
|
|
if OPTIONS.chrome_binary:
|
|
chrome_binary = OPTIONS.chrome_binary
|
|
if not test_helpers.check_chrome_binary(chrome_binary):
|
|
print('Unable to find a Chrome binary at \'%s\'' % chrome_binary)
|
|
sys.exit(1)
|
|
|
|
if OPTIONS.chrome_features:
|
|
chrome_features = '--enable-features=%s' % OPTIONS.chrome_features
|
|
|
|
if (chrome_binary is None):
|
|
print('Unable to run, no Chrome binary provided')
|
|
sys.exit(1)
|
|
|
|
if (OPTIONS.test_suite is None):
|
|
print('Unable to run, no test suite provided')
|
|
sys.exit(1)
|
|
|
|
test_suite = OPTIONS.test_suite
|
|
test_file = OPTIONS.test_file
|
|
|
|
print('Using Chromium binary ({}{})\n'.format(chrome_binary, ' ' + chrome_features if chrome_features else ''))
|
|
print('Using Test Suite (%s)\n' % test_suite)
|
|
print('Using target (%s)\n' % OPTIONS.target)
|
|
|
|
if test_file is not None:
|
|
print('Testing file (%s)' % test_file)
|
|
|
|
cwd = devtools_paths.devtools_root_path()
|
|
test_suite_path = os.path.join(cwd, 'out', OPTIONS.target, 'gen', 'test',
|
|
test_suite)
|
|
|
|
errors_found = False
|
|
try:
|
|
errors_found = run_tests(chrome_binary,
|
|
chrome_features,
|
|
test_suite_path,
|
|
test_suite,
|
|
test_file=test_file)
|
|
except Exception as err:
|
|
print(err)
|
|
|
|
if errors_found:
|
|
print('ERRORS DETECTED')
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run_test()
|