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))
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)
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)
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)
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) ])
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)
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)
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)
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)
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) ])
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)
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)
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)
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)
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)')
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))
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']})))
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))
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))
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})), )
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))
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() ])
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) ])
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))
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) ])
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) ])
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() ])
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)
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)
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)