-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
526 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,66 @@ | ||
package npm | ||
|
||
import ( | ||
biutils "github.com/jfrog/build-info-go/build/utils" | ||
"github.com/jfrog/build-info-go/utils" | ||
"github.com/jfrog/jfrog-cli-core/v2/utils/tests" | ||
"github.com/jfrog/jfrog-client-go/utils/log" | ||
testsUtils "github.com/jfrog/jfrog-client-go/utils/tests" | ||
"github.com/stretchr/testify/assert" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
const testdataDir = "../testdata/npm/" | ||
const minimumWorkspacesNpmVersion = "7.24.2" | ||
|
||
func TestGetPackageFileNameFromOutput(t *testing.T) { | ||
tests := []struct { | ||
testName string | ||
outputTestDataFile string | ||
expectedPackageFilename string | ||
}{ | ||
{"Get package filename for npm 6", "npmPackOutputV6", "npm-example-0.0.3.tgz"}, | ||
{"Get package filename for npm 7", "npmPackOutputV7", "npm-example-ver0.0.3.tgz"}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.testName, func(t *testing.T) { | ||
output, err := os.ReadFile(filepath.Join(testdataDir, test.outputTestDataFile)) | ||
if err != nil { | ||
assert.NoError(t, err) | ||
return | ||
} | ||
actualFilename, err := getPackageFileNameFromOutput(string(output)) | ||
if err != nil { | ||
assert.NoError(t, err) | ||
return | ||
} | ||
assert.Equal(t, test.expectedPackageFilename, actualFilename) | ||
}) | ||
func TestNpmPackWorkspaces(t *testing.T) { | ||
|
||
npmVersion, executablePath, err := biutils.GetNpmVersionAndExecPath(nil) | ||
assert.NoError(t, err) | ||
// 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 | ||
} | ||
|
||
tmpDir, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t) | ||
defer createTempDirCallback() | ||
|
||
npmProjectPath := filepath.Join("..", "..", "..", "tests", "testdata", "npm-workspaces") | ||
err = utils.CopyDir(npmProjectPath, tmpDir, true, nil) | ||
assert.NoError(t, err) | ||
|
||
cwd, err := os.Getwd() | ||
assert.NoError(t, err) | ||
chdirCallback := testsUtils.ChangeDirWithCallback(t, cwd, tmpDir) | ||
defer chdirCallback() | ||
|
||
packedFileNames, err := Pack([]string{"--workspaces", "--verbose"}, executablePath) | ||
assert.NoError(t, err) | ||
|
||
expected := []string{"module1-1.0.0.tgz", "module2-1.0.0.tgz"} | ||
assert.Equal(t, expected, packedFileNames) | ||
} | ||
|
||
func TestNpmPack(t *testing.T) { | ||
|
||
_, executablePath, err := biutils.GetNpmVersionAndExecPath(nil) | ||
assert.NoError(t, err) | ||
tmpDir, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t) | ||
defer createTempDirCallback() | ||
npmProjectPath := filepath.Join("..", "..", "..", "tests", "testdata", "npm-workspaces") | ||
err = utils.CopyDir(npmProjectPath, tmpDir, false, nil) | ||
assert.NoError(t, err) | ||
|
||
cwd, err := os.Getwd() | ||
assert.NoError(t, err) | ||
chdirCallback := testsUtils.ChangeDirWithCallback(t, cwd, tmpDir) | ||
defer chdirCallback() | ||
|
||
packedFileNames, err := Pack([]string{"--verbose"}, executablePath) | ||
assert.NoError(t, err) | ||
|
||
expected := []string{"npm-pack-test-1.0.0.tgz"} | ||
assert.Equal(t, expected, packedFileNames) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.