Ejemplo n.º 1
0
    def test_build_from_local_fixes_symlinks(self):
        class Options:
            source = '.'
            node_packages = []
            node_engine = '4'
            npm_run = []
            node_package_manager = 'npm'
            source = '.'

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'package.json'), 'w').close()

        # Setup stub project symlinks
        modules_path = os.path.join('lib', 'node_modules')
        project_path = os.path.join(plugin.installdir, modules_path, 'project')
        dep_path = os.path.join(modules_path, 'dep')
        os.makedirs(os.path.join(plugin.builddir, dep_path))
        os.makedirs(os.path.join(plugin.installdir, modules_path))
        os.symlink(os.path.join('..', '..', '..', 'build'), project_path)

        plugin.build()

        self.assertThat(project_path, DirExists())
        self.assertThat(os.path.join(project_path, dep_path), DirExists())
        self.assertFalse(os.path.islink(project_path))
Ejemplo n.º 2
0
    def test_build_executes_npm_run_commands(self):
        class Options:
            source = '.'
            node_packages = []
            node_engine = '4'
            npm_run = ['command_one', 'avocado']
            node_package_manager = self.package_manager
            source = '.'

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'package.json'), 'w').close()

        plugin.build()

        if self.package_manager == 'npm':
            cmd = ['npm', 'run']
        else:
            cmd = [os.path.join(plugin.partdir, 'npm', 'bin', 'yarn'), 'run']

        expected_run_calls = [
            mock.call(cmd + ['command_one'], cwd=plugin.builddir),
            mock.call(cmd + ['avocado'], cwd=plugin.builddir),
        ]
        self.run_mock.assert_has_calls(expected_run_calls)
Ejemplo n.º 3
0
    def test_missing_package_json(self):
        plugin = nodejs.NodePlugin("test-part", self.options, self.project)

        self.create_assets(plugin, skip_package_json=True)

        self.assertRaises(nodejs.NodejsPluginMissingPackageJsonError,
                          plugin.pull)
Ejemplo n.º 4
0
    def test_build_executes_npm_run_commands(self):
        self.options.npm_run = ["command_one", "avocado"]
        self.options.node_package_manager = self.package_manager

        plugin = nodejs.NodePlugin("test-part", self.options,
                                   self.project_options)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, "package.json"), "w").close()

        plugin.build()

        if self.package_manager == "npm":
            cmd = ["npm", "run"]
            expected_run_calls = [
                mock.call(cmd + ["command_one"], cwd=plugin.builddir),
                mock.call(cmd + ["avocado"], cwd=plugin.builddir),
            ]
        else:
            cmd = [os.path.join(plugin.partdir, "npm", "bin", "yarn")]
            env = dict()
            if self.http_proxy is not None:
                cmd.extend(["--proxy", self.http_proxy])
                env["http_proxy"] = self.http_proxy
            if self.https_proxy is not None:
                cmd.extend(["--https-proxy", self.https_proxy])
                env["https_proxy"] = self.https_proxy
            cmd.append("run")
            expected_run_calls = [
                mock.call(cmd + ["command_one"], cwd=plugin.builddir, env=env),
                mock.call(cmd + ["avocado"], cwd=plugin.builddir, env=env),
            ]

        self.run_mock.assert_has_calls(expected_run_calls)
Ejemplo n.º 5
0
    def test_build_local_sources(self):
        class Options:
            source = '.'
            node_packages = []
            node_engine = '4'
            npm_run = []

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'package.json'), 'w').close()

        plugin.build()

        self.run_mock.assert_has_calls([
            mock.call(['npm', '--cache-min=Infinity', 'install'],
                      cwd=plugin.builddir),
            mock.call(['npm', '--cache-min=Infinity', 'install', '--global'],
                      cwd=plugin.builddir)
        ])
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine),
                path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
            mock.call().provision(plugin.installdir,
                                  clean_target=False,
                                  keep_tarball=True)
        ])
