From ff4c04fc811f2e59f5c7c3d515ba7c2b41fea7bd Mon Sep 17 00:00:00 2001 From: Justin Nguyen <70992422+jnvtnguyen@users.noreply.github.com> Date: Sun, 18 Aug 2024 19:02:00 -0700 Subject: [PATCH] Fix #20846: No spec file found for the file x when running frontend tests (#20849) * Updates * Updates * Updates * Updates * Updates --- scripts/pre_push_hook.py | 4 +++- scripts/pre_push_hook_test.py | 3 ++- scripts/run_frontend_tests.py | 9 +++++++++ scripts/run_frontend_tests_test.py | 7 ++++--- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/pre_push_hook.py b/scripts/pre_push_hook.py index cf79d69ee1be..25328721a9a5 100755 --- a/scripts/pre_push_hook.py +++ b/scripts/pre_push_hook.py @@ -356,7 +356,9 @@ def main(args: Optional[List[str]] = None) -> None: if js_or_ts_files: frontend_test_cmds = FRONTEND_TEST_CMDS.copy() frontend_test_cmds.append( - '--specs_to_run=%s --allow_no_spec' + '--allow_no_spec') + frontend_test_cmds.append( + '--specs_to_run=%s' % ','.join(js_or_ts_files)) frontend_status = run_script_and_get_returncode( frontend_test_cmds) diff --git a/scripts/pre_push_hook_test.py b/scripts/pre_push_hook_test.py index 6f6d49fdc91e..6878297b0d74 100644 --- a/scripts/pre_push_hook_test.py +++ b/scripts/pre_push_hook_test.py @@ -464,7 +464,8 @@ def test_frontend_test_failure(self) -> None: def mock_run_script_and_get_returncode(script: List[str]) -> int: if ( script == pre_push_hook.FRONTEND_TEST_CMDS + [ - '--specs_to_run=files1.js,file2.ts --allow_no_spec' + '--allow_no_spec', + '--specs_to_run=files1.js,file2.ts', ] ): return 1 diff --git a/scripts/run_frontend_tests.py b/scripts/run_frontend_tests.py index 6fdd0bad628f..f8f5ab3542b0 100644 --- a/scripts/run_frontend_tests.py +++ b/scripts/run_frontend_tests.py @@ -217,6 +217,15 @@ def main(args: Optional[Sequence[str]] = None) -> None: if spec_file: specs_to_run.add(spec_file) + if ( + (parsed_args.specs_to_run or + parsed_args.run_on_changed_files_in_branch) and + not specs_to_run + ): + print('No valid specs found to run.') + exit_code = 0 if parsed_args.allow_no_spec else 1 + sys.exit(exit_code) + if specs_to_run: print('Running the following specs:', specs_to_run) cmd.append('--specs_to_run=%s' % ','.join(sorted(specs_to_run))) diff --git a/scripts/run_frontend_tests_test.py b/scripts/run_frontend_tests_test.py index b4a7b2e5091c..d559d5187652 100644 --- a/scripts/run_frontend_tests_test.py +++ b/scripts/run_frontend_tests_test.py @@ -237,9 +237,10 @@ def test_frontend_tests_with_specs_to_run_no_specs_found_allow_no_spec( with self.swap_success_Popen, self.print_swap, self.swap_build: with self.swap_install_third_party_libs, self.swap_common: with self.swap_check_frontend_coverage: - run_frontend_tests.main( - args=['--specs_to_run', 'invalid.ts', - '--allow_no_spec']) + with self.assertRaisesRegex(SystemExit, '0'): + run_frontend_tests.main( + args=['--specs_to_run', 'invalid.ts', + '--allow_no_spec']) def test_frontend_tests_with_run_on_changed_files_in_branch(self) -> None: git_refs = [git_changes_utils.GitRef(