Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add npm publish -workspaces test #2471

Merged
merged 11 commits into from
Mar 12, 2024
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240305100201-685c9c30adde
replace github.com/jfrog/jfrog-cli-core/v2 => github.com/eyaldelarea/jfrog-cli-core/v2 v2.0.0-20240311152428-e408f32663a1

replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.28.1-0.20240228121257-3414cc0ffcb6

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdf
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/eyaldelarea/jfrog-cli-core/v2 v2.0.0-20240311152428-e408f32663a1 h1:FiG2/mLsBJ75SzMvT/wCv5mOtV56ennd8ZcIqezyIpQ=
github.com/eyaldelarea/jfrog-cli-core/v2 v2.0.0-20240311152428-e408f32663a1/go.mod h1:fTnA9KjwuMEWnqAFPPoLc6IzvYxD8SorqawESk74fP8=
github.com/forPelevin/gomoji v1.1.8 h1:JElzDdt0TyiUlecy6PfITDL6eGvIaxqYH1V52zrd0qQ=
github.com/forPelevin/gomoji v1.1.8/go.mod h1:8+Z3KNGkdslmeGZBC3tCrwMrcPy5GRzAD+gL9NAwMXg=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
Expand Down Expand Up @@ -127,8 +129,6 @@ github.com/jfrog/gofrog v1.6.3 h1:F7He0+75HcgCe6SGTSHLFCBDxiE2Ja0tekvvcktW6wc=
github.com/jfrog/gofrog v1.6.3/go.mod h1:SZ1EPJUruxrVGndOzHd+LTiwWYKMlHqhKD+eu+v5Hqg=
github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYLipdsOFMY=
github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240305100201-685c9c30adde h1:e1TWEAPAJZ+HFBxQ2UoJ0aKfj9xJ2XgkFjygsCkMHbg=
github.com/jfrog/jfrog-cli-core/v2 v2.31.1-0.20240305100201-685c9c30adde/go.mod h1:lgwEgVIfazK/BjJarpaS5Mdpw86DWeDCSNDCwJqH8kg=
github.com/jfrog/jfrog-cli-security v1.0.4-0.20240303113253-d82ecc02d9eb h1:JUqwNOqzwj+1oZQXY1p/xnnH97BEMfOKGG505vGVIe4=
github.com/jfrog/jfrog-cli-security v1.0.4-0.20240303113253-d82ecc02d9eb/go.mod h1:pOqg/hGw6eHWNyLDHeOCyq/Ntuc+wLJTV2Z8XuwXspU=
github.com/jfrog/jfrog-client-go v1.28.1-0.20240228121257-3414cc0ffcb6 h1:W+79g2W3ARRhIZtBfG0t73fi4IlyiIRWwdm1tajOkkc=
Expand Down
58 changes: 58 additions & 0 deletions npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ func initNpmProjectTest(t *testing.T) (npmProjectPath string) {
return
}

func initNpmWorkspacesProjectTest(t *testing.T) (npmProjectPath string) {
npmProjectPath = filepath.Dir(createNpmProject(t, "npmworkspaces"))
err := createConfigFileForTest([]string{npmProjectPath}, tests.NpmRemoteRepo, tests.NpmRepo, t, project.Npm, false)
assert.NoError(t, err)
testFolder := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "npm", "npmworkspaces")
err = biutils.CopyDir(testFolder, npmProjectPath, true, []string{})
assert.NoError(t, err)
prepareArtifactoryForNpmBuild(t, npmProjectPath)
return
}

func initGlobalNpmFilesTest(t *testing.T) (npmProjectPath string) {
npmProjectPath = createNpmProject(t, "npmproject")
jfrogHomeDir, err := coreutils.GetJfrogHomeDir()
Expand Down Expand Up @@ -499,6 +510,53 @@ func TestNpmPackInstall(t *testing.T) {
assert.Len(t, npmBuildInfo.Modules, 0)
}

func TestNpmPackWorkspaces(t *testing.T) {
EyalDelarea marked this conversation as resolved.
Show resolved Hide resolved
initNpmTest(t)
defer cleanNpmTest(t)
wd, err := os.Getwd()
assert.NoError(t, err, "Failed to get current dir")
defer clientTestUtils.ChangeDirAndAssert(t, wd)

// Init npm project & npmp command for testing
npmProjectPath := initNpmWorkspacesProjectTest(t)
configFilePath := filepath.Join(npmProjectPath, ".jfrog", "projects", "npm.yaml")
args := []string{"--detailed-summary=true", "--workspaces"}
npmpCmd := npm.NewNpmPublishCommand()
npmpCmd.SetConfigFilePath(configFilePath).SetArgs(args)
npmpCmd.SetNpmArgs(args)
assert.NoError(t, npmpCmd.Init())
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
}

expectedTars := []string{"nested1", "nested2"}
for index, tar := range expectedTars {
// Verify deploy details
tarballName := tar + "-1.0.0.tgz"
expectedSourcePath := filepath.Join(npmProjectPath, tarballName)
expectedTargetPath := serverDetails.ArtifactoryUrl + tests.NpmRepo + "/" + tar + "/-/" + tarballName
assert.Equal(t, expectedSourcePath, files[index].SourcePath, "Summary validation failed - unmatched SourcePath.")
assert.Equal(t, expectedTargetPath, files[index].RtUrl+files[index].TargetPath, "Summary validation failed - unmatched TargetPath.")
assert.Equal(t, len(expectedTars), len(files), "Summary validation failed - two archive should be deployed.")
// Verify sha256 is valid (a string size 256 characters) and not an empty string.
assert.Equal(t, 64, len(files[index].Sha256), "Summary validation failed - sha256 should be in size 64 digits.")
EyalDelarea marked this conversation as resolved.
Show resolved Hide resolved
}
}

func TestYarn(t *testing.T) {
initNpmTest(t)
defer cleanNpmTest(t)
Expand Down
15 changes: 15 additions & 0 deletions testdata/npm/npmworkspaces/nested1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "nested1",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"loadash": "^1.0.0"
EyalDelarea marked this conversation as resolved.
Show resolved Hide resolved
}
}
15 changes: 15 additions & 0 deletions testdata/npm/npmworkspaces/nested2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "nested2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"loadash": "^1.0.0"
EyalDelarea marked this conversation as resolved.
Show resolved Hide resolved
}
}
21 changes: 21 additions & 0 deletions testdata/npm/npmworkspaces/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "jfrog-cli-tests",
"version": "v1.0.0",
"description": "test package",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"xml": "1.0.1"
},
"devDependencies": {
"json": "9.0.6"
},
"workspaces": [
"nested1",
"nested2"
]
}
Loading