Ejemplo n.º 6
0
    def test_pull_local_sources(self):
        self.options.node_package_manager = self.package_manager

        plugin = nodejs.NodePlugin('test-part', self.options,
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()

        if self.package_manager == 'npm':
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().download(),
                mock.call().provision(plugin.installdir,
                                      clean_target=False,
                                      keep_tarball=True),
            ]
        else:
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call('https://yarnpkg.com/latest.tar.gz',
                          plugin._npm_dir),
                mock.call().download(),
                mock.call().download(),
                mock.call().provision(plugin.installdir,
                                      clean_target=False,
                                      keep_tarball=True),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False,
                                      keep_tarball=True),
            ]

        self.run_mock.assert_has_calls([])
        self.tar_mock.assert_has_calls(expected_tar_calls)
Ejemplo n.º 7
0
    def test_build_executes_npm_run_commands(self):
        self.options.npm_run = ['command_one', 'avocado']
        self.options.node_package_manager = self.package_manager

        plugin = nodejs.NodePlugin('test-part', self.options,
                                   self.project_options)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'package.json'), 'w').close()

        plugin.build()

        if self.package_manager == 'npm':
            cmd = ['npm', 'run']
            expected_run_calls = [
                mock.call(cmd + ['command_one'], cwd=plugin.builddir),
                mock.call(cmd + ['avocado'], cwd=plugin.builddir),
            ]
        else:
            cmd = [os.path.join(plugin.partdir, 'npm', 'bin', 'yarn')]
            env = dict()
            if self.http_proxy is not None:
                cmd.extend(['--proxy', self.http_proxy])
                env['http_proxy'] = self.http_proxy
            if self.https_proxy is not None:
                cmd.extend(['--https-proxy', self.https_proxy])
                env['https_proxy'] = self.https_proxy
            cmd.append('run')
            expected_run_calls = [
                mock.call(cmd + ['command_one'], cwd=plugin.builddir, env=env),
                mock.call(cmd + ['avocado'], cwd=plugin.builddir, env=env),
            ]

        self.run_mock.assert_has_calls(expected_run_calls)
Ejemplo n.º 8
0
    def test_pull_executes_npm_run_commands(self):
        self.options.npm_run = ['command_one', 'avocado']
        self.options.node_package_manager = self.package_manager

        plugin = nodejs.NodePlugin('test-part', self.options,
                                   self.project_options)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'package.json'), 'w').close()

        plugin.pull()

        if self.package_manager == 'npm':
            cmd = ['npm', 'run']
            expected_run_calls = [
                mock.call(cmd + ['command_one'],
                          cwd=plugin.sourcedir),
                mock.call(cmd + ['avocado'],
                          cwd=plugin.sourcedir),
            ]
        else:
            cmd = [os.path.join(plugin.partdir, 'npm', 'bin', 'yarn'), 'run']
            hidden_bin_path = os.path.join(
                plugin.sourcedir, 'node_modules', '.bin')
            expected_run_calls = [
                mock.call(cmd + ['command_one'],
                          cwd=plugin.sourcedir,
                          env=dict(PATH=hidden_bin_path)),
                mock.call(cmd + ['avocado'],
                          cwd=plugin.sourcedir,
                          env=dict(PATH=hidden_bin_path)),
            ]

        self.run_mock.assert_has_calls(expected_run_calls)
Ejemplo n.º 9
0
    def test_pull(self):
        plugin = nodejs.NodePlugin("test-part", self.options, self.project)

        self.create_assets(plugin)

        plugin.pull()

        if self.package_manager == "npm":
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().download(),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False,
                                      keep_tarball=True),
            ]
        else:
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().download(),
                mock.call("https://yarnpkg.com/latest.tar.gz",
                          plugin._npm_dir),
                mock.call().download(),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False,
                                      keep_tarball=True),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False,
                                      keep_tarball=True),
            ]

        self.tar_mock.assert_has_calls(expected_tar_calls)
Ejemplo n.º 10
0
    def test_pull_and_build_node_packages_sources(self):
        class Options:
            source = None
            node_packages = ['my-pkg']
            node_engine = '4'

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()
        plugin.build()

        self.run_mock.assert_has_calls([
            mock.call(['npm', 'install', '-g', 'my-pkg'], cwd=plugin.builddir)
        ])
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine),
                path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
            mock.call().download(),
            mock.call().provision(plugin.installdir,
                                  clean_target=False,
                                  keep_tarball=True)
        ])
