def test_build_js_files_in_prod_mode_with_deparallelize_terser(self): def mock_update_dev_mode_in_constants_js(unused_filename, unused_dev_mode): pass update_dev_mode_in_constants_js_swap = self.swap_with_checks( run_e2e_tests, 'update_dev_mode_in_constants_js', mock_update_dev_mode_in_constants_js, expected_args=[(self.mock_constant_file_path, False)]) run_cmd_swap = self.swap_with_checks(common, 'run_cmd', self.mock_run_cmd, called=False) build_main_swap = self.swap_with_checks( build, 'main', self.mock_build_main, expected_kwargs=[{ 'args': ['--prod_env', '--deparallelize_terser'] }]) with self.constant_file_path_swap: with self.node_bin_path_swap, self.webpack_bin_path_swap: with update_dev_mode_in_constants_js_swap, run_cmd_swap: with build_main_swap: run_e2e_tests.build_js_files(False, deparallelize_terser=True)
def test_build_js_files_in_dev_mode_with_exception_raised(self): def mock_check_call(commands): raise subprocess.CalledProcessError(returncode=2, cmd=commands, output='ERROR') def mock_exit(unused_code): pass expected_commands = [ self.mock_node_bin_path, self.mock_webpack_bin_path, '--config', 'webpack.dev.config.ts' ] check_call_swap = self.swap_with_checks(subprocess, 'check_call', mock_check_call, expected_args=[ (expected_commands, ) ]) build_main_swap = self.swap_with_checks(build, 'main', self.mock_build_main, expected_kwargs=[{ 'args': [] }]) exit_swap = self.swap_with_checks(sys, 'exit', mock_exit, expected_args=[(2, )]) print_swap = self.print_swap(expected_args=[('ERROR', )]) with print_swap, self.constant_file_path_swap: with self.node_bin_path_swap, self.webpack_bin_path_swap: with check_call_swap, exit_swap, build_main_swap: run_e2e_tests.build_js_files(True)
def test_build_js_files_in_dev_mode_with_hash_file_exists(self): def mock_isdir(unused_path): return True expected_commands = [ self.mock_node_bin_path, self.mock_webpack_bin_path, '--config', 'webpack.dev.config.ts' ] isdir_swap = self.swap_with_checks(os.path, 'isdir', mock_isdir) check_call_swap = self.swap_with_checks(subprocess, 'check_call', self.mock_check_call, expected_args=[ (expected_commands, ) ]) build_main_swap = self.swap_with_checks(build, 'main', self.mock_build_main, expected_kwargs=[{ 'args': [] }]) print_swap = self.print_swap(called=False) with print_swap, self.constant_file_path_swap, check_call_swap: with self.node_bin_path_swap, self.webpack_bin_path_swap: with build_main_swap, isdir_swap: run_e2e_tests.build_js_files(True)
def test_build_js_files_in_dev_mode_with_hash_file_not_exist(self): def mock_update_dev_mode_in_constants_js( unused_filename, unused_dev_mode): pass def mock_isdir(unused_path): return True expected_commands = [ self.mock_node_bin_path, self.mock_webpack_bin_path, '--config', 'webpack.dev.config.ts'] mock_hash_file_path = 'NOT_A_FILE.json' hash_file_path_swap = self.swap( run_e2e_tests, 'HASHES_FILE_PATH', mock_hash_file_path) update_dev_mode_in_constants_js_swap = self.swap_with_checks( run_e2e_tests, 'update_dev_mode_in_constants_js', mock_update_dev_mode_in_constants_js, expected_args=[(self.mock_constant_file_path, True)]) isdir_swap = self.swap_with_checks(os.path, 'isdir', mock_isdir) check_call_swap = self.swap_with_checks( subprocess, 'check_call', self.mock_check_call, expected_args=[(expected_commands,)]) build_main_swap = self.swap_with_checks( build, 'main', self.mock_build_main, expected_kwargs=[{'args': []}]) print_swap = self.print_swap(called=False) with print_swap, self.constant_file_path_swap: with self.node_bin_path_swap, self.webpack_bin_path_swap: with update_dev_mode_in_constants_js_swap, check_call_swap: with hash_file_path_swap, build_main_swap, isdir_swap: run_e2e_tests.build_js_files(True) with python_utils.open_file(mock_hash_file_path, 'r') as f: content = f.readlines() os.remove(mock_hash_file_path) self.assertEqual(content, ['{}'])
def test_build_js_files_in_dev_mode_with_hash_file_exists(self): def mock_isdir(unused_path): return True def mock_update_dev_mode_in_constants_js( unused_filename, unused_dev_mode): pass def mock_is_file(unused_path): return True expected_commands = [ self.mock_node_bin_path, self.mock_webpack_bin_path, '--config', 'webpack.dev.config.ts'] is_file_swap = self.swap_with_checks( os.path, 'isfile', mock_is_file, expected_args=[(run_e2e_tests.HASHES_FILE_PATH,)]) update_dev_mode_in_constants_js_swap = self.swap_with_checks( run_e2e_tests, 'update_dev_mode_in_constants_js', mock_update_dev_mode_in_constants_js, expected_args=[(self.mock_constant_file_path, True)]) isdir_swap = self.swap_with_checks(os.path, 'isdir', mock_isdir) check_call_swap = self.swap_with_checks( subprocess, 'check_call', self.mock_check_call, expected_args=[(expected_commands,)]) build_main_swap = self.swap_with_checks( build, 'main', self.mock_build_main, expected_kwargs=[{'args': []}]) print_swap = self.print_swap(called=False) with print_swap, self.constant_file_path_swap: with self.node_bin_path_swap, self.webpack_bin_path_swap: with update_dev_mode_in_constants_js_swap, check_call_swap: with is_file_swap, build_main_swap, isdir_swap: run_e2e_tests.build_js_files(True)
def test_build_js_files_in_prod_mode_with_source_maps(self): self.exit_stack.enter_context(self.swap_with_checks( common, 'run_cmd', lambda *_: None, called=False)) self.exit_stack.enter_context(self.swap_with_checks( build, 'main', lambda *_, **__: None, expected_kwargs=[{'args': ['--prod_env', '--source_maps']}])) run_e2e_tests.build_js_files(False, source_maps=True)
def test_build_js_files_in_dev_mode_with_exception_raised(self): def mock_update_dev_mode_in_constants_js(unused_filename, unused_dev_mode): pass def mock_is_file(unused_path): return True def mock_run_cmd(commands): raise subprocess.CalledProcessError(returncode=2, cmd=commands, output='ERROR') def mock_exit(unused_code): pass expected_commands = [ self.mock_node_bin_path, self.mock_webpack_bin_path, '--config', 'webpack.dev.config.ts' ] is_file_swap = self.swap_with_checks( os.path, 'isfile', mock_is_file, expected_args=[(run_e2e_tests.HASHES_FILE_PATH, )]) update_dev_mode_in_constants_js_swap = self.swap_with_checks( run_e2e_tests, 'update_dev_mode_in_constants_js', mock_update_dev_mode_in_constants_js, expected_args=[(self.mock_constant_file_path, True)]) run_cmd_swap = self.swap_with_checks(common, 'run_cmd', mock_run_cmd, expected_args=[ (expected_commands, ) ]) # The mock exit will not actually exit the program, so the # build_js_files function will continue and build.main will still be # executed. But in actual case, this function will not be executed. build_main_swap = self.swap_with_checks(build, 'main', self.mock_build_main, expected_kwargs=[{ 'args': [] }]) exit_swap = self.swap_with_checks(sys, 'exit', mock_exit, expected_args=[(2, )]) print_swap = self.print_swap(expected_args=[('ERROR', )]) with print_swap, self.constant_file_path_swap: with self.node_bin_path_swap, self.webpack_bin_path_swap: with update_dev_mode_in_constants_js_swap, run_cmd_swap: with is_file_swap, exit_swap, build_main_swap: run_e2e_tests.build_js_files(True)
def test_build_js_files_in_dev_mode_with_exception_raised(self): def mock_update_dev_mode_in_constants_js(unused_filename, unused_dev_mode): pass def mock_is_file(unused_path): return True def mock_check_call(commands): raise subprocess.CalledProcessError(returncode=2, cmd=commands, output='ERROR') def mock_exit(unused_code): pass expected_commands = [ self.mock_node_bin_path, self.mock_webpack_bin_path, '--config', 'webpack.dev.config.ts' ] is_file_swap = self.swap_with_checks( os.path, 'isfile', mock_is_file, expected_args=[(run_e2e_tests.HASHES_FILE_PATH, )]) update_dev_mode_in_constants_js_swap = self.swap_with_checks( run_e2e_tests, 'update_dev_mode_in_constants_js', mock_update_dev_mode_in_constants_js, expected_args=[(self.mock_constant_file_path, True)]) check_call_swap = self.swap_with_checks(subprocess, 'check_call', mock_check_call, expected_args=[ (expected_commands, ) ]) build_main_swap = self.swap_with_checks(build, 'main', self.mock_build_main, expected_kwargs=[{ 'args': [] }]) exit_swap = self.swap_with_checks(sys, 'exit', mock_exit, expected_args=[(2, )]) print_swap = self.print_swap(expected_args=[('ERROR', )]) with print_swap, self.constant_file_path_swap: with self.node_bin_path_swap, self.webpack_bin_path_swap: with update_dev_mode_in_constants_js_swap, check_call_swap: with is_file_swap, exit_swap, build_main_swap: run_e2e_tests.build_js_files(True)
def test_webpack_compilation_in_dev_mode_with_source_maps(self): self.exit_stack.enter_context(self.swap_with_checks( common, 'run_cmd', lambda *_: None, called=False)) self.exit_stack.enter_context(self.swap_with_checks( build, 'main', lambda *_, **__: None, expected_kwargs=[{'args': []}])) self.exit_stack.enter_context(self.swap_with_checks( run_e2e_tests, 'run_webpack_compilation', lambda **_: None, expected_kwargs=[{'source_maps': True}])) run_e2e_tests.build_js_files(True, source_maps=True)
def test_build_js_files_in_dev_mode_with_exception_raised(self): return_code = 2 self.exit_stack.enter_context(self.swap_to_always_raise( servers, 'managed_webpack_compiler', error=subprocess.CalledProcessError(return_code, []))) self.exit_stack.enter_context(self.swap_with_checks( build, 'main', lambda *_, **__: None, expected_kwargs=[{'args': []}])) self.exit_stack.enter_context(self.swap_with_checks( sys, 'exit', lambda _: None, expected_args=[(return_code,)])) run_e2e_tests.build_js_files(True)
def test_build_js_files_in_prod_mode(self): run_cmd_swap = self.swap_with_checks( common, 'run_cmd', self.mock_run_cmd, called=False) build_main_swap = self.swap_with_checks( build, 'main', self.mock_build_main, expected_kwargs=[{'args': ['--prod_env']}]) with self.constant_file_path_swap: with self.node_bin_path_swap, self.webpack_bin_path_swap: with run_cmd_swap, build_main_swap: run_e2e_tests.build_js_files(False)
def test_build_js_files_in_dev_mode_with_hash_file_exists(self): old_os_path_isdir = os.path.isdir def mock_os_path_isdir(path): if path == 'webpack_bundles': return True return old_os_path_isdir(path) self.exit_stack.enter_context(self.swap_with_checks( servers, 'managed_webpack_compiler', mock_managed_process)) self.exit_stack.enter_context(self.swap_with_checks( build, 'main', lambda *_, **__: None, expected_kwargs=[{'args': []}])) self.exit_stack.enter_context(self.swap_with_checks( os.path, 'isdir', mock_os_path_isdir)) self.exit_stack.enter_context(self.swap_with_checks( sys, 'exit', lambda _: None, called=False)) run_e2e_tests.build_js_files(True)