Skip to content

Commit 67fd875

Browse files
committed
[ANE-2235] Fix hlint warnings in PnpmLockSpec.hs by replacing error/undefined with invalidDependency
1 parent 50ed98b commit 67fd875

File tree

1 file changed

+49
-11
lines changed

1 file changed

+49
-11
lines changed

Diff for: test/Pnpm/PnpmLockSpec.hs

+49-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Pnpm.PnpmLockSpec (
44
spec,
55
) where
66

7+
import Data.Either (fromRight)
78
import Data.Set qualified as Set
89
import Data.String.Conversion (toString)
910
import Data.Text (Text)
@@ -30,26 +31,40 @@ import Test.Hspec (
3031
it,
3132
runIO,
3233
)
34+
import Test.Hspec.Core.QuickCheck (shouldSatisfy)
35+
import Test.Hspec.Expectations (shouldMatchList)
36+
37+
-- | A dependency value used as a default in case of parsing errors in tests
38+
invalidDependency :: Dependency
39+
invalidDependency =
40+
Dependency
41+
NodeJSType
42+
"INVALID_PACKAGE_NAME"
43+
Nothing
44+
mempty
45+
mempty
46+
mempty
3347

3448
mkProdDep :: Text -> Dependency
35-
mkProdDep nameAtVersion = mkDep nameAtVersion (Just EnvProduction)
49+
mkProdDep nameAtVersion = fromRight invalidDependency $ mkDep nameAtVersion (Just EnvProduction)
3650

3751
mkDevDep :: Text -> Dependency
38-
mkDevDep nameAtVersion = mkDep nameAtVersion (Just EnvDevelopment)
52+
mkDevDep nameAtVersion = fromRight invalidDependency $ mkDep nameAtVersion (Just EnvDevelopment)
3953

40-
mkDep :: Text -> Maybe DepEnvironment -> Dependency
54+
mkDep :: Text -> Maybe DepEnvironment -> Either String Dependency
4155
mkDep nameAtVersion env = do
4256
let nameAndVersionSplit = Text.splitOn "@" nameAtVersion
4357
case nameAndVersionSplit of
4458
[name, version] ->
45-
Dependency
46-
NodeJSType
47-
name
48-
(CEq <$> (Just version))
49-
mempty
50-
(maybe mempty Set.singleton env)
51-
mempty
52-
_ -> error $ "Invalid package name format: " ++ toString nameAtVersion
59+
Right $
60+
Dependency
61+
NodeJSType
62+
name
63+
(CEq <$> (Just version))
64+
mempty
65+
(maybe mempty Set.singleton env)
66+
mempty
67+
_ -> Left $ "Invalid package name format: " ++ toString nameAtVersion
5368

5469
colors :: Dependency
5570
colors =
@@ -113,6 +128,21 @@ spec = do
113128
describe "can work with v9.0 format" $ do
114129
checkGraph pnpmLockV9 pnpmLockV9GraphSpec
115130

131+
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]"]
145+
116146
pnpmLockGraphSpec :: Graphing Dependency -> Spec
117147
pnpmLockGraphSpec graph = do
118148
let hasEdge :: Dependency -> Dependency -> IO ()
@@ -403,3 +433,11 @@ pnpmLockV9GraphSpec graph = do
403433
, mkProdDep "@npmcli/[email protected]"
404434
]
405435
graph
436+
437+
it "should include Babel plugin dependencies" $ do
438+
-- Test a few representative Babel plugin dependencies
439+
hasEdge (mkProdDep "@babel/[email protected]") (mkProdDep "@babel/core@^7.0.0")
440+
hasEdge (mkProdDep "@babel/[email protected]") (mkProdDep "@babel/core@^7.0.0")
441+
hasEdge (mkProdDep "@babel/[email protected]") (mkProdDep "@babel/core@^7.0.0")
442+
hasEdge (mkProdDep "@babel/[email protected]") (mkProdDep "@babel/types@*")
443+
hasEdge (mkProdDep "@babel/[email protected]") (mkProdDep "@babel/types@*")

0 commit comments

Comments
 (0)