Ejemplo n.º 11
0
    def test_build_scoped_name(self):
        plugin = nodejs.NodePlugin("test-part", self.options, self.project)

        self.create_assets(plugin, package_name="@org/name")

        plugin.build()

        if self.package_manager == "npm":
            expected_run_calls = [
                mock.call(
                    [self.get_npm_cmd(plugin), "install", "--unsafe-perm"],
                    cwd=os.path.join(plugin.builddir),
                    env=mock.ANY,
                ),
                mock.call(
                    [self.get_npm_cmd(plugin), "pack"],
                    cwd=plugin.builddir,
                    env=mock.ANY,
                ),
                mock.call(
                    [
                        self.get_npm_cmd(plugin),
                        "install",
                        "--unsafe-perm",
                        "--offline",
                        "--prod",
                    ],
                    cwd=os.path.join(plugin.builddir, "package"),
                    env=mock.ANY,
                ),
            ]
        else:
            cmd = [self.get_yarn_cmd(plugin)]
            if self.http_proxy is not None:
                cmd.extend(["--proxy", self.http_proxy])
            if self.https_proxy is not None:
                cmd.extend(["--https-proxy", self.https_proxy])
            expected_run_calls = [
                mock.call(cmd + ["install"], cwd=plugin.builddir,
                          env=mock.ANY),
                mock.call(
                    cmd + ["pack", "--filename", "org-name-1.0.tgz"],
                    cwd=plugin.builddir,
                    env=mock.ANY,
                ),
                mock.call(
                    cmd + ["install", "--offline", "--prod"],
                    cwd=os.path.join(plugin.builddir, "package"),
                    env=mock.ANY,
                ),
            ]

        self.run_mock.assert_has_calls(expected_run_calls)

        expected_tar_calls = [
            mock.call("org-name-1.0.tgz", plugin.builddir),
            mock.call().provision(os.path.join(plugin.builddir, "package")),
        ]
        self.tar_mock.assert_has_calls(expected_tar_calls)
Ejemplo n.º 12
0
    def test_pull_and_build_node_packages_sources(self):
        self.options.node_packages = ['my-pkg']
        self.options.node_package_manager = self.package_manager

        plugin = nodejs.NodePlugin('test-part', self.options,
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()
        plugin.build()

        if self.package_manager == 'npm':
            cmd = ['npm', '--cache-min=Infinity', 'install',
                   '--global', 'my-pkg']
            expected_run_calls = [
                mock.call(cmd, cwd=plugin.sourcedir),
                mock.call(cmd, cwd=plugin.builddir),
            ]
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().download(),
                mock.call().provision(
                    plugin.installdir, clean_target=False, keep_tarball=True),
            ]
        else:
            cmd = [os.path.join(plugin.partdir, 'npm', 'bin', 'yarn')]
            if self.http_proxy is not None:
                cmd.extend(['--proxy', self.http_proxy])
            if self.https_proxy is not None:
                cmd.extend(['--https-proxy', self.https_proxy])
            expected_run_calls = [
                mock.call(cmd + ['add', 'my-pkg'],
                          cwd=plugin.sourcedir),
                mock.call(cmd +
                          ['global', 'add', 'my-pkg',
                           '--offline', '--prod',
                           '--global-folder', plugin.installdir,
                           '--prefix', plugin.installdir],
                          cwd=plugin.builddir)
            ]
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call('https://yarnpkg.com/latest.tar.gz',
                          plugin._npm_dir),
                mock.call().download(),
                mock.call().download(),
                mock.call().provision(plugin.installdir, clean_target=False,
                                      keep_tarball=True),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False, keep_tarball=True),
                mock.call().provision(plugin.installdir, clean_target=False,
                                      keep_tarball=True),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False, keep_tarball=True),
            ]

        self.run_mock.assert_has_calls(expected_run_calls)
        self.tar_mock.assert_has_calls(expected_tar_calls)
