-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(node): Reduce indentation in
Yarn2Test
Use constructor init syntax for the `WordSpec` to be able to reduce indentation for a better overview. Signed-off-by: Sebastian Schuberth <[email protected]>
- Loading branch information
1 parent
ee6016c
commit 7b93abf
Showing
1 changed file
with
59 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,91 +31,89 @@ import org.ossreviewtoolkit.model.config.AnalyzerConfiguration | |
import org.ossreviewtoolkit.model.config.PackageManagerConfiguration | ||
import org.ossreviewtoolkit.model.config.RepositoryConfiguration | ||
|
||
class Yarn2Test : WordSpec() { | ||
init { | ||
"command" should { | ||
"return the executable defined in .yarnrc.yml if no package.json is present" { | ||
checkExecutableFromYarnRc(tempdir()) | ||
} | ||
|
||
"return the executable defined in .yarnrc.yml if no package manager is defined" { | ||
val workingDir = tempdir() | ||
writePackageJson(workingDir, null) | ||
class Yarn2Test : WordSpec({ | ||
"command" should { | ||
"return the executable defined in .yarnrc.yml if no package.json is present" { | ||
checkExecutableFromYarnRc(tempdir()) | ||
} | ||
|
||
checkExecutableFromYarnRc(workingDir) | ||
} | ||
"return the executable defined in .yarnrc.yml if no package manager is defined" { | ||
val workingDir = tempdir() | ||
writePackageJson(workingDir, null) | ||
|
||
"return the executable defined in .yarnrc.yml if package.json is invalid" { | ||
val workingDir = tempdir() | ||
workingDir.resolve("package.json").writeText("invalid-json") | ||
checkExecutableFromYarnRc(workingDir) | ||
} | ||
|
||
checkExecutableFromYarnRc(workingDir) | ||
} | ||
"return the executable defined in .yarnrc.yml if package.json is invalid" { | ||
val workingDir = tempdir() | ||
workingDir.resolve("package.json").writeText("invalid-json") | ||
|
||
"throw if no executable is defined in .yarnrc.yml" { | ||
val workingDir = tempdir() | ||
workingDir.resolve(".yarnrc.yml").writeText("someProperty: some-value") | ||
checkExecutableFromYarnRc(workingDir) | ||
} | ||
|
||
val yarn = Yarn2("yarn", workingDir, AnalyzerConfiguration(), RepositoryConfiguration()) | ||
"throw if no executable is defined in .yarnrc.yml" { | ||
val workingDir = tempdir() | ||
workingDir.resolve(".yarnrc.yml").writeText("someProperty: some-value") | ||
|
||
val exception = shouldThrow<IllegalArgumentException> { | ||
yarn.command(workingDir) | ||
} | ||
val yarn = Yarn2("yarn", workingDir, AnalyzerConfiguration(), RepositoryConfiguration()) | ||
|
||
exception.localizedMessage shouldContain "No Yarn 2+ executable" | ||
val exception = shouldThrow<IllegalArgumentException> { | ||
yarn.command(workingDir) | ||
} | ||
|
||
"throw if the executable defined in .yarnrc.yml does not exist" { | ||
val workingDir = tempdir() | ||
val executable = "non-existing-yarn-wrapper.js" | ||
workingDir.resolve(".yarnrc.yml").writeText("yarnPath: $executable") | ||
exception.localizedMessage shouldContain "No Yarn 2+ executable" | ||
} | ||
|
||
val yarn = Yarn2("yarn", workingDir, AnalyzerConfiguration(), RepositoryConfiguration()) | ||
"throw if the executable defined in .yarnrc.yml does not exist" { | ||
val workingDir = tempdir() | ||
val executable = "non-existing-yarn-wrapper.js" | ||
workingDir.resolve(".yarnrc.yml").writeText("yarnPath: $executable") | ||
|
||
val exception = shouldThrow<IllegalArgumentException> { | ||
yarn.command(workingDir) | ||
} | ||
val yarn = Yarn2("yarn", workingDir, AnalyzerConfiguration(), RepositoryConfiguration()) | ||
|
||
exception.localizedMessage shouldContain executable | ||
val exception = shouldThrow<IllegalArgumentException> { | ||
yarn.command(workingDir) | ||
} | ||
|
||
"return the default executable name if Corepack is enabled based on the configuration option" { | ||
val workingDir = tempdir() | ||
val yarn2Options = mapOf("corepackOverride" to "true") | ||
val analyzerConfiguration = AnalyzerConfiguration( | ||
packageManagers = mapOf("Yarn2" to PackageManagerConfiguration(options = yarn2Options)) | ||
) | ||
exception.localizedMessage shouldContain executable | ||
} | ||
|
||
val yarn = Yarn2("Yarn2", workingDir, analyzerConfiguration, RepositoryConfiguration()) | ||
val command = yarn.command(workingDir) | ||
"return the default executable name if Corepack is enabled based on the configuration option" { | ||
val workingDir = tempdir() | ||
val yarn2Options = mapOf("corepackOverride" to "true") | ||
val analyzerConfiguration = AnalyzerConfiguration( | ||
packageManagers = mapOf("Yarn2" to PackageManagerConfiguration(options = yarn2Options)) | ||
) | ||
|
||
command shouldBe "yarn" | ||
} | ||
val yarn = Yarn2("Yarn2", workingDir, analyzerConfiguration, RepositoryConfiguration()) | ||
val command = yarn.command(workingDir) | ||
|
||
"return the default executable name if Corepack is enabled based on the package.json" { | ||
val workingDir = tempdir() | ||
writePackageJson(workingDir, "[email protected]") | ||
command shouldBe "yarn" | ||
} | ||
|
||
val yarn = Yarn2("Yarn2", workingDir, AnalyzerConfiguration(), RepositoryConfiguration()) | ||
val command = yarn.command(workingDir) | ||
"return the default executable name if Corepack is enabled based on the package.json" { | ||
val workingDir = tempdir() | ||
writePackageJson(workingDir, "[email protected]") | ||
|
||
command shouldBe "yarn" | ||
} | ||
val yarn = Yarn2("Yarn2", workingDir, AnalyzerConfiguration(), RepositoryConfiguration()) | ||
val command = yarn.command(workingDir) | ||
|
||
"return the executable defined in .yarnrc.yml if Corepack detection is turned off" { | ||
val workingDir = tempdir() | ||
writePackageJson(workingDir, "[email protected]") | ||
command shouldBe "yarn" | ||
} | ||
|
||
val yarn2Options = mapOf("corepackOverride" to "false") | ||
val analyzerConfiguration = AnalyzerConfiguration( | ||
packageManagers = mapOf("Yarn2" to PackageManagerConfiguration(options = yarn2Options)) | ||
) | ||
"return the executable defined in .yarnrc.yml if Corepack detection is turned off" { | ||
val workingDir = tempdir() | ||
writePackageJson(workingDir, "[email protected]") | ||
|
||
checkExecutableFromYarnRc(workingDir, analyzerConfiguration) | ||
} | ||
val yarn2Options = mapOf("corepackOverride" to "false") | ||
val analyzerConfiguration = AnalyzerConfiguration( | ||
packageManagers = mapOf("Yarn2" to PackageManagerConfiguration(options = yarn2Options)) | ||
) | ||
|
||
checkExecutableFromYarnRc(workingDir, analyzerConfiguration) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
/** | ||
* Check whether an executable defined in a `.yarnrc.yml` file is used when invoked with the given [workingDir] | ||
|