Beispiel #1
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)
Beispiel #2
0
    def test_build_scoped_name_with_yarn(self):
        self.options.nodejs_package_manager = "yarn"
        plugin = nodejs.NodePlugin("test-part", self.options, self.project)

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

        plugin.build()

        cmd = [self.get_yarn_cmd(plugin)]
        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)
Beispiel #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)
Beispiel #4
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)
Beispiel #5
0
def nodejs_plugin(project, request):
    """Return an instance of NodejsPlugin setup varying bases and pkg managers."""

    class Options:
        source = "."
        nodejs_version = nodejs._NODEJS_VERSION
        nodejs_package_manager = request.param
        nodejs_yarn_version = ""
        source = "."

    return nodejs.NodePlugin("test-part", Options(), project)
Beispiel #6
0
    def test_build_with_npm(self):
        self.options.nodejs_package_manager = "npm"
        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"))

        expected_run_calls = [
            mock.call(
                [self.get_npm_cmd(plugin), "install", "--unsafe-perm"],
                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",
                    "--unsafe-perm",
                    "--offline",
                    "--prod",
                ],
                cwd=os.path.join(plugin.builddir, "package"),
                env=expected_env,
            ),
        ]
        expected_tar_calls = [
            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)
Beispiel #7
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))
Beispiel #8
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})
            ),
        )
Beispiel #9
0
    def test_pull_with_npm(self):
        self.options.nodejs_package_manager = "npm"
        plugin = nodejs.NodePlugin("test-part", self.options, self.project)

        self.create_assets(plugin)

        plugin.pull()

        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
            ),
        ]

        self.tar_mock.assert_has_calls(expected_tar_calls)
Beispiel #10
0
    def test_build_yarn_with_proxy(self):
        self.useFixture(
            fixtures.EnvironmentVariable("http_proxy", "http://localhost:3132")
        )
        self.useFixture(
            fixtures.EnvironmentVariable("https_proxy", "http://localhost:3133")
        )
        self.options.nodejs_package_manager = "yarn"
        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())

        cmd = [
            self.get_yarn_cmd(plugin),
            "--proxy",
            "http://localhost:3132",
            "--https-proxy",
            "http://localhost:3133",
        ]

        expected_run_calls = [
            mock.call(cmd + ["install"], cwd=plugin.builddir, env=mock.ANY),
            mock.call(
                cmd + ["pack", "--filename", "test-nodejs-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)
Beispiel #11
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", "--unsafe-perm"],
                    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",
                        "--unsafe-perm",
                        "--offline",
                        "--prod",
                    ],
                    cwd=os.path.join(plugin.builddir, "package"),
                    env=expected_env,
                ),
            ]
            expected_tar_calls = [
                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"], 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("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)