Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/jfrog/jfrog-cli into simple-…
Browse files Browse the repository at this point in the history
…defer

# Conflicts:
#	go.mod
#	go.sum
  • Loading branch information
sverdlov93 committed Mar 27, 2024
2 parents 3ac4543 + 26ead66 commit 5e6aced
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 14 deletions.
73 changes: 59 additions & 14 deletions npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,20 +549,7 @@ func TestNpmPublishWithWorkspaces(t *testing.T) {
err = commands.Exec(npmpCmd)
assert.NoError(t, err)

result := npmpCmd.Result()
assert.NotNil(t, result)
reader := result.Reader()
readerGetErrorAndAssert(t, reader)
defer readerCloseAndAssert(t, reader)
// Read result
var files []clientutils.FileTransferDetails
for transferDetails := new(clientutils.FileTransferDetails); reader.NextRecord(transferDetails) == nil; transferDetails = new(clientutils.FileTransferDetails) {
files = append(files, *transferDetails)
}
if files == nil {
assert.NotNil(t, files)
return
}
files := assertNpmPublishResultFiles(t, npmpCmd)

expectedTars := []string{"nested1", "nested2"}
for index, tar := range expectedTars {
Expand All @@ -577,6 +564,51 @@ func TestNpmPublishWithWorkspaces(t *testing.T) {
}
}

// Test npm publish command with provided tarball
func TestNpmPackProvidedTarball(t *testing.T) {
// Check npm version
npmVersion, _, err := buildutils.GetNpmVersionAndExecPath(log.Logger)
if err != nil {
assert.NoError(t, err)
return
}
// In npm under v7 skip test
if npmVersion.Compare(minimumWorkspacesNpmVersion) > 0 {
log.Info("Test skipped as this function in not supported in npm version " + npmVersion.GetVersion())
return
}

// Prepare test
initNpmTest(t)
defer cleanNpmTest(t)
tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
testFolder := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "npm", "npmprovidedtarball")
err = biutils.CopyDir(testFolder, tempDirPath, false, []string{})
assert.NoError(t, err)

// CD inside the copied project and create npm config
wd, err := os.Getwd()
assert.NoError(t, err)
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, tempDirPath)
defer chdirCallback()
err = createConfigFileForTest([]string{tempDirPath}, tests.NpmRemoteRepo, tests.NpmRepo, t, project.Npm, false)
assert.NoError(t, err)

// Init npm project & npmp command for testing
configFilePath := filepath.Join(tempDirPath, ".jfrog", "projects", "npm.yaml")
args := []string{"jfrog-cli-tests-v1.0.0.tgz", "--detailed-summary=true", "--workspaces", "--verbose"}
npmpCmd := npm.NewNpmPublishCommand()
npmpCmd.SetConfigFilePath(configFilePath).SetArgs(args)
npmpCmd.SetNpmArgs(args)
assert.NoError(t, npmpCmd.Init())
err = commands.Exec(npmpCmd)
assert.NoError(t, err)

// Check result
assertNpmPublishResultFiles(t, npmpCmd)
}

func TestYarn(t *testing.T) {
initNpmTest(t)
defer cleanNpmTest(t)
Expand Down Expand Up @@ -679,3 +711,16 @@ func runGenericNpm(t *testing.T, args ...string) {
jfCli := coretests.NewJfrogCli(execMain, "jf", "")
assert.NoError(t, jfCli.WithoutCredentials().Exec(args...))
}

func assertNpmPublishResultFiles(t *testing.T, npmpCmd *npm.NpmPublishCommand) (files []clientutils.FileTransferDetails) {
result := npmpCmd.Result()
assert.NotNil(t, result)
reader := result.Reader()
readerGetErrorAndAssert(t, reader)
defer readerCloseAndAssert(t, reader)
for transferDetails := new(clientutils.FileTransferDetails); reader.NextRecord(transferDetails) == nil; transferDetails = new(clientutils.FileTransferDetails) {
files = append(files, *transferDetails)
}
assert.NotNil(t, files)
return files
}
Binary file not shown.

0 comments on commit 5e6aced

Please sign in to comment.