Skip to content

Commit

Permalink
Fix oppia#20846: No spec file found for the file x when running front…
Browse files Browse the repository at this point in the history
…end tests (oppia#20849)

* Updates

* Updates

* Updates

* Updates

* Updates
  • Loading branch information
jnvtnguyen authored Aug 19, 2024
1 parent 2cdf240 commit ff4c04f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion scripts/pre_push_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion scripts/pre_push_hook_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions scripts/run_frontend_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
7 changes: 4 additions & 3 deletions scripts/run_frontend_tests_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ff4c04f

Please sign in to comment.