From 7b93abf5f53432e8cb231afa024c9ef4030e296c Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Thu, 12 Dec 2024 15:44:52 +0100 Subject: [PATCH] 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 --- .../node/src/test/kotlin/yarn2/Yarn2Test.kt | 120 +++++++++--------- 1 file changed, 59 insertions(+), 61 deletions(-) diff --git a/plugins/package-managers/node/src/test/kotlin/yarn2/Yarn2Test.kt b/plugins/package-managers/node/src/test/kotlin/yarn2/Yarn2Test.kt index 7922c9d2ed393..06a5f427dc1c3 100644 --- a/plugins/package-managers/node/src/test/kotlin/yarn2/Yarn2Test.kt +++ b/plugins/package-managers/node/src/test/kotlin/yarn2/Yarn2Test.kt @@ -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 { - yarn.command(workingDir) - } + val yarn = Yarn2("yarn", workingDir, AnalyzerConfiguration(), RepositoryConfiguration()) - exception.localizedMessage shouldContain "No Yarn 2+ executable" + val exception = shouldThrow { + 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 { - yarn.command(workingDir) - } + val yarn = Yarn2("yarn", workingDir, AnalyzerConfiguration(), RepositoryConfiguration()) - exception.localizedMessage shouldContain executable + val exception = shouldThrow { + 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, "yarn@4.0.0") + 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, "yarn@4.0.0") - 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, "yarn@4.0.0") + 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, "yarn@4.0.0") - 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]