2020-08-25 21:10:59 +03:00
|
|
|
module Generator.ExternalCodeGenerator.JsTest where
|
2020-07-21 21:42:29 +03:00
|
|
|
|
2021-04-28 18:36:00 +03:00
|
|
|
import Generator.ExternalCodeGenerator.Common (asGenExtFile)
|
|
|
|
import Generator.ExternalCodeGenerator.Js as Js
|
2020-07-28 17:52:03 +03:00
|
|
|
import qualified StrongPath as SP
|
2021-04-28 18:36:00 +03:00
|
|
|
import Test.Tasty.Hspec
|
2020-07-21 21:42:29 +03:00
|
|
|
|
2020-08-25 21:10:59 +03:00
|
|
|
spec_resolveJsFileWaspImportsForExtCodeDir :: Spec
|
|
|
|
spec_resolveJsFileWaspImportsForExtCodeDir = do
|
2021-07-03 12:00:01 +03:00
|
|
|
(asGenExtFile [SP.relfile|extFile.js|], "import foo from 'bar'") ~> "import foo from 'bar'"
|
|
|
|
(asGenExtFile [SP.relfile|extFile.js|], "import foo from '@wasp/bar'") ~> "import foo from '../bar'"
|
|
|
|
(asGenExtFile [SP.relfile|a/extFile.js|], "import foo from \"@wasp/bar/foo\"")
|
2021-04-28 18:36:00 +03:00
|
|
|
~> "import foo from \"../../bar/foo\""
|
2020-07-21 21:42:29 +03:00
|
|
|
where
|
|
|
|
(path, text) ~> expectedText =
|
2021-04-28 18:36:00 +03:00
|
|
|
it (SP.toFilePath path ++ " " ++ show text ++ " -> " ++ show expectedText) $ do
|
2021-07-03 12:00:01 +03:00
|
|
|
Js.resolveJsFileWaspImportsForExtCodeDir [SP.reldir|src|] path text `shouldBe` expectedText
|