github.com/jfrog/jfrog-cli-core/v2@v2.51.0/artifactory/utils/npm/pack_test.go (about) 1 package npm 2 3 import ( 4 biutils "github.com/jfrog/build-info-go/build/utils" 5 "github.com/jfrog/build-info-go/utils" 6 "github.com/jfrog/jfrog-cli-core/v2/utils/tests" 7 "github.com/jfrog/jfrog-client-go/utils/log" 8 testsUtils "github.com/jfrog/jfrog-client-go/utils/tests" 9 "github.com/stretchr/testify/assert" 10 "os" 11 "path/filepath" 12 "testing" 13 ) 14 15 const minimumWorkspacesNpmVersion = "7.24.2" 16 17 func TestNpmPackWorkspaces(t *testing.T) { 18 19 npmVersion, executablePath, err := biutils.GetNpmVersionAndExecPath(nil) 20 assert.NoError(t, err) 21 // In npm under v7 skip test 22 if npmVersion.Compare(minimumWorkspacesNpmVersion) > 0 { 23 log.Info("Test skipped as this function in not supported in npm version " + npmVersion.GetVersion()) 24 return 25 } 26 27 tmpDir, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t) 28 defer createTempDirCallback() 29 30 npmProjectPath := filepath.Join("..", "..", "..", "tests", "testdata", "npm-workspaces") 31 err = utils.CopyDir(npmProjectPath, tmpDir, true, nil) 32 assert.NoError(t, err) 33 34 cwd, err := os.Getwd() 35 assert.NoError(t, err) 36 chdirCallback := testsUtils.ChangeDirWithCallback(t, cwd, tmpDir) 37 defer chdirCallback() 38 39 packedFileNames, err := Pack([]string{"--workspaces", "--verbose"}, executablePath) 40 assert.NoError(t, err) 41 42 expected := []string{"module1-1.0.0.tgz", "module2-1.0.0.tgz"} 43 assert.Equal(t, expected, packedFileNames) 44 } 45 46 func TestNpmPack(t *testing.T) { 47 48 _, executablePath, err := biutils.GetNpmVersionAndExecPath(nil) 49 assert.NoError(t, err) 50 tmpDir, createTempDirCallback := tests.CreateTempDirWithCallbackAndAssert(t) 51 defer createTempDirCallback() 52 npmProjectPath := filepath.Join("..", "..", "..", "tests", "testdata", "npm-workspaces") 53 err = utils.CopyDir(npmProjectPath, tmpDir, false, nil) 54 assert.NoError(t, err) 55 56 cwd, err := os.Getwd() 57 assert.NoError(t, err) 58 chdirCallback := testsUtils.ChangeDirWithCallback(t, cwd, tmpDir) 59 defer chdirCallback() 60 61 packedFileNames, err := Pack([]string{"--verbose"}, executablePath) 62 assert.NoError(t, err) 63 64 expected := []string{"npm-pack-test-1.0.0.tgz"} 65 assert.Equal(t, expected, packedFileNames) 66 }