From a08500377ba1e5d15ddeae536441f620f64dc1df Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Thu, 10 Feb 2022 15:39:35 +0000 Subject: [PATCH] Add --mocha-fgrep to unit tests This CL adds the ability to run: ``` npm run auto-unittest -- --mocha-fgrep=breadcrumb ``` To the Karma unit test suite to mirror the similar flag available in the interactions and e2e test runner script. This is also why it's named `fgrep`, as that's the same flag as used in the other script, and we should be consistent. Bug: none Change-Id: Ic119f7186e0e97c83e00bf92a66d69181c931a8b Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3452723 Auto-Submit: Jack Franklin Reviewed-by: Tim Van der Lippe Commit-Queue: Tim Van der Lippe --- scripts/test/run_auto_unittests.py | 6 +++++- scripts/test/run_unittests.py | 17 +++++++++++++---- test/unittests/karma.conf.js | 6 ++++++ 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/scripts/test/run_auto_unittests.py b/scripts/test/run_auto_unittests.py index 831e900896..180e4e6919 100755 --- a/scripts/test/run_auto_unittests.py +++ b/scripts/test/run_auto_unittests.py @@ -52,12 +52,16 @@ def main(): dest='cwd', help='Path to the directory containing the out dir', default=devtools_paths.devtools_root_path()) + parser.add_argument('--mocha-fgrep', + dest='mocha_fgrep', + help='Run only tests that match this string.') args = parser.parse_args(sys.argv[1:]) efficiently_recompile.recompile(args.target, 'test/unittests') run_unittests.run_unit_tests_on_ninja_build_target( args.target, args.no_text_coverage, args.no_html_coverage, - args.coverage, args.expanded_reporting, args.chrome_binary, args.cwd) + args.coverage, args.expanded_reporting, args.chrome_binary, args.cwd, + args.mocha_fgrep) if __name__ == '__main__': diff --git a/scripts/test/run_unittests.py b/scripts/test/run_unittests.py index 4cbaaa8623..efb887c47b 100755 --- a/scripts/test/run_unittests.py +++ b/scripts/test/run_unittests.py @@ -23,7 +23,7 @@ import devtools_paths def run_tests(chrome_binary, target, no_text_coverage, no_html_coverage, - coverage, expanded_reporting, cwd): + coverage, expanded_reporting, cwd, mocha_fgrep): karmaconfig_path = os.path.join(cwd, 'out', target, 'gen', 'test', 'unittests', 'karma.conf.js') @@ -34,6 +34,7 @@ def run_tests(chrome_binary, target, no_text_coverage, no_html_coverage, print('Using karma config ' + karmaconfig_path) + exec_command = [devtools_paths.node_path(), devtools_paths.karma_path(), 'start', test_helpers.to_platform_path_exact(karmaconfig_path)] env = os.environ.copy() @@ -48,6 +49,9 @@ def run_tests(chrome_binary, target, no_text_coverage, no_html_coverage, env['EXPANDED_REPORTING'] = '1' if (chrome_binary is not None): env['CHROME_BIN'] = chrome_binary + if (mocha_fgrep is not None): + print('Using Mocha --fgrep flag ' + mocha_fgrep) + env['MOCHA_FGREP'] = mocha_fgrep exit_code = test_helpers.popen(exec_command, cwd=cwd, env=env) if exit_code == 1: return True @@ -61,7 +65,8 @@ def run_unit_tests_on_ninja_build_target(target, coverage=False, expanded_reporting=False, chrome_binary=None, - cwd=None): + cwd=None, + mocha_fgrep=None): if chrome_binary and not test_helpers.check_chrome_binary(chrome_binary): print( 'Chrome binary argument path does not exist or is not executable, reverting to downloaded binary' @@ -88,7 +93,7 @@ def run_unit_tests_on_ninja_build_target(target, errors_found = run_tests(chrome_binary, target, no_text_coverage, no_html_coverage, coverage, expanded_reporting, - cwd) + cwd, mocha_fgrep) if coverage and not no_html_coverage: print('') @@ -137,12 +142,16 @@ def main(): dest='cwd', help='Path to the directory containing the out dir', default=devtools_paths.devtools_root_path()) + parser.add_argument('--mocha-fgrep', + dest='mocha_fgrep', + help='Run only tests that match this string.') args = parser.parse_args(sys.argv[1:]) run_unit_tests_on_ninja_build_target(args.target, args.no_text_coverage, args.no_html_coverage, args.coverage, args.expanded_reporting, - args.chrome_binary, args.cwd) + args.chrome_binary, args.cwd, + args.mocha_fgrep) if __name__ == '__main__': diff --git a/test/unittests/karma.conf.js b/test/unittests/karma.conf.js index 1ff66ec4df..b5c76f4960 100644 --- a/test/unittests/karma.conf.js +++ b/test/unittests/karma.conf.js @@ -20,6 +20,8 @@ const COVERAGE_ENABLED = Boolean(process.env['COVERAGE']) || Boolean(USER_DEFINE const EXPANDED_REPORTING = Boolean(process.env['EXPANDED_REPORTING']); const KARMA_TIMEOUT = process.env['KARMA_TIMEOUT'] ? Number(process.env['KARMA_TIMEOUT']) : undefined; +const MOCHA_FGREP = process.env['MOCHA_FGREP'] || undefined; + // true by default const TEXT_COVERAGE_ENABLED = COVERAGE_ENABLED && !process.env['NO_TEXT_COVERAGE']; // true by default @@ -163,6 +165,10 @@ module.exports = function(config) { * so. */ targetDir, + + mocha: { + grep: MOCHA_FGREP, + } }, plugins: [