Ejemplo n.º 13
0
    def test_build_with_npm_flags(self):
        self.options.node_package_manager = self.package_manager
        self.options.npm_flags = ['--test-flag']

        open('package.json', 'w').close()

        plugin = nodejs.NodePlugin('test-part', self.options,
                                   self.project_options)

        os.makedirs(plugin.builddir)
        open(os.path.join(plugin.builddir, 'package.json'), 'w').close()

        plugin.build()

        if self.package_manager == 'npm':
            cmd = ['npm', '--test-flag', '--cache-min=Infinity', 'install']
            expected_run_calls = [
                mock.call(cmd, cwd=plugin.builddir),
                mock.call(cmd + ['--global'], cwd=plugin.builddir),
            ]
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().provision(plugin.installdir,
                                      clean_target=False,
                                      keep_tarball=True),
            ]
        else:
            cmd = [
                os.path.join(plugin.partdir, 'npm', 'bin', 'yarn'),
                '--test-flag'
            ]
            if self.http_proxy is not None:
                cmd.extend(['--proxy', self.http_proxy])
            if self.https_proxy is not None:
                cmd.extend(['--https-proxy', self.https_proxy])
            expected_run_calls = [
                mock.call(cmd + [
                    'global', 'add', 'file:{}'.format(plugin.builddir),
                    '--offline', '--prod', '--global-folder',
                    plugin.installdir, '--prefix', plugin.installdir
                ],
                          cwd=plugin.builddir)
            ]
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().provision(plugin.installdir,
                                      clean_target=False,
                                      keep_tarball=True),
                mock.call('https://yarnpkg.com/latest.tar.gz',
                          plugin._npm_dir),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False,
                                      keep_tarball=True),
            ]

        self.run_mock.assert_has_calls(expected_run_calls)
        self.tar_mock.assert_has_calls(expected_tar_calls)
Ejemplo n.º 14
0
    def test_pull_and_build_node_packages_sources(self):
        class Options:
            source = None
            node_packages = ['my-pkg']
            node_engine = nodejs._NODEJS_VERSION
            npm_run = []
            node_package_manager = self.package_manager
            source = '.'

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()
        plugin.build()

        if self.package_manager == 'npm':
            cmd = ['npm', '--cache-min=Infinity', 'install',
                   '--global', 'my-pkg']
            expected_run_calls = [
                mock.call(cmd, cwd=plugin.sourcedir),
                mock.call(cmd, cwd=plugin.builddir),
            ]
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().download(),
                mock.call().provision(
                    plugin.installdir, clean_target=False, keep_tarball=True),
            ]
        else:
            cmd = os.path.join(plugin.partdir, 'npm', 'bin', 'yarn')
            expected_run_calls = [
                mock.call([cmd, 'add', 'my-pkg'],
                          cwd=plugin.sourcedir),
                mock.call([cmd, 'global', 'add', 'my-pkg',
                           '--offline', '--prod', '--global-folder',
                           plugin.installdir], cwd=plugin.builddir)
            ]
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call('https://yarnpkg.com/latest.tar.gz',
                          plugin._npm_dir),
                mock.call().download(),
                mock.call().download(),
                mock.call().provision(plugin.installdir, clean_target=False,
                                      keep_tarball=True),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False, keep_tarball=True),
                mock.call().provision(plugin.installdir, clean_target=False,
                                      keep_tarball=True),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False, keep_tarball=True),
            ]

        self.run_mock.assert_has_calls(expected_run_calls)
        self.tar_mock.assert_has_calls(expected_tar_calls)
Ejemplo n.º 15
0
    def test_unsupported_arch_raises_exception(self, machine_mock):
        machine_mock.return_value = 'fantasy-arch'

        class Options:
            source = None
            node_packages = []

        with self.assertRaises(EnvironmentError) as raised:
            nodejs.NodePlugin('test-part', Options())

        self.assertEqual(raised.exception.__str__(),
                         'architecture not supported (fantasy-arch)')
