-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
66c5040
commit 3344c6f
Showing
2 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
internal/resolution/lockfile/fixtures/npm_type_order/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -43,7 +43,6 @@ r 1.0.0 | |
Dev KnownAs a-dev|@fake-registry/a@^2.3.4 2.3.4 | ||
@fake-registry/b@^2.0.0 2.0.0 | ||
c: @fake-registry/c@^1.0.0 1.1.1 | ||
# peerDependency becomes optional | ||
Scope peer|$d@^2.0.0 | ||
d: @fake-registry/d@^2.0.0 2.2.2 | ||
# workspace | ||
|
@@ -113,6 +112,49 @@ r 1.0.0 | |
} | ||
} | ||
|
||
func TestNpmReadTypeOrder(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Testing the behavior when a package is included in multiple dependency type fields. | ||
// Empirically, devDependencies > optionalDependencies > dependencies > peerDependencies | ||
|
||
// This lockfile was manually constructed. | ||
df, err := lf.OpenLocalDepFile("./fixtures/npm_type_order/package-lock.json") | ||
if err != nil { | ||
t.Fatalf("failed to open file: %v", err) | ||
} | ||
defer df.Close() | ||
|
||
npmRW := lockfile.NpmReadWriter{} | ||
got, err := npmRW.Read(df) | ||
if err != nil { | ||
t.Fatalf("failed to read file: %v", err) | ||
} | ||
|
||
if err := got.Canon(); err != nil { | ||
t.Fatalf("failed canonicalizing got graph: %v", err) | ||
} | ||
|
||
want, err := schema.ParseResolve(` | ||
root 1.0.0 | ||
Dev|[email protected] 4.0.0 | ||
Opt|[email protected] 3.0.0 | ||
[email protected] 2.0.0 | ||
Scope peer|[email protected] 1.0.0 | ||
`, resolve.NPM) | ||
if err != nil { | ||
t.Fatalf("error parsing want graph: %v", err) | ||
} | ||
|
||
if err := want.Canon(); err != nil { | ||
t.Fatalf("failed canonicalizing want graph: %v", err) | ||
} | ||
|
||
if diff := cmp.Diff(want, got); diff != "" { | ||
t.Errorf("npm lockfile mismatch (-want +got):\n%s", diff) | ||
} | ||
} | ||
|
||
func TestNpmWrite(t *testing.T) { | ||
t.Parallel() | ||
|
||
|