예제 #1
0
 def _get_package_managers(self):
     npm = PackageManagerNpm([self._install_node])
     yarnpkg = PackageManagerYarnpkg([self._install_node, self._install_yarnpkg])
     return {
         PACKAGE_MANAGER_NPM: npm,
         PACKAGE_MANAGER_YARNPKG: yarnpkg,
         PACKAGE_MANAGER_YARNPKG_ALIAS: yarnpkg,  # Allow yarn to be used as an alias for yarnpkg
     }
예제 #2
0
 def setUp(self):
   self.npm = PackageManagerNpm([fake_install])
예제 #3
0
class TestNpm(unittest.TestCase):

  def setUp(self):
    self.npm = PackageManagerNpm([fake_install])
  
  def test_run_cli(self, mock_command_gen):
    fake_cli = 'fake_cli'
    args = ['arg1', 'arg2']

    self.assertRaises(RuntimeError, self.npm.run_cli, fake_cli, args=args)

  def test_run_script(self, mock_command_gen):
    script_name = 'script_name'
    script_args = ['arg1', 'arg2']
    self.npm.run_script(script_name, script_args=script_args)
    mock_command_gen.assert_called_once_with(
      [fake_install], 'npm',
      args=(['run-script', script_name, '--'] + script_args), node_paths=None)

  def test_install_module_options_off(self, mock_command_gen):
    self.npm.install_module(
      install_optional=False, production_only=False, force=False)
    mock_command_gen.assert_called_once_with(
      [fake_install], 'npm',
      args=['install', '--no-optional'], node_paths=None
    )

  def test_install_module_options_on(self, mock_command_gen):
    self.npm.install_module(
      install_optional=True, production_only=True, force=True)
    mock_command_gen.assert_called_once_with(
      [fake_install], 'npm',
      args=['install', '--production', '--force'], node_paths=None
    )

  def test_add_package_default(self, mock_command_gen):
    package_name = 'package_name'
    self.npm.add_package(package_name)
    mock_command_gen.assert_called_once_with(
      [fake_install], 'npm',
      args=['install', package_name, '--save-prod'],
      node_paths=None
    )

  def test_add_package_other_options(self, mock_command_gen):
    package_name = 'package_name'
    for type_option, expected_args in {
      PackageInstallationTypeOption.DEV: ['--save-dev'],
      PackageInstallationTypeOption.PEER: [],
      PackageInstallationTypeOption.OPTIONAL: ['--save-optional'],
      PackageInstallationTypeOption.BUNDLE: ['--save-bundle'],
      PackageInstallationTypeOption.NO_SAVE: ['--no-save'],
    }.items():
      self.npm.add_package(
        package_name,
        type_option=type_option,
      )
      mock_command_gen.assert_called_once_with(
        [fake_install], 'npm',
        args=['install', package_name] + expected_args,
        node_paths=None
      )
      mock_command_gen.reset_mock()
    for version_option, expected_args in {
      PackageInstallationVersionOption.EXACT: ['--save-exact'],
      PackageInstallationVersionOption.TILDE: [],
    }.items():
      self.npm.add_package(
        package_name,
        version_option=version_option,
      )
      mock_command_gen.assert_called_once_with(
        [fake_install], 'npm',
        args=['install', package_name, '--save-prod'] + expected_args,
        node_paths=None
      )
      mock_command_gen.reset_mock()
예제 #4
0
class TestNpm(unittest.TestCase):
    def setUp(self):
        self.npm = PackageManagerNpm([fake_install])

    def test_run_cli(self, mock_command_gen):
        fake_cli = "fake_cli"
        args = ["arg1", "arg2"]

        self.assertRaises(RuntimeError, self.npm.run_cli, fake_cli, args=args)

    def test_run_script(self, mock_command_gen):
        script_name = "script_name"
        script_args = ["arg1", "arg2"]
        self.npm.run_script(script_name, script_args=script_args)
        mock_command_gen.assert_called_once_with(
            [fake_install],
            "npm",
            args=(["run-script", script_name, "--"] + script_args),
            node_paths=None,
        )

    def test_install_module_options_off(self, mock_command_gen):
        self.npm.install_module(install_optional=False, production_only=False, force=False)
        mock_command_gen.assert_called_once_with(
            [fake_install], "npm", args=["install", "--no-optional"], node_paths=None
        )

    def test_install_module_options_on(self, mock_command_gen):
        self.npm.install_module(install_optional=True, production_only=True, force=True)
        mock_command_gen.assert_called_once_with(
            [fake_install], "npm", args=["install", "--production", "--force"], node_paths=None
        )

    def test_add_package_default(self, mock_command_gen):
        package_name = "package_name"
        self.npm.add_package(package_name)
        mock_command_gen.assert_called_once_with(
            [fake_install], "npm", args=["install", package_name, "--save-prod"], node_paths=None
        )

    def test_add_package_other_options(self, mock_command_gen):
        package_name = "package_name"
        for type_option, expected_args in {
            PackageInstallationTypeOption.DEV: ["--save-dev"],
            PackageInstallationTypeOption.PEER: [],
            PackageInstallationTypeOption.OPTIONAL: ["--save-optional"],
            PackageInstallationTypeOption.BUNDLE: ["--save-bundle"],
            PackageInstallationTypeOption.NO_SAVE: ["--no-save"],
        }.items():
            self.npm.add_package(
                package_name, type_option=type_option,
            )
            mock_command_gen.assert_called_once_with(
                [fake_install],
                "npm",
                args=["install", package_name] + expected_args,
                node_paths=None,
            )
            mock_command_gen.reset_mock()
        for version_option, expected_args in {
            PackageInstallationVersionOption.EXACT: ["--save-exact"],
            PackageInstallationVersionOption.TILDE: [],
        }.items():
            self.npm.add_package(
                package_name, version_option=version_option,
            )
            mock_command_gen.assert_called_once_with(
                [fake_install],
                "npm",
                args=["install", package_name, "--save-prod"] + expected_args,
                node_paths=None,
            )
            mock_command_gen.reset_mock()