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 <jacktfranklin@chromium.org>
Reviewed-by: Tim Van der Lippe <tvanderlippe@chromium.org>
Commit-Queue: Tim Van der Lippe <tvanderlippe@chromium.org>
This commit is contained in:
Jack Franklin
2022-02-11 09:55:47 +00:00
committed by Devtools-frontend LUCI CQ
parent e25b01f6e9
commit a08500377b
3 changed files with 24 additions and 5 deletions
+5 -1
View File
@@ -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__':
+13 -4
View File
@@ -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__':
+6
View File
@@ -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: [