def test_003_js_app_apk(self): # Extract APK apk = TnsPaths.get_apk_path(app_name=self.js_app, release=True) extracted_apk = os.path.join(Settings.TEST_OUT_TEMP, 'js-apk') File.unzip(file_path=apk, dest_dir=extracted_apk) res = os.path.join(extracted_apk, 'res') assets_app = os.path.join(extracted_apk, 'assets', 'app') assets_snapshots = os.path.join(extracted_apk, 'assets', 'snapshots') lib = os.path.join(extracted_apk, 'lib') run(cmd='du -hs *', cwd=lib, wait=True, log_level=logging.INFO) # Verify content of APK assert PerfUtils.is_value_in_range(actual=Folder.get_size(lib), expected=38724352, tolerance=0.1) assert PerfUtils.is_value_in_range(actual=Folder.get_size(res), expected=843827, tolerance=0.1) assert PerfUtils.is_value_in_range(actual=Folder.get_size(assets_app), expected=641606, tolerance=0.1) assert PerfUtils.is_value_in_range( actual=Folder.get_size(assets_snapshots), expected=5811260, tolerance=0.1) # Verify final apk size assert PerfUtils.is_value_in_range(actual=File.get_size(apk), expected=18216351, tolerance=0.05)
def test_102_ng_app_ipa(self): ipa = TnsPaths.get_ipa_path(app_name=self.ng_app, release=True, for_device=True) assert PerfUtils.is_value_in_range(actual=File.get_size(ipa), expected=16226626, tolerance=0.05)
def test_201_prepare_ios_initial(self, template, template_package, change_set): actual = Helpers.get_actual_result(template, Platform.IOS, 'prepare_initial') expected = Helpers.get_expected_result(template, Platform.IOS, 'prepare_initial') assert PerfUtils.is_value_in_range( actual, expected, TOLERANCE), 'Initial ios prepare time is not OK.'
def test_300_build_android_initial(self, template, template_package, change_set): actual = Helpers.get_actual_result(template, Platform.ANDROID, 'build_initial') expected = Helpers.get_expected_result(template, Platform.ANDROID, 'build_initial') assert PerfUtils.is_value_in_range( actual, expected, TOLERANCE), 'Initial android build time is not OK.'
def test_311_build_ios_incremental(self, template, template_package, change_set): actual = Helpers.get_actual_result(template, Platform.IOS, 'build_incremental') expected = Helpers.get_expected_result(template, Platform.IOS, 'build_incremental') assert PerfUtils.is_value_in_range( actual, expected, TOLERANCE), 'Incremental ios build time is not OK.'
def test_010_create_master_detail_app(self): actual = PerfUtils.get_average_time(lambda: Tns.create( app_name=APP_NAME, template=Template.MASTER_DETAIL_NG.local_package, update=False), retry_count=RETRY_COUNT) expected = EXPECTED_RESULTS['master-detail-ng']['create'] assert PerfUtils.is_value_in_range( actual, expected, TOLERANCE), 'MasterDetailNG project create time is not OK.'
def test_002_create_ng_app(self): actual = PerfUtils.get_average_time( lambda: Tns.create(app_name=APP_NAME, template=Template.HELLO_WORLD_NG.local_package, update=False), retry_count=RETRY_COUNT) expected = EXPECTED_RESULTS['hello-world-ng']['create'] assert PerfUtils.is_value_in_range( actual, expected, TOLERANCE), 'NG Hello Word project create time is not OK.'
def test_102_ng_app_apk(self): # Extract APK apk = TnsPaths.get_apk_path(app_name=self.ng_app, release=True) extracted_apk = os.path.join(Settings.TEST_OUT_TEMP, 'ng-apk') File.unzip(file_path=apk, dest_dir=extracted_apk) assets_app = os.path.join(extracted_apk, 'assets', 'app') assets_snapshots = os.path.join(extracted_apk, 'assets', 'snapshots') # No asserts for lib and res, since it is same as JS project assert PerfUtils.is_value_in_range(actual=Folder.get_size(assets_app), expected=1342382, tolerance=0.1) assert PerfUtils.is_value_in_range( actual=Folder.get_size(assets_snapshots), expected=13157964, tolerance=0.1) # Verify final apk size assert PerfUtils.is_value_in_range(actual=File.get_size(apk), expected=20087522, tolerance=0.05)
def test_302_prepare_with_doctor_do_not_make_it_much_slower(self): pa_d_time = PerfUtils.get_average_time( lambda: Tns.prepare_android(app_name=APP_NAME), retry_count=RETRY_COUNT) pi_d_time = PerfUtils.get_average_time( lambda: Tns.prepare_ios(app_name=APP_NAME), retry_count=RETRY_COUNT) os.environ['NS_SKIP_ENV_CHECK'] = 'true' pa_nd_time = PerfUtils.get_average_time( lambda: Tns.prepare_android(app_name=APP_NAME), retry_count=RETRY_COUNT) pi_nd_time = PerfUtils.get_average_time( lambda: Tns.prepare_ios(app_name=APP_NAME), retry_count=RETRY_COUNT) android_diff = pa_d_time - pa_nd_time ios_diff = pi_d_time - pi_nd_time assert PerfUtils.is_value_in_range( android_diff, 3, tolerance=1.0), 'Prepare android with common is slower.' assert PerfUtils.is_value_in_range( ios_diff, 6, tolerance=0.5), 'Prepare ios with common is slower.'
def test_002_js_app_node_modules(self): folder = os.path.join(TnsPaths.get_app_path(app_name=self.js_app), 'node_modules') assert PerfUtils.is_value_in_range(actual=Folder.get_size(folder), expected=51791943, tolerance=0.2)
def test_001_js_app_app_resources(self): folder = os.path.join(TnsPaths.get_app_path(app_name=self.js_app), 'app') assert PerfUtils.is_value_in_range(actual=Folder.get_size(folder), expected=2991548, tolerance=0.1)
def test_101_ng_app_node_modules(self): app_folder = os.path.join(TnsPaths.get_app_path(app_name=self.ng_app), 'node_modules') assert PerfUtils.is_value_in_range(actual=Folder.get_size(app_folder), expected=200248003, tolerance=0.2)
def test_100_ng_app_app_resources(self): app_folder = os.path.join(TnsPaths.get_app_path(app_name=self.ng_app), 'App_Resources') assert PerfUtils.is_value_in_range(actual=Folder.get_size(app_folder), expected=2986244, tolerance=0.1)
def test_301_doctor_performance_inside_project(self): time = PerfUtils.get_average_time( lambda: Tns.doctor(app_name=APP_NAME), retry_count=RETRY_COUNT) assert PerfUtils.is_value_in_range( actual=time, expected=10.73), 'Doctor exec time is not OK.'
def test_300_doctor_performance_outside_project(self): time = PerfUtils.get_average_time(lambda: Tns.doctor(), retry_count=RETRY_COUNT) assert PerfUtils.is_value_in_range( actual=time, expected=9.63), 'Doctor exec time is not OK.'
def created(app_name, output=None, app_data=None, path=Settings.TEST_RUN_HOME, webpack=True, theme=True): """ Verify app is created properly. :param app_name: Name of the app. :param output: Console output of `tns create` command. :param app_data: AppInfo object. :param path: Base path where app is created. :param webpack: If true it will verify webpack plugin is installed. :param theme: If true it will verify default {N} theme is installed. """ # Assert app exists app_path = os.path.join(path, app_name) assert Folder.exists( app_path ), 'Failed to create app. ' + os.linesep + app_path + ' do not exists!' # Assert output if output is not None: assert 'Now you can navigate to your project with $ cd' in output assert 'After that you can preview it on device by executing $ tns preview' in output assert 'After that you can run it on device/emulator by executing $ tns run <platform>' not in output assert 'Project {0} was successfully created'.format(app_name) in output, \ 'Failed to create {0}'.format(app_name) # Verify modules installed node_path = TnsPaths.get_app_node_modules_path(app_name=app_name, path=path) assert Folder.exists(os.path.join( node_path, 'tns-core-modules')), '{N} theme do not exists in app.' assert File.exists( os.path.join(node_path, 'tns-core-modules', 'tns-core-modules.d.ts')) # Verify {N} core theme is installed if theme: assert Folder.exists( os.path.join( node_path, 'nativescript-theme-core')), '{N} theme do not exists.' # Verify webpack is installed before_watch_hooks = os.path.join(app_path, 'hooks', 'before-watch') if webpack: assert Folder.exists( os.path.join(node_path, 'nativescript-dev-webpack') ), 'Webpack not installed in app.' assert File.exists(os.path.join( app_path, 'webpack.config.js')), 'Missing webpack config.' # Assert app data if app_data is not None: # Verify typescript in TS and NG apps: if app_data.app_type in { AppType.TS, AppType.NG, AppType.SHARED_NG }: assert not Folder.exists(os.path.join(node_path, 'nativescript-dev-typescript')), \ 'TS not installed in app.' assert File.exists(os.path.join( app_path, 'tsconfig.json')), 'Missing config.' if webpack: assert File.exists( os.path.join(app_path, 'tsconfig.tns.json')), 'Missing config.' assert not File.exists(os.path.join(before_watch_hooks, 'nativescript-dev-typescript.js')), \ 'Hooks not installed.' # Assert app id if app_data.bundle_id is not None: pass # Assert size if app_data.size is not None: app_size = Folder.get_size(app_path) assert PerfUtils.is_value_in_range( actual=app_size, expected=app_data.size.init, tolerance=0.25), 'Actual project size is not expected!'