Repository: oppia/oppia
File: scripts/run_frontend_tests_test.py (Python)

Code before:
        cmd = ['./node_modules/dtslint/bin/index.js',
           run_frontend_tests.DTSLINT_TYPE_TESTS_DIR_RELATIVE_PATH,
           '--localTs',
           run_frontend_tests.TYPESCRIPT_DIR_RELATIVE_PATH]
        self.assertIn(cmd, self.cmd_token_list)
        self.assertIn('Running dtslint type tests.', self.print_arr)
        self.assertIn(
            'The dtslint (type tests) failed.', self.sys_exit_message)

    def test_no_tests_are_run_when_dtslint_flag_passed(self) -> None:
        with self.swap_success_Popen, self.print_swap:
            run_frontend_tests.main(args=['--dtslint_only'])
        self.assertIn('Running dtslint type tests.', self.print_arr)
        self.assertIn('Done!', self.print_arr)
        self.assertEqual(len(self.cmd_token_list), 1)

    def test_frontend_tests_with_specs_to_run(self) -> None:
        original_os_path_exists = os.path.exists
        def mock_os_path_exists(path: str) -> bool:
            if path == 'home-page.component.spec.ts':
                return True
            if path == 'about-page.component.spec.ts':
                return True
            if path == 'test-module.spec.js':
                return True
            if path == 'states.model.spec.ts':
                return True
            return original_os_path_exists(path)
        os_path_exists_swap = self.swap(
            os.path, 'exists', mock_os_path_exists)

        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, os_path_exists_swap:
                    run_frontend_tests.main(
                        args=['--check_coverage', '--specs_to_run='
                              'home-page.component.spec.ts,'
                              'about-page.component.ts,'
                              'test-module.js,'
                              'states.model.ts'])

        cmd = [
            common.NODE_BIN_PATH, '--max-old-space-size=4096',
            os.path.join(common.NODE_MODULES_PATH, 'karma', 'bin', 'karma'),
            'start', os.path.join('core', 'tests', 'karma.conf.ts'),
            '--specs_to_run='
            'states.model.spec.ts,'
            'about-page.component.spec.ts,'
            'home-page.component.spec.ts,'
            'test-module.spec.js']
        self.assertIn(cmd, self.cmd_token_list)

Review comment (suggestion):
Change this with some other ``*FactorySpec``. Basically use that file, which you think will be the last object factory to get merged.

Ditto below

Code after:
        cmd = ['./node_modules/dtslint/bin/index.js',
           run_frontend_tests.DTSLINT_TYPE_TESTS_DIR_RELATIVE_PATH,
           '--localTs',
           run_frontend_tests.TYPESCRIPT_DIR_RELATIVE_PATH]
        self.assertIn(cmd, self.cmd_token_list)
        self.assertIn('Running dtslint type tests.', self.print_arr)
        self.assertIn(
            'The dtslint (type tests) failed.', self.sys_exit_message)

    def test_no_tests_are_run_when_dtslint_flag_passed(self) -> None:
        with self.swap_success_Popen, self.print_swap:
            run_frontend_tests.main(args=['--dtslint_only'])
        self.assertIn('Running dtslint type tests.', self.print_arr)
        self.assertIn('Done!', self.print_arr)
        self.assertEqual(len(self.cmd_token_list), 1)

    def test_frontend_tests_with_specs_to_run(self) -> None:
        original_os_path_exists = os.path.exists
        def mock_os_path_exists(path: str) -> bool:
            if path == 'home-page.component.spec.ts':
                return True
            if path == 'about-page.component.spec.ts':
                return True
            if path == 'test-module.spec.js':
                return True
            if path == 'ExplorationObjectFactorySpec.ts':
                return True
            return original_os_path_exists(path)
        os_path_exists_swap = self.swap(
            os.path, 'exists', mock_os_path_exists)

        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, os_path_exists_swap:
                    run_frontend_tests.main(
                        args=['--check_coverage', '--specs_to_run='
                              'home-page.component.spec.ts,'
                              'about-page.component.ts,'
                              'test-module.js,'
                              'ExplorationObjectFactory.ts'])

        cmd = [
            common.NODE_BIN_PATH, '--max-old-space-size=4096',
            os.path.join(common.NODE_MODULES_PATH, 'karma', 'bin', 'karma'),
            'start', os.path.join('core', 'tests', 'karma.conf.ts'),
            '--specs_to_run='
            'ExplorationObjectFactorySpec.ts,'
            'about-page.component.spec.ts,'
            'home-page.component.spec.ts,'
            'test-module.spec.js']
        self.assertIn(cmd, self.cmd_token_list)