def create_app_ng(app_name, attributes={}, log_trace=False, assert_success=True, update_modules=True, template_version=None): if template_version is not None: template = "tns-template-hello-world-ng@" + template_version attr = {"--template": template} else: if BRANCH is "master": attr = {"--template": SUT_FOLDER + os.path.sep + "tns-template-hello-world-ng.tgz"} else: attr = {"--template": "tns-template-hello-world-ng"} attributes.update(attr) output = Tns.create_app(app_name=app_name, attributes=attributes, log_trace=log_trace, assert_success=assert_success, update_modules=update_modules) if update_modules: Tns.update_angular(path=app_name) Tns.update_typescript(path=app_name) if assert_success: if USE_YARN != "True": if Npm.version() < 5: assert "nativescript-angular" in output assert File.exists(os.path.join(app_name, 'node_modules', 'nativescript-theme-core')) package_json = File.read(os.path.join(app_name, 'package.json')) assert "tns-core-modules" in package_json assert "nativescript-angular" in package_json assert "nativescript-dev-typescript" in package_json return output
def update_webpack(path): """ Update modules for {N} project :param path: Path to {N} project :return: Output of command that update nativescript-dev-webpack plugin. """ # Escape path with spaces if " " in path: path = "\"" + path + "\"" if USE_YARN == "True": Npm.uninstall(package="nativescript-dev-webpack", option="--dev", folder=path) output = Npm.install(package=WEBPACK_PACKAGE, option="--dev", folder=path) else: Npm.uninstall(package="nativescript-dev-webpack", option="--save-dev", folder=path) output = Npm.install(package=WEBPACK_PACKAGE, option="--save-dev", folder=path) if Npm.version() > 3: assert "ERR" not in output, "Something went wrong when webpack are installed." # Update webpack dependencies update_script = os.path.join(TEST_RUN_HOME, path, "node_modules", ".bin", "update-ns-webpack --deps --configs") run(update_script) if USE_YARN == "True": Folder.cleanup(folder=os.path.join(TEST_RUN_HOME, path, "node_modules")) Npm.yarn_install(folder=path) else: Npm.install(folder=path) return output
def update_typescript(path): """ Update modules for {N} project :param path: Path to {N} project :return: Output of command that update nativescript-typescript plugin. """ # Escape path with spaces if " " in path: path = "\"" + path + "\"" if USE_YARN == "True": Npm.uninstall(package="nativescript-typescript", folder=path) output = Npm.install(package=TYPESCRIPT_PACKAGE, folder=path) else: Npm.uninstall(package="nativescript-typescript", option="--save", folder=path) output = Npm.install(package=TYPESCRIPT_PACKAGE, option="--save", folder=path) if Npm.version() > 3: assert "ERR" not in output, "Something went wrong when typescript are installed." # Update TS dependencies update_script = os.path.join(TEST_RUN_HOME, path, "node_modules", ".bin", "ns-upgrade-tsconfig") run(update_script) if USE_YARN == "True": Npm.yarn_install(folder=path) else: Npm.install(folder=path) return output
def update_typescript(path): """ Update modules for {N} project :param path: Path to {N} project :return: Output of command that update nativescript-typescript plugin. """ # Escape path with spaces if " " in path: path = "\"" + path + "\"" if USE_YARN == "True": Npm.uninstall(package="nativescript-typescript", folder=path) output = Npm.install(package=TYPESCRIPT_PACKAGE, folder=path) else: Npm.uninstall(package="nativescript-typescript", option="--save", folder=path) output = Npm.install(package=TYPESCRIPT_PACKAGE, option="--save", folder=path) if Npm.version() > 3: assert "ERR" not in output, "Something went wrong when typescript are installed." # Update TS dependencies update_script = os.path.join(TEST_RUN_HOME, path, "node_modules", ".bin", "ns-upgrade-tsconfig") run(update_script) if USE_YARN == "True": Npm.yarn_install(folder=path) else: Npm.install(folder=path) return output
def update_angular(path): """ Update modules for {N} project :param path: Path to {N} project :return: Output of command that update nativescript-angular plugin. """ # Escape path with spaces if " " in path: path = "\"" + path + "\"" if USE_YARN == "True": Npm.uninstall(package="nativescript-angular", folder=path) output = Npm.install(package=ANGULAR_PACKAGE, folder=path) else: Npm.uninstall(package="nativescript-angular", option="--save", folder=path) output = Npm.install(package=ANGULAR_PACKAGE, option="--save", folder=path) if Npm.version() > 3: assert "ERR" not in output, "Something went wrong when angular are installed." # Update NG dependencies update_script = os.path.join(TEST_RUN_HOME, path, "node_modules", ".bin", "update-app-ng-deps") update_out = run(update_script) assert "Angular dependencies updated" in update_out if USE_YARN == "True": Npm.yarn_install(folder=path) else: Npm.install(folder=path) return output
def created_ts(app_name, output=None): """ Assert TypeScript application is created properly. :param app_name: App name :param output: Output of `tns create command` """ # First make sure base app is created TnsAsserts.created(app_name=app_name, output=output) # Assert output contains TypeScript plugin if USE_YARN != "True": if Npm.version() < 5: assert 'nativescript-dev-typescript' in output # Assert files added with TypeScript plugin ts_config = os.path.join(app_name, 'tsconfig.json') ref_dts = os.path.join(app_name, 'references.d.ts') dts = os.path.join(app_name, TnsAsserts.TNS_MODULES, 'tns-core-modules.d.ts') # Assert content of files added with TypeScript plugin. assert File.exists(ts_config) assert not File.exists(ref_dts) assert File.exists(dts) ts_config_json = TnsAsserts.get_tsconfig_json(app_name=app_name) paths = ts_config_json.get('compilerOptions').get('paths') assert paths is not None, 'Paths missing in tsconfig.json' assert not Folder.is_empty(os.path.join(app_name, TnsAsserts.NODE_MODULES, 'nativescript-dev-typescript')) assert File.exists(os.path.join(app_name, TnsAsserts.HOOKS, 'before-prepare', 'nativescript-dev-typescript.js')) assert File.exists(os.path.join(app_name, TnsAsserts.HOOKS, 'before-watch', 'nativescript-dev-typescript.js')) assert File.exists(os.path.join(app_name, TnsAsserts.NODE_MODULES, 'typescript', 'bin', 'tsc'))
def created(app_name, output=None, full_check=True): """ Assert application is created properly. :param app_name: App name :param output: Output of `tns create command` :param full_check: If true everything will be checked. If false only console output will be checked. """ # Assert console output is ok if output is not None: app = app_name.rsplit('/')[-1] if USE_YARN != "True": if Npm.version() < 5: assert 'nativescript-theme-core' in output assert 'Project {0} was successfully created'.format(app) in output, 'Failed to create {0}'.format(app) if full_check: # Assert files are ok assert File.exists(app_name) assert File.exists(app_name + '/node_modules/tns-core-modules/package.json') assert File.exists(app_name + '/node_modules/tns-core-modules/LICENSE') assert File.exists(app_name + '/node_modules/tns-core-modules/xml/xml.js') assert File.exists(app_name + '/node_modules/nativescript-theme-core') # Assert content of package.json app_id = app_name.replace(' ', '').replace('_', '').replace('-', '').rsplit('/')[-1] strings = ['org.nativescript.{0}'.format(app_id), 'tns-core-modules', 'nativescript-theme-core'] TnsAsserts.package_json_contains(app_name, string_list=strings)
def create_app_ng(app_name, attributes={}, log_trace=False, assert_success=True, update_modules=True, template_version=None): if template_version is not None: template = "tns-template-hello-world-ng@" + template_version attr = {"--template": template} else: if BRANCH is "master": attr = { "--template": SUT_FOLDER + os.path.sep + "tns-template-hello-world-ng.tgz" } else: attr = {"--template": "tns-template-hello-world-ng"} attributes.update(attr) output = Tns.create_app(app_name=app_name, attributes=attributes, log_trace=log_trace, assert_success=assert_success, update_modules=update_modules) if update_modules: Tns.update_angular(path=app_name) Tns.update_typescript(path=app_name) if assert_success: if USE_YARN != "True": if Npm.version() < 5: assert "nativescript-angular" in output assert File.exists( os.path.join(app_name, 'node_modules', 'nativescript-theme-core')) package_json = File.read(os.path.join(app_name, 'package.json')) assert "tns-core-modules" in package_json assert "nativescript-angular" in package_json assert "nativescript-dev-typescript" in package_json return output
def created_ts(app_name, output=None): """ Assert TypeScript application is created properly. :param app_name: App name :param output: Output of `tns create command` """ # First make sure base app is created TnsAsserts.created(app_name=app_name, output=output) # Assert output contains TypeScript plugin if USE_YARN != "True": if Npm.version() < 5: assert 'nativescript-dev-typescript' in output # Assert files added with TypeScript plugin ts_config = os.path.join(app_name, 'tsconfig.json') ref_dts = os.path.join(app_name, 'references.d.ts') dts = os.path.join(app_name, TnsAsserts.TNS_MODULES, 'tns-core-modules.d.ts') # Assert content of files added with TypeScript plugin. assert File.exists(ts_config) assert not File.exists(ref_dts) assert File.exists(dts) ts_config_json = TnsAsserts.get_tsconfig_json(app_name=app_name) paths = ts_config_json.get('compilerOptions').get('paths') assert paths is not None, 'Paths missing in tsconfig.json' assert not Folder.is_empty( os.path.join(app_name, TnsAsserts.NODE_MODULES, 'nativescript-dev-typescript')) assert File.exists( os.path.join(app_name, TnsAsserts.HOOKS, 'before-prepare', 'nativescript-dev-typescript.js')) assert File.exists( os.path.join(app_name, TnsAsserts.HOOKS, 'before-watch', 'nativescript-dev-typescript.js')) assert File.exists( os.path.join(app_name, TnsAsserts.NODE_MODULES, 'typescript', 'bin', 'tsc'))
def update_modules(path): """ Update modules for {N} project :param path: Path to {N} project :return: Output of command that update tns-core-modules plugin. """ # Escape path with spaces if " " in path: path = "\"" + path + "\"" if USE_YARN == "True": Npm.uninstall(package="tns-core-modules", folder=path) output = Npm.install(package=MODULES_PACKAGE, folder=path) else: Npm.uninstall(package="tns-core-modules", option="--save", folder=path) output = Npm.install(package=MODULES_PACKAGE, option="--save", folder=path) if Npm.version() > 3: assert "ERR" not in output, "Something went wrong when modules are installed." return output
def update_webpack(path): """ Update modules for {N} project :param path: Path to {N} project :return: Output of command that update nativescript-dev-webpack plugin. """ # Escape path with spaces if " " in path: path = "\"" + path + "\"" if USE_YARN == "True": Npm.uninstall(package="nativescript-dev-webpack", option="--dev", folder=path) output = Npm.install(package=WEBPACK_PACKAGE, option="--dev", folder=path) else: Npm.uninstall(package="nativescript-dev-webpack", option="--save-dev", folder=path) output = Npm.install(package=WEBPACK_PACKAGE, option="--save-dev", folder=path) if Npm.version() > 3: assert "ERR" not in output, "Something went wrong when webpack are installed." # Update webpack dependencies update_script = os.path.join(TEST_RUN_HOME, path, "node_modules", ".bin", "update-ns-webpack --deps --configs") run(update_script) if USE_YARN == "True": Folder.cleanup( folder=os.path.join(TEST_RUN_HOME, path, "node_modules")) Npm.yarn_install(folder=path) else: Npm.install(folder=path) return output
def created(app_name, output=None, full_check=True): """ Assert application is created properly. :param app_name: App name :param output: Output of `tns create command` :param full_check: If true everything will be checked. If false only console output will be checked. """ # Assert console output is ok if output is not None: app = app_name.rsplit('/')[-1] if USE_YARN != "True": if Npm.version() < 5: assert 'nativescript-theme-core' in output assert 'Project {0} was successfully created'.format( app) in output, 'Failed to create {0}'.format(app) if full_check: # Assert files are ok assert File.exists(app_name) assert File.exists(app_name + '/node_modules/tns-core-modules/package.json') assert File.exists(app_name + '/node_modules/tns-core-modules/LICENSE') assert File.exists(app_name + '/node_modules/tns-core-modules/xml/xml.js') assert File.exists(app_name + '/node_modules/nativescript-theme-core') # Assert content of package.json app_id = app_name.replace(' ', '').replace('_', '').replace( '-', '').rsplit('/')[-1] strings = [ 'org.nativescript.{0}'.format(app_id), 'tns-core-modules', 'nativescript-theme-core' ] TnsAsserts.package_json_contains(app_name, string_list=strings)
def update_angular(path): """ Update modules for {N} project :param path: Path to {N} project :return: Output of command that update nativescript-angular plugin. """ # Escape path with spaces if " " in path: path = "\"" + path + "\"" if USE_YARN == "True": Npm.uninstall(package="nativescript-angular", folder=path) output = Npm.install(package=ANGULAR_PACKAGE, folder=path) else: Npm.uninstall(package="nativescript-angular", option="--save", folder=path) output = Npm.install(package=ANGULAR_PACKAGE, option="--save", folder=path) if Npm.version() > 3: assert "ERR" not in output, "Something went wrong when angular are installed." # Update NG dependencies update_script = os.path.join(TEST_RUN_HOME, path, "node_modules", ".bin", "update-app-ng-deps") update_out = run(update_script) assert "Angular dependencies updated" in update_out if USE_YARN == "True": Npm.yarn_install(folder=path) else: Npm.install(folder=path) return output
def update_modules(path): """ Update modules for {N} project :param path: Path to {N} project :return: Output of command that update tns-core-modules plugin. """ # Escape path with spaces if " " in path: path = "\"" + path + "\"" if USE_YARN == "True": Npm.uninstall(package="tns-core-modules", folder=path) output = Npm.install(package=MODULES_PACKAGE, folder=path) else: Npm.uninstall(package="tns-core-modules", option="--save", folder=path) output = Npm.install(package=MODULES_PACKAGE, option="--save", folder=path) if Npm.version() > 3: assert "ERR" not in output, "Something went wrong when modules are installed." return output