@@ -30,8 +30,10 @@ import (
30
30
)
31
31
32
32
type npmTestParams struct {
33
- testName string
34
- command string
33
+ testName string
34
+ nativeCommand string
35
+ // Deprecated
36
+ legacyCommand string
35
37
repo string
36
38
npmArgs string
37
39
wd string
@@ -47,7 +49,16 @@ func cleanNpmTest() {
47
49
tests .CleanFileSystem ()
48
50
}
49
51
50
- func TestNpm (t * testing.T ) {
52
+ func TestNpmNativeSyntax (t * testing.T ) {
53
+ testNpm (t , false )
54
+ }
55
+
56
+ // Deprecated
57
+ func TestNpmLegacy (t * testing.T ) {
58
+ testNpm (t , true )
59
+ }
60
+
61
+ func testNpm (t * testing.T , isLegacy bool ) {
51
62
initNpmTest (t )
52
63
defer cleanNpmTest ()
53
64
wd , err := os .Getwd ()
@@ -67,28 +78,32 @@ func TestNpm(t *testing.T) {
67
78
68
79
npmProjectPath , npmScopedProjectPath , npmNpmrcProjectPath , npmProjectCi := initNpmFilesTest (t )
69
80
var npmTests = []npmTestParams {
70
- {testName : "npm ci" , command : "npm ci" , repo : tests .NpmRemoteRepo , wd : npmProjectCi , validationFunc : validateNpmInstall },
71
- {testName : "npm ci with module" , command : "npm ci" , repo : tests .NpmRemoteRepo , wd : npmProjectCi , moduleName : ModuleNameJFrogTest , validationFunc : validateNpmInstall },
72
- {testName : "npm i with module" , command : "npm install" , repo : tests .NpmRemoteRepo , wd : npmProjectPath , moduleName : ModuleNameJFrogTest , validationFunc : validateNpmInstall },
73
- {testName : "npm i with scoped project" , command : "npm install" , repo : tests .NpmRemoteRepo , wd : npmScopedProjectPath , validationFunc : validateNpmInstall },
74
- {testName : "npm i with npmrc project" , command : "npm install" , repo : tests .NpmRemoteRepo , wd : npmNpmrcProjectPath , validationFunc : validateNpmInstall },
75
- {testName : "npm i with production" , command : "npm install" , repo : tests .NpmRemoteRepo , wd : npmProjectPath , validationFunc : validateNpmInstall , npmArgs : "--production" },
76
- {testName : "npm i with npmrc project" , command : "npm i" , repo : tests .NpmRemoteRepo , wd : npmNpmrcProjectPath , validationFunc : validateNpmPackInstall , npmArgs : "yaml" },
77
- {testName : "npmp with module" , command : "npm p" , repo : tests .NpmRepo , wd : npmScopedProjectPath , moduleName : ModuleNameJFrogTest , validationFunc : validateNpmScopedPublish },
78
- {testName : "npmp " , command : "npm publish" , repo : tests .NpmRepo , wd : npmProjectPath , validationFunc : validateNpmPublish },
79
- {testName : "npm conditional publish" , command : "npm publish --scan" , repo : tests .NpmRepo , wd : npmProjectPath , validationFunc : validateNpmPublish },
81
+ {testName : "npm ci" , nativeCommand : "npm ci" , legacyCommand : "rt npmci " , repo : tests .NpmRemoteRepo , wd : npmProjectCi , validationFunc : validateNpmInstall },
82
+ {testName : "npm ci with module" , nativeCommand : "npm ci" , legacyCommand : "rt npmci " , repo : tests .NpmRemoteRepo , wd : npmProjectCi , moduleName : ModuleNameJFrogTest , validationFunc : validateNpmInstall },
83
+ {testName : "npm i with module" , nativeCommand : "npm install" , legacyCommand : "rt npm- install" , repo : tests .NpmRemoteRepo , wd : npmProjectPath , moduleName : ModuleNameJFrogTest , validationFunc : validateNpmInstall },
84
+ {testName : "npm i with scoped project" , nativeCommand : "npm install" , legacyCommand : "rt npm- install" , repo : tests .NpmRemoteRepo , wd : npmScopedProjectPath , validationFunc : validateNpmInstall },
85
+ {testName : "npm i with npmrc project" , nativeCommand : "npm install" , legacyCommand : "rt npm- install" , repo : tests .NpmRemoteRepo , wd : npmNpmrcProjectPath , validationFunc : validateNpmInstall },
86
+ {testName : "npm i with production" , nativeCommand : "npm install" , legacyCommand : "rt npm- install" , repo : tests .NpmRemoteRepo , wd : npmProjectPath , validationFunc : validateNpmInstall , npmArgs : "--production" },
87
+ {testName : "npm i with npmrc project" , nativeCommand : "npm i" , legacyCommand : "rt npmi " , repo : tests .NpmRemoteRepo , wd : npmNpmrcProjectPath , validationFunc : validateNpmPackInstall , npmArgs : "yaml" },
88
+ {testName : "npm p with module" , nativeCommand : "npm p" , legacyCommand : "rt npmp " , repo : tests .NpmRepo , wd : npmScopedProjectPath , moduleName : ModuleNameJFrogTest , validationFunc : validateNpmScopedPublish },
89
+ {testName : "npm p " , nativeCommand : "npm publish" , legacyCommand : "rt npm- publish" , repo : tests .NpmRepo , wd : npmProjectPath , validationFunc : validateNpmPublish },
90
+ {testName : "npm conditional publish" , nativeCommand : "npm publish --scan" , legacyCommand : "rt npm- publish --scan" , repo : tests .NpmRepo , wd : npmProjectPath , validationFunc : validateNpmPublish },
80
91
}
81
92
82
93
for i , npmTest := range npmTests {
83
94
t .Run (npmTest .testName , func (t * testing.T ) {
95
+ npmCmd := npmTest .nativeCommand
96
+ if isLegacy {
97
+ npmCmd = npmTest .legacyCommand
98
+ }
84
99
err = os .Chdir (filepath .Dir (npmTest .wd ))
85
100
assert .NoError (t , err )
86
101
npmrcFileInfo , err := os .Stat (".npmrc" )
87
102
if err != nil && ! os .IsNotExist (err ) {
88
103
assert .Fail (t , err .Error ())
89
104
}
90
105
var buildNumber string
91
- commandArgs := strings .Split (npmTest . command , " " )
106
+ commandArgs := strings .Split (npmCmd , " " )
92
107
buildNumber = strconv .Itoa (i + 100 )
93
108
commandArgs = append (commandArgs , npmTest .npmArgs )
94
109
@@ -231,12 +246,11 @@ func validateNpmInstall(t *testing.T, npmTestParams npmTestParams, isNpm7 bool)
231
246
return
232
247
}
233
248
buildInfo := publishedBuildInfo .BuildInfo
234
- if buildInfo .Modules == nil || len (buildInfo .Modules ) == 0 {
235
- // Case no module was created
236
- t .Error (fmt .Sprintf ("npm install test with command '%s' and repo '%s' failed" , npmTestParams .command , npmTestParams .repo ))
249
+ if buildInfo .Modules == nil {
250
+ assert .NotNil (t , buildInfo .Modules )
237
251
return
238
252
}
239
-
253
+ assert . NotEmpty ( t , buildInfo . Modules )
240
254
equalDependenciesSlices (t , expectedDependencies , buildInfo .Modules [0 ].Dependencies )
241
255
}
242
256
0 commit comments