Ejemplo n.º 16
0
    def test_clean_pull_step(self):
        self.options.node_package_manager = self.package_manager

        plugin = nodejs.NodePlugin('test-part', self.options,
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()

        self.assertTrue(os.path.exists(plugin._npm_dir))

        plugin.clean_pull()

        self.assertFalse(os.path.exists(plugin._npm_dir))
Ejemplo n.º 17
0
    def test_get_manifest_with_node_packages(self):
        self.run_output_mock.return_value = self.ls_output

        self.options.node_package_manager = self.package_manager
        plugin = nodejs.NodePlugin('test-part', self.options,
                                   self.project_options)
        os.makedirs(plugin.sourcedir)

        plugin.build()

        self.assertThat(
            plugin.get_manifest(), Equals(
                collections.OrderedDict(
                    {'node-packages':
                     ['testpackage1=1.0', 'testpackage2=1.2']})))
Ejemplo n.º 18
0
    def test_get_manifest_with_yarn_lock_file(self):
        self.options.node_package_manager = 'yarn'
        plugin = nodejs.NodePlugin('test-part', self.options,
                                   self.project_options)
        os.makedirs(plugin.sourcedir)
        with open(os.path.join(plugin.sourcedir, 'yarn.lock'),
                  'w') as yarn_lock_file:
            yarn_lock_file.write('test yarn lock contents')

        plugin.build()

        expected_manifest = collections.OrderedDict()
        expected_manifest['yarn-lock-contents'] = 'test yarn lock contents'
        expected_manifest['node-packages'] = []

        self.assertThat(plugin.get_manifest(), Equals(expected_manifest))
Ejemplo n.º 19
0
    def test_get_manifest_with_yarn_lock_file(self):
        self.options.nodejs_package_manager = "yarn"
        plugin = nodejs.NodePlugin("test-part", self.options, self.project)

        self.create_assets(plugin)

        with open(os.path.join(plugin.builddir, "yarn.lock"), "w") as yarn_lock_file:
            yarn_lock_file.write("test yarn lock contents")

        plugin.build()

        expected_manifest = collections.OrderedDict()
        expected_manifest["yarn-lock-contents"] = "test yarn lock contents"
        expected_manifest["node-packages"] = []

        self.assertThat(plugin.get_manifest(), Equals(expected_manifest))
Ejemplo n.º 20
0
    def test_get_manifest_with_node_packages(self):
        self.run_output_mock.return_value = self.ls_output
        self.options.node_package_manager = self.package_manager

        plugin = nodejs.NodePlugin("test-part", self.options, self.project)

        self.create_assets(plugin)

        plugin.build()

        self.assertThat(
            plugin.get_manifest(),
            Equals(
                collections.OrderedDict(
                    {"node-packages": self.expected_dependencies})),
        )
Ejemplo n.º 21
0
    def test_clean_pull_step(self):
        class Options:
            source = '.'
            node_packages = []

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()

        self.assertTrue(os.path.exists(plugin._npm_dir))

        plugin.clean_pull()

        self.assertFalse(os.path.exists(plugin._npm_dir))
Ejemplo n.º 22
0
    def test_pull_local_sources(self):
        class Options:
            source = '.'
            node_packages = []

        plugin = nodejs.NodePlugin('test-part', Options())

        os.makedirs(plugin.sourcedir)

        plugin.pull()

        self.assertFalse(self.run_mock.called, 'run() was called')
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs._get_nodejs_release(),
                path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
            mock.call().pull()
        ])
Ejemplo n.º 23
0
    def test_build_executes_npm_run_commands(self):
        class Options:
            source = '.'
            node_packages = []
            node_engine = '4'
            npm_run = ['command_one', 'avocado']

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'package.json'), 'w').close()

        plugin.build()

        self.run_mock.assert_has_calls([
            mock.call(['npm', 'run', 'command_one'], cwd=plugin.builddir),
            mock.call(['npm', 'run', 'avocado'], cwd=plugin.builddir)
        ])
Ejemplo n.º 24
0
    def test_build_from_local_fixes_symlinks(self):
        plugin = nodejs.NodePlugin("test-part", self.options,
                                   self.project_options)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, "package.json"), "w").close()

        # Setup stub project symlinks
        modules_path = os.path.join("lib", "node_modules")
        project_path = os.path.join(plugin.installdir, modules_path, "project")
        dep_path = os.path.join(modules_path, "dep")
        os.makedirs(os.path.join(plugin.builddir, dep_path))
        os.makedirs(os.path.join(plugin.installdir, modules_path))
        os.symlink(os.path.join("..", "..", "..", "build"), project_path)

        plugin.build()

        self.assertThat(project_path, DirExists())
        self.assertThat(os.path.join(project_path, dep_path), DirExists())
        self.assertFalse(os.path.islink(project_path))
Ejemplo n.º 25
0
    def test_build_local_sources(self):
        class Options:
            source = '.'
            node_packages = []

        plugin = nodejs.NodePlugin('test-part', Options())

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'package.json'), 'w').close()

        plugin.build()

        self.run_mock.assert_has_calls(
            [mock.call(['npm', 'install', '-g'], cwd=plugin.builddir)])
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs._get_nodejs_release(),
                path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
            mock.call().provision(plugin.installdir)
        ])
