Skip to content

Commit 93378a4

Browse files
committed
[ANE-2235] Fix pnpm v9 test dependencies
1 parent 67fd875 commit 93378a4

File tree

1 file changed

+52
-18
lines changed

1 file changed

+52
-18
lines changed

test/Pnpm/PnpmLockSpec.hs

+52-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module Pnpm.PnpmLockSpec (
44
spec,
55
) where
66

7-
import Data.Either (fromRight)
7+
import Data.ByteString qualified as BS
8+
import Data.Either (fromRight, isRight)
89
import Data.Set qualified as Set
910
import Data.String.Conversion (toString)
1011
import Data.Text (Text)
@@ -23,16 +24,16 @@ import GraphUtil (
2324
import Graphing (Graphing)
2425
import Path (Abs, File, Path, mkRelFile, (</>))
2526
import Path.IO (getCurrentDir)
26-
import Strategy.Node.Pnpm.PnpmLock (buildGraph)
27+
import Strategy.Node.Pnpm.PnpmLock (analyze, buildGraph)
2728
import Test.Hspec (
2829
Spec,
2930
describe,
3031
expectationFailure,
3132
it,
3233
runIO,
34+
shouldMatchList,
35+
shouldSatisfy,
3336
)
34-
import Test.Hspec.Core.QuickCheck (shouldSatisfy)
35-
import Test.Hspec.Expectations (shouldMatchList)
3637

3738
-- | A dependency value used as a default in case of parsing errors in tests
3839
invalidDependency :: Dependency
@@ -124,24 +125,33 @@ spec = do
124125

125126
-- v9 format
126127
let pnpmLockV9 = currentDir </> $(mkRelFile "test/Pnpm/testdata/pnpm-lock-v9.yaml")
128+
let pnpmLockV9Test = currentDir </> $(mkRelFile "test/Pnpm/testdata/pnpm-lock-v9-test.yaml")
127129

128130
describe "can work with v9.0 format" $ do
129-
checkGraph pnpmLockV9 pnpmLockV9GraphSpec
131+
describe "with real-world pnpm repo lockfile" $
132+
checkGraph pnpmLockV9 pnpmLockV9GraphSpec
133+
134+
describe "with test dependencies" $
135+
checkGraph pnpmLockV9Test pnpmLockV9TestGraphSpec
130136

131137
describe "parsePnpmLock" $ do
132-
it "parses v6 lockfile" $ do
133-
lockfile <- readFileBS "test/Pnpm/fixtures/pnpm-lock-v6.yaml"
134-
let result = parsePnpmLock lockfile
135-
result `shouldSatisfy` isRight
136-
let Right deps = result
137-
deps `shouldMatchList` [colors, mkDevDep "[email protected]", mkDevDep "[email protected]"]
138-
139-
it "parses v9 lockfile" $ do
140-
lockfile <- readFileBS "test/Pnpm/fixtures/pnpm-lock-v9.yaml"
141-
let result = parsePnpmLock lockfile
142-
result `shouldSatisfy` isRight
143-
let Right deps = result
144-
deps `shouldMatchList` [colors, mkDevDep "[email protected]", mkDevDep "[email protected]"]
138+
currentDir <- runIO getCurrentDir
139+
let v6LockfilePath = currentDir </> $(mkRelFile "test/Pnpm/testdata/pnpm-lock-v6.yaml")
140+
let v9LockfilePath = currentDir </> $(mkRelFile "test/Pnpm/testdata/pnpm-lock-v9.yaml")
141+
142+
checkGraph v6LockfilePath $ \graph ->
143+
it "parses v6 lockfile" $
144+
expectDirect [colors, mkDevDep "[email protected]", mkDevDep "[email protected]"] graph
145+
146+
checkGraph v9LockfilePath $ \graph ->
147+
it "parses v9 lockfile" $
148+
expectDirect
149+
[ mkProdDep "[email protected]"
150+
, mkProdDep "[email protected]"
151+
, mkProdDep "[email protected]"
152+
, mkProdDep "[email protected]"
153+
]
154+
graph
145155

146156
pnpmLockGraphSpec :: Graphing Dependency -> Spec
147157
pnpmLockGraphSpec graph = do
@@ -441,3 +451,27 @@ pnpmLockV9GraphSpec graph = do
441451
hasEdge (mkProdDep "@babel/[email protected]") (mkProdDep "@babel/core@^7.0.0")
442452
hasEdge (mkProdDep "@babel/[email protected]") (mkProdDep "@babel/types@*")
443453
hasEdge (mkProdDep "@babel/[email protected]") (mkProdDep "@babel/types@*")
454+
455+
pnpmLockV9TestGraphSpec :: Graphing Dependency -> Spec
456+
pnpmLockV9TestGraphSpec graph = do
457+
let hasEdge :: Dependency -> Dependency -> IO ()
458+
hasEdge = expectEdge graph
459+
460+
describe "buildGraph with test dependencies" $ do
461+
it "should include git, url and dev dependencies" $ do
462+
expectDirect
463+
[ colorsTarball
464+
, lodash
465+
, mkDevDep "[email protected]"
466+
]
467+
graph
468+
469+
it "should include all relevant edges for aws-sdk" $ do
470+
hasEdge (mkProdDep "[email protected]") (mkProdDep "[email protected]")
471+
hasEdge (mkProdDep "[email protected]") (mkProdDep "[email protected]")
472+
hasEdge (mkProdDep "[email protected]") (mkProdDep "[email protected]")
473+
hasEdge (mkProdDep "[email protected]") (mkProdDep "[email protected]")
474+
475+
it "should include all relevant edges for react" $ do
476+
hasEdge (mkDevDep "[email protected]") (mkDevDep "[email protected]")
477+
hasEdge (mkDevDep "[email protected]") (mkDevDep "[email protected]")

0 commit comments

Comments
 (0)