diff --git a/waspc/test/Generator/JsImportTest.hs b/waspc/test/Generator/JsImportTest.hs index a402024f7..189cb31df 100644 --- a/waspc/test/Generator/JsImportTest.hs +++ b/waspc/test/Generator/JsImportTest.hs @@ -22,7 +22,7 @@ spec_GeneratorJsImportTest = do it "makes a JsImport from ExtImport" $ do extImportToJsImport pathToExtCodeDir pathFromImportLocationToExtCodeDir extImport `shouldBe` JI.JsImport - { JI._path = [SP.relfileP|../ext-src/folder/test.js|], + { JI._path = JI.RelativeImportPath [SP.relfileP|../ext-src/folder/test.js|], JI._name = JsImportModule "test", JI._importAlias = Nothing } diff --git a/waspc/test/JsImportTest.hs b/waspc/test/JsImportTest.hs index e61086105..6fbbe229c 100644 --- a/waspc/test/JsImportTest.hs +++ b/waspc/test/JsImportTest.hs @@ -1,6 +1,6 @@ module JsImportTest where -import StrongPath (Dir', File', Path, Posix, Rel, ()) +import StrongPath (()) import qualified StrongPath as SP import Test.Tasty.Hspec (Spec, describe, it, shouldBe) import Wasp.JsImport @@ -9,43 +9,53 @@ spec_JsImportTest :: Spec spec_JsImportTest = do describe "makeJsImport" $ do it "makes JsImport with default import from a path" $ do - makeJsImport testJsFileImportPath (JsImportModule "test") + makeJsImport testRelativeImportPath (JsImportModule "test") `shouldBe` JsImport - { _path = testJsFileImportPath, + { _path = testRelativeImportPath, _name = JsImportModule "test", _importAlias = Nothing } describe "applyJsImportAlias" $ do it "applies alias to JsImport" $ do - let jsImport = makeJsImport testJsFileImportPath (JsImportModule "test") + let jsImport = makeJsImport testRelativeImportPath (JsImportModule "test") applyJsImportAlias (Just "alias") jsImport `shouldBe` jsImport {_importAlias = Just "alias"} describe "getJsImportStmtAndIdentifier" $ do describe "generates import statement and identifier from" $ do it "default import" $ do getJsImportStmtAndIdentifier - (makeJsImport testJsFileImportPath (JsImportModule "test")) - `shouldBe` ("import test from '" ++ generatedImportPathForTestJsFile ++ "'", "test") + (makeJsImport testRelativeImportPath (JsImportModule "test")) + `shouldBe` ("import test from '" ++ generatedImportPathForRelativeImportPath ++ "'", "test") it "default import with alias" $ do getJsImportStmtAndIdentifier ( applyJsImportAlias (Just "alias") - (makeJsImport testJsFileImportPath (JsImportModule "test")) + (makeJsImport testRelativeImportPath (JsImportModule "test")) ) - `shouldBe` ("import alias from '" ++ generatedImportPathForTestJsFile ++ "'", "alias") + `shouldBe` ("import alias from '" ++ generatedImportPathForRelativeImportPath ++ "'", "alias") it "named import" $ do getJsImportStmtAndIdentifier - (makeJsImport testJsFileImportPath (JsImportField "test")) - `shouldBe` ("import { test } from '" ++ generatedImportPathForTestJsFile ++ "'", "test") + (makeJsImport testRelativeImportPath (JsImportField "test")) + `shouldBe` ("import { test } from '" ++ generatedImportPathForRelativeImportPath ++ "'", "test") it "named import with alias" $ do getJsImportStmtAndIdentifier ( applyJsImportAlias (Just "alias") - (makeJsImport testJsFileImportPath (JsImportField "test")) + (makeJsImport testRelativeImportPath (JsImportField "test")) ) - `shouldBe` ("import { test as alias } from '" ++ generatedImportPathForTestJsFile ++ "'", "alias") + `shouldBe` ("import { test as alias } from '" ++ generatedImportPathForRelativeImportPath ++ "'", "alias") + it "import from module" $ do + getJsImportStmtAndIdentifier + (makeJsImport testModuleImportPath (JsImportModule "test")) + `shouldBe` ("import test from '" ++ generatedImportPathForModuleImportPath ++ "'", "test") where - testJsFileImportPath :: Path Posix (Rel Dir') File' - testJsFileImportPath = [SP.reldirP|ext-src|] [SP.relfileP|folder/test.js|] + testRelativeImportPath :: JsImportPath + testRelativeImportPath = RelativeImportPath $ [SP.reldirP|ext-src|] [SP.relfileP|folder/test.js|] - generatedImportPathForTestJsFile = "./ext-src/folder/test.js" + generatedImportPathForRelativeImportPath = "./ext-src/folder/test.js" + + testModuleImportPath :: JsImportPath + testModuleImportPath = ModuleImportPath [SP.relfileP|wasp/server/api|] + + generatedImportPathForModuleImportPath :: String + generatedImportPathForModuleImportPath = "wasp/server/api"