-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style(node): Remove one level of nesting from tests
Use `StringSpec`s instead of `WordSpec`s as the latter were used to nest all tests as a whole only. Signed-off-by: Sebastian Schuberth <[email protected]>
- Loading branch information
1 parent
59562ef
commit 3eb2b4a
Showing
4 changed files
with
154 additions
and
162 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 |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
|
||
package org.ossreviewtoolkit.plugins.packagemanagers.node.npm | ||
|
||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.core.spec.style.StringSpec | ||
import io.kotest.engine.spec.tempdir | ||
import io.kotest.inspectors.forAll | ||
import io.kotest.inspectors.forAtLeastOne | ||
|
@@ -43,116 +43,114 @@ import org.ossreviewtoolkit.utils.test.matchExpectedResult | |
import org.ossreviewtoolkit.utils.test.patchActualResult | ||
import org.ossreviewtoolkit.utils.test.patchExpectedResult | ||
|
||
class NpmFunTest : WordSpec({ | ||
"NPM" should { | ||
"resolve dependencies for a project with a 'shrinkwrap.json' correctly" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/shrinkwrap/package.json") | ||
val expectedResultFile = getAssetFile("projects/synthetic/npm/shrinkwrap-expected-output.yml") | ||
|
||
val result = create("NPM").resolveSingleProject(definitionFile, resolveScopes = true) | ||
|
||
patchActualResult(result.toYaml()) should matchExpectedResult( | ||
expectedResultFile, | ||
definitionFile, | ||
custom = mapOf( | ||
"<REPLACE_PROJECT_NAME>" to "npm-${definitionFile.parentFile.name}", | ||
"<REPLACE_LOCKFILE_NAME>" to "npm-shrinkwrap.json" | ||
) | ||
) | ||
} | ||
class NpmFunTest : StringSpec({ | ||
"Resolve dependencies for a project with a 'shrinkwrap.json' correctly" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/shrinkwrap/package.json") | ||
val expectedResultFile = getAssetFile("projects/synthetic/npm/shrinkwrap-expected-output.yml") | ||
|
||
val result = create("NPM").resolveSingleProject(definitionFile, resolveScopes = true) | ||
|
||
"exclude scopes if configured" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/shrinkwrap/package.json") | ||
val expectedResultFile = getAssetFile( | ||
"projects/synthetic/npm/shrinkwrap-skip-excluded-scopes-expected-output.yml" | ||
patchActualResult(result.toYaml()) should matchExpectedResult( | ||
expectedResultFile, | ||
definitionFile, | ||
custom = mapOf( | ||
"<REPLACE_PROJECT_NAME>" to "npm-${definitionFile.parentFile.name}", | ||
"<REPLACE_LOCKFILE_NAME>" to "npm-shrinkwrap.json" | ||
) | ||
) | ||
} | ||
|
||
val result = create("NPM", excludedScopes = setOf("devDependencies")) | ||
.resolveSingleProject(definitionFile, resolveScopes = true) | ||
"Exclude scopes if configured" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/shrinkwrap/package.json") | ||
val expectedResultFile = getAssetFile( | ||
"projects/synthetic/npm/shrinkwrap-skip-excluded-scopes-expected-output.yml" | ||
) | ||
|
||
patchActualResult(result.toYaml()) should matchExpectedResult(expectedResultFile, definitionFile) | ||
} | ||
val result = create("NPM", excludedScopes = setOf("devDependencies")) | ||
.resolveSingleProject(definitionFile, resolveScopes = true) | ||
|
||
"resolve dependencies for a project with lockfile correctly" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/project-with-lockfile/package.json") | ||
val expectedResultFile = getAssetFile("projects/synthetic/npm/project-with-lockfile-expected-output.yml") | ||
patchActualResult(result.toYaml()) should matchExpectedResult(expectedResultFile, definitionFile) | ||
} | ||
|
||
val result = create("NPM").resolveSingleProject(definitionFile, resolveScopes = true) | ||
"Resolve dependencies for a project with lockfile correctly" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/project-with-lockfile/package.json") | ||
val expectedResultFile = getAssetFile("projects/synthetic/npm/project-with-lockfile-expected-output.yml") | ||
|
||
patchActualResult(result.toYaml()) should matchExpectedResult(expectedResultFile, definitionFile) | ||
} | ||
val result = create("NPM").resolveSingleProject(definitionFile, resolveScopes = true) | ||
|
||
"show an error if no lockfile is present" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/no-lockfile/package.json") | ||
val expectedResultFile = getAssetFile("projects/synthetic/npm/no-lockfile-expected-output.yml") | ||
patchActualResult(result.toYaml()) should matchExpectedResult(expectedResultFile, definitionFile) | ||
} | ||
|
||
val result = create("NPM").resolveSingleProject(definitionFile) | ||
"Show an error if no lockfile is present" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/no-lockfile/package.json") | ||
val expectedResultFile = getAssetFile("projects/synthetic/npm/no-lockfile-expected-output.yml") | ||
|
||
patchActualResult(result.toYaml()) should matchExpectedResult(expectedResultFile, definitionFile) | ||
} | ||
val result = create("NPM").resolveSingleProject(definitionFile) | ||
|
||
patchActualResult(result.toYaml()) should matchExpectedResult(expectedResultFile, definitionFile) | ||
} | ||
|
||
"show an error if the 'package.json' file is invalid" { | ||
val workingDir = tempdir() | ||
val definitionFile = workingDir.resolve("package.json").apply { writeText("<>") } | ||
"Show an error if the 'package.json' file is invalid" { | ||
val workingDir = tempdir() | ||
val definitionFile = workingDir.resolve("package.json").apply { writeText("<>") } | ||
|
||
val result = create("NPM", allowDynamicVersions = true).resolveSingleProject(definitionFile) | ||
val result = create("NPM", allowDynamicVersions = true).resolveSingleProject(definitionFile) | ||
|
||
result.issues.forAtLeastOne { | ||
it.source shouldBe "NPM" | ||
it.severity shouldBe Severity.ERROR | ||
it.message shouldContain "Unexpected token" | ||
} | ||
result.issues.forAtLeastOne { | ||
it.source shouldBe "NPM" | ||
it.severity shouldBe Severity.ERROR | ||
it.message shouldContain "Unexpected token" | ||
} | ||
} | ||
|
||
"create issues for list errors" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/list-issues/package.json") | ||
"Create issues for list errors" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/list-issues/package.json") | ||
|
||
val result = create("NPM", "legacyPeerDeps" to "true").resolveSingleProject(definitionFile) | ||
val result = create("NPM", "legacyPeerDeps" to "true").resolveSingleProject(definitionFile) | ||
|
||
result.issues shouldNot beEmpty() | ||
val elsproblems = result.issues.filter { it.message.startsWith("invalid: ") } | ||
result.issues shouldNot beEmpty() | ||
val elsproblems = result.issues.filter { it.message.startsWith("invalid: ") } | ||
|
||
elsproblems shouldHaveSize 2 | ||
elsproblems.forAll { it.severity shouldBe Severity.ERROR } | ||
elsproblems shouldHaveSize 2 | ||
elsproblems.forAll { it.severity shouldBe Severity.ERROR } | ||
|
||
elsproblems shouldHaveSingleElement { it.message.startsWith("invalid: [email protected]") } | ||
elsproblems shouldHaveSingleElement { it.message.startsWith("invalid: [email protected]") } | ||
} | ||
elsproblems shouldHaveSingleElement { it.message.startsWith("invalid: [email protected]") } | ||
elsproblems shouldHaveSingleElement { it.message.startsWith("invalid: [email protected]") } | ||
} | ||
|
||
"resolve dependencies even if the 'node_modules' directory already exists" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/node-modules/package.json") | ||
val expectedResultFile = getAssetFile("projects/synthetic/npm/node-modules-expected-output.yml") | ||
"Resolve dependencies even if the 'node_modules' directory already exists" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/node-modules/package.json") | ||
val expectedResultFile = getAssetFile("projects/synthetic/npm/node-modules-expected-output.yml") | ||
|
||
val result = create("NPM").resolveSingleProject(definitionFile, resolveScopes = true) | ||
val result = create("NPM").resolveSingleProject(definitionFile, resolveScopes = true) | ||
|
||
patchActualResult(result.toYaml()) should matchExpectedResult( | ||
expectedResultFile, | ||
definitionFile, | ||
custom = mapOf("<REPLACE_LOCKFILE_NAME>" to "package-lock.json") | ||
) | ||
} | ||
patchActualResult(result.toYaml()) should matchExpectedResult( | ||
expectedResultFile, | ||
definitionFile, | ||
custom = mapOf("<REPLACE_LOCKFILE_NAME>" to "package-lock.json") | ||
) | ||
} | ||
|
||
"resolve Babel dependencies correctly" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/babel/package.json") | ||
val expectedResultFile = getAssetFile("projects/synthetic/npm/babel-expected-output.yml") | ||
val expectedResult = patchExpectedResult(expectedResultFile, definitionFile) | ||
.fromYaml<ProjectAnalyzerResult>() | ||
"Resolve Babel dependencies correctly" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/babel/package.json") | ||
val expectedResultFile = getAssetFile("projects/synthetic/npm/babel-expected-output.yml") | ||
val expectedResult = patchExpectedResult(expectedResultFile, definitionFile) | ||
.fromYaml<ProjectAnalyzerResult>() | ||
|
||
val result = create("NPM").resolveSingleProject(definitionFile, resolveScopes = true) | ||
val result = create("NPM").resolveSingleProject(definitionFile, resolveScopes = true) | ||
|
||
result.withInvariantIssues().toYaml() shouldBe expectedResult.withInvariantIssues().toYaml() | ||
} | ||
result.withInvariantIssues().toYaml() shouldBe expectedResult.withInvariantIssues().toYaml() | ||
} | ||
|
||
"resolve dependencies with URLs as versions correctly" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/version-urls/package.json") | ||
val expectedResultFile = getAssetFile("projects/synthetic/npm/version-urls-expected-output.yml") | ||
val expectedResult = patchExpectedResult(expectedResultFile, definitionFile) | ||
.fromYaml<ProjectAnalyzerResult>() | ||
"Resolve dependencies with URLs as versions correctly" { | ||
val definitionFile = getAssetFile("projects/synthetic/npm/version-urls/package.json") | ||
val expectedResultFile = getAssetFile("projects/synthetic/npm/version-urls-expected-output.yml") | ||
val expectedResult = patchExpectedResult(expectedResultFile, definitionFile) | ||
.fromYaml<ProjectAnalyzerResult>() | ||
|
||
val result = create("NPM", allowDynamicVersions = true) | ||
.resolveSingleProject(definitionFile, resolveScopes = true) | ||
val result = create("NPM", allowDynamicVersions = true) | ||
.resolveSingleProject(definitionFile, resolveScopes = true) | ||
|
||
result.withInvariantIssues().toYaml() shouldBe expectedResult.withInvariantIssues().toYaml() | ||
} | ||
result.withInvariantIssues().toYaml() shouldBe expectedResult.withInvariantIssues().toYaml() | ||
} | ||
}) |
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
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
Oops, something went wrong.