diff --git a/npm_test.go b/npm_test.go index e4fba64fd..4d87f3d10 100644 --- a/npm_test.go +++ b/npm_test.go @@ -714,6 +714,45 @@ func TestYarn(t *testing.T) { inttestutils.DeleteBuild(serverDetails.ArtifactoryUrl, tests.YarnBuildName, artHttpDetails) } +func TestYarnUpgradeToV4(t *testing.T) { + initNpmTest(t) + defer cleanNpmTest(t) + + // Temporarily change the cache folder to a temporary folder - to make sure the cache is clean and dependencies will be downloaded from Artifactory + tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t) + defer createTempDirCallback() + + testDataSource := filepath.Join(filepath.FromSlash(tests.GetTestResourcesPath()), "yarn") + testDataTarget := filepath.Join(tempDirPath, tests.Out, "yarn") + assert.NoError(t, biutils.CopyDir(testDataSource, testDataTarget, true, nil)) + + yarnProjectPath := filepath.Join(testDataTarget, "yarnproject") + assert.NoError(t, createConfigFileForTest([]string{yarnProjectPath}, tests.NpmRemoteRepo, "", t, project.Yarn, false)) + + wd, err := os.Getwd() + assert.NoError(t, err, "Failed to get current dir") + chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, yarnProjectPath) + defer chdirCallback() + cleanUpYarnGlobalFolder := clientTestUtils.SetEnvWithCallbackAndAssert(t, "YARN_GLOBAL_FOLDER", tempDirPath) + defer cleanUpYarnGlobalFolder() + + // Add "localhost" to http whitelist + yarnExecPath, err := exec.LookPath("yarn") + assert.NoError(t, err) + // Get original http white list config + origWhitelist, err := yarn.ConfigGet("unsafeHttpWhitelist", yarnExecPath, true) + assert.NoError(t, err) + assert.NoError(t, yarn.ConfigSet("unsafeHttpWhitelist", "[\"localhost\"]", yarnExecPath, true)) + defer func() { + // Restore original whitelist config + assert.NoError(t, yarn.ConfigSet("unsafeHttpWhitelist", origWhitelist, yarnExecPath, true)) + }() + + jfrogCli := coretests.NewJfrogCli(execMain, "jfrog", "") + err = jfrogCli.Exec("yarn", "set", "version", "4.0.1") + assert.Error(t, err) +} + // Checks if the expected dependencies match the actual dependencies. Only the dependencies' IDs and scopes (not more than one scope) are compared. func equalDependenciesSlices(t *testing.T, expectedDependencies []expectedDependency, actualDependencies []buildinfo.Dependency) { assert.Equal(t, len(expectedDependencies), len(actualDependencies))