Ejemplo n.º 26
0
    def test_pull_and_build_node_packages_sources(self):
        class Options:
            source = None
            node_packages = ['my-pkg']

        plugin = nodejs.NodePlugin('test-part', Options())

        os.makedirs(plugin.sourcedir)

        plugin.pull()
        plugin.build()

        self.run_mock.assert_has_calls([
            mock.call(['npm', 'install', '-g', 'my-pkg'], cwd=plugin.builddir)
        ])
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs._get_nodejs_release(),
                path.join(os.path.abspath('.'), 'parts', 'test-part', 'npm')),
            mock.call().pull(),
            mock.call().provision(plugin.installdir)
        ])
Ejemplo n.º 27
0
    def test_pull_local_sources(self):
        class Options:
            source = '.'
            node_packages = []
            node_engine = '4'
            npm_run = []

        plugin = nodejs.NodePlugin('test-part', Options(),
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()

        self.assertFalse(self.run_mock.called, 'run() was called')
        self.tar_mock.assert_has_calls([
            mock.call(
                nodejs.get_nodejs_release(plugin.options.node_engine,
                                          plugin.project.deb_arch),
                path.join(self.parts_dir, 'test-part', 'npm')),
            mock.call().download()
        ])
Ejemplo n.º 28
0
    def test_build_with_npm_flags(self):
        self.options.node_package_manager = self.package_manager
        self.options.npm_flags = ["--test-flag"]

        open("package.json", "w").close()

        plugin = nodejs.NodePlugin("test-part", self.options,
                                   self.project_options)

        os.makedirs(plugin.builddir)
        open(os.path.join(plugin.builddir, "package.json"), "w").close()

        plugin.build()

        if self.package_manager == "npm":
            cmd = ["npm", "--test-flag", "--cache-min=Infinity", "install"]
            expected_run_calls = [
                mock.call(cmd, cwd=plugin.builddir),
                mock.call(cmd + ["--global"], cwd=plugin.builddir),
            ]
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().provision(plugin.installdir,
                                      clean_target=False,
                                      keep_tarball=True),
            ]
        else:
            cmd = [
                os.path.join(plugin.partdir, "npm", "bin", "yarn"),
                "--test-flag"
            ]
            if self.http_proxy is not None:
                cmd.extend(["--proxy", self.http_proxy])
            if self.https_proxy is not None:
                cmd.extend(["--https-proxy", self.https_proxy])
            expected_run_calls = [
                mock.call(
                    cmd + [
                        "global",
                        "add",
                        "file:{}".format(plugin.builddir),
                        "--offline",
                        "--prod",
                        "--global-folder",
                        plugin.installdir,
                        "--prefix",
                        plugin.installdir,
                    ],
                    cwd=plugin.builddir,
                )
            ]
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().provision(plugin.installdir,
                                      clean_target=False,
                                      keep_tarball=True),
                mock.call("https://yarnpkg.com/latest.tar.gz",
                          plugin._npm_dir),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False,
                                      keep_tarball=True),
            ]

        self.run_mock.assert_has_calls(expected_run_calls)
        self.tar_mock.assert_has_calls(expected_tar_calls)
Ejemplo n.º 29
0
    def test_pull_and_build_node_packages_sources(self):
        self.options.node_packages = ["my-pkg"]
        self.options.node_package_manager = self.package_manager

        plugin = nodejs.NodePlugin("test-part", self.options,
                                   self.project_options)

        os.makedirs(plugin.sourcedir)

        plugin.pull()
        plugin.build()

        if self.package_manager == "npm":
            cmd = [
                "npm", "--cache-min=Infinity", "install", "--global", "my-pkg"
            ]
            expected_run_calls = [
                mock.call(cmd, cwd=plugin.sourcedir),
                mock.call(cmd, cwd=plugin.builddir),
            ]
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().download(),
                mock.call().provision(plugin.installdir,
                                      clean_target=False,
                                      keep_tarball=True),
            ]
        else:
            cmd = [os.path.join(plugin.partdir, "npm", "bin", "yarn")]
            if self.http_proxy is not None:
                cmd.extend(["--proxy", self.http_proxy])
            if self.https_proxy is not None:
                cmd.extend(["--https-proxy", self.https_proxy])
            expected_run_calls = [
                mock.call(cmd + ["add", "my-pkg"], cwd=plugin.sourcedir),
                mock.call(
                    cmd + [
                        "global",
                        "add",
                        "my-pkg",
                        "--offline",
                        "--prod",
                        "--global-folder",
                        plugin.installdir,
                        "--prefix",
                        plugin.installdir,
                    ],
                    cwd=plugin.builddir,
                ),
            ]
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().download(),
                mock.call("https://yarnpkg.com/latest.tar.gz",
                          plugin._npm_dir),
                mock.call().download(),
                mock.call().provision(plugin.installdir,
                                      clean_target=False,
                                      keep_tarball=True),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False,
                                      keep_tarball=True),
                mock.call().provision(plugin.installdir,
                                      clean_target=False,
                                      keep_tarball=True),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False,
                                      keep_tarball=True),
            ]

        self.run_mock.assert_has_calls(expected_run_calls)
        self.tar_mock.assert_has_calls(expected_tar_calls)
Ejemplo n.º 30
0
    def test_build(self):
        plugin = nodejs.NodePlugin("test-part", self.options, self.project)

        self.create_assets(plugin)

        plugin.build()

        self.assertThat(os.path.join(plugin.installdir, "bin", "run"),
                        FileExists())

        expected_env = dict(PATH=os.path.join(plugin._npm_dir, "bin"))
        if self.http_proxy is not None:
            expected_env["http_proxy"] = self.http_proxy
        if self.https_proxy is not None:
            expected_env["https_proxy"] = self.https_proxy
        if self.package_manager == "npm":
            expected_run_calls = [
                mock.call(
                    [
                        self.get_npm_cmd(plugin), "install", "--offline",
                        "--prod"
                    ],
                    cwd=plugin.builddir,
                    env=expected_env,
                ),
                mock.call(
                    [self.get_npm_cmd(plugin), "pack"],
                    cwd=plugin.builddir,
                    env=expected_env,
                ),
                mock.call(
                    [
                        self.get_npm_cmd(plugin), "install", "--offline",
                        "--prod"
                    ],
                    cwd=os.path.join(plugin.builddir, "package"),
                    env=expected_env,
                ),
            ]
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False,
                                      keep_tarball=True),
                mock.call("test-nodejs-1.0.tgz", plugin.builddir),
                mock.call().provision(os.path.join(plugin.builddir,
                                                   "package")),
            ]
        else:
            cmd = [self.get_yarn_cmd(plugin)]
            if self.http_proxy is not None:
                cmd.extend(["--proxy", self.http_proxy])
            if self.https_proxy is not None:
                cmd.extend(["--https-proxy", self.https_proxy])
            expected_run_calls = [
                mock.call(
                    cmd + ["install", "--offline", "--prod"],
                    cwd=plugin.builddir,
                    env=expected_env,
                ),
                mock.call(
                    cmd + ["pack", "--filename", "test-nodejs-1.0.tgz"],
                    cwd=plugin.builddir,
                    env=expected_env,
                ),
                mock.call(
                    cmd + ["install", "--offline", "--prod"],
                    cwd=os.path.join(plugin.builddir, "package"),
                    env=expected_env,
                ),
            ]
            expected_tar_calls = [
                mock.call(self.nodejs_url, plugin._npm_dir),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False,
                                      keep_tarball=True),
                mock.call("https://yarnpkg.com/latest.tar.gz",
                          plugin._npm_dir),
                mock.call().provision(plugin._npm_dir,
                                      clean_target=False,
                                      keep_tarball=True),
                mock.call("test-nodejs-1.0.tgz", plugin.builddir),
                mock.call().provision(os.path.join(plugin.builddir,
                                                   "package")),
            ]

        self.run_mock.assert_has_calls(expected_run_calls)
        self.tar_mock.assert_has_calls(expected_tar_calls)

        expected_tar_calls = [
            mock.call("test-nodejs-1.0.tgz", plugin.builddir),
            mock.call().provision(os.path.join(plugin.builddir, "package")),
        ]
        self.tar_mock.assert_has_calls(expected_tar_calls)