def main(args=None): """Runs lighthouse checks and deletes reports.""" parsed_args = _PARSER.parse_args(args=args) if parsed_args.mode == LIGHTHOUSE_MODE_ACCESSIBILITY: lighthouse_mode = LIGHTHOUSE_MODE_ACCESSIBILITY server_mode = SERVER_MODE_DEV elif parsed_args.mode == LIGHTHOUSE_MODE_PERFORMANCE: lighthouse_mode = LIGHTHOUSE_MODE_PERFORMANCE server_mode = SERVER_MODE_PROD else: raise Exception('Invalid parameter passed in: \'%s\', please choose' 'from \'accessibility\' or \'performance\'' % parsed_args.mode) enable_webpages() atexit.register(cleanup) if lighthouse_mode == LIGHTHOUSE_MODE_PERFORMANCE: python_utils.PRINT('Building files in production mode.') # We are using --source_maps here, so that we have at least one CI check # that builds using source maps in prod env. This is to ensure that # there are no issues while deploying oppia. build.main(args=['--prod_env', '--source_maps']) elif lighthouse_mode == LIGHTHOUSE_MODE_ACCESSIBILITY: build.main(args=[]) run_webpack_compilation() else: raise Exception('Invalid lighthouse mode: \'%s\', please choose' 'from \'accessibility\' or \'performance\'' % lighthouse_mode) common.start_redis_server() # TODO(#11549): Move this to top of the file. import contextlib2 managed_dev_appserver = common.managed_dev_appserver( APP_YAML_FILENAMES[server_mode], port=GOOGLE_APP_ENGINE_PORT, clear_datastore=True, log_level='critical', skip_sdk_update_check=True) with contextlib2.ExitStack() as stack: stack.enter_context(common.managed_elasticsearch_dev_server()) if constants.EMULATOR_MODE: stack.enter_context(common.managed_firebase_auth_emulator()) stack.enter_context(managed_dev_appserver) # Wait for the servers to come up. common.wait_for_port_to_be_in_use(feconf.ES_LOCALHOST_PORT) common.wait_for_port_to_be_in_use(GOOGLE_APP_ENGINE_PORT) run_lighthouse_puppeteer_script() run_lighthouse_checks(lighthouse_mode)
def run_tests(args): """Run the scripts to start end-to-end tests.""" oppia_instance_is_already_running = is_oppia_server_already_running() if oppia_instance_is_already_running: sys.exit(1) setup_and_install_dependencies(args.skip_install) common.start_redis_server() atexit.register(cleanup) dev_mode = not args.prod_env if args.skip_build: build.modify_constants(prod_env=args.prod_env) else: build_js_files(dev_mode, deparallelize_terser=args.deparallelize_terser, source_maps=args.source_maps) version = args.chrome_driver_version or get_chrome_driver_version() python_utils.PRINT('\n\nCHROMEDRIVER VERSION: %s\n\n' % version) start_webdriver_manager(version) # TODO(#11549): Move this to top of the file. import contextlib2 with contextlib2.ExitStack() as stack: stack.enter_context(common.managed_firebase_auth_emulator()) stack.enter_context( common.managed_dev_appserver( 'app.yaml' if args.prod_env else 'app_dev.yaml', port=GOOGLE_APP_ENGINE_PORT, log_level=args.server_log_level, clear_datastore=True, skip_sdk_update_check=True, env={'PORTSERVER_ADDRESS': PORTSERVER_SOCKET_FILEPATH})) common.wait_for_port_to_be_open(WEB_DRIVER_PORT) common.wait_for_port_to_be_open(GOOGLE_APP_ENGINE_PORT) python_utils.PRINT( 'Note: If ADD_SCREENSHOT_REPORTER is set to true in' 'core/tests/protractor.conf.js, you can view screenshots' 'of the failed tests in ../protractor-screenshots/') commands = [common.NODE_BIN_PATH] if args.debug_mode: commands.append('--inspect-brk') # This flag ensures tests fail if waitFor calls time out. commands.append('--unhandled-rejections=strict') commands.append(PROTRACTOR_BIN_PATH) commands.extend( get_e2e_test_parameters(args.sharding_instances, args.suite, dev_mode)) p = subprocess.Popen(commands, stdout=subprocess.PIPE) output_lines = [] while True: nextline = p.stdout.readline() if len(nextline) == 0 and p.poll() is not None: break if isinstance(nextline, str): # This is a failsafe line in case we get non-unicode input, # but the tests provide all strings as unicode. nextline = nextline.decode('utf-8') # pragma: nocover output_lines.append(nextline.rstrip()) # Replaces non-ASCII characters with '?'. sys.stdout.write(nextline.encode('ascii', errors='replace')) return output_lines, p.returncode