2020-07-21 21:42:29 +03:00
|
|
|
module Generator.WebAppGeneratorTest where
|
2019-04-11 00:15:52 +03:00
|
|
|
|
2021-07-03 12:00:01 +03:00
|
|
|
import Fixtures (systemSPRoot)
|
2021-04-28 18:36:00 +03:00
|
|
|
import qualified StrongPath as SP
|
|
|
|
import System.FilePath ((</>))
|
|
|
|
import Test.Tasty.Hspec
|
2022-01-20 13:45:14 +03:00
|
|
|
import qualified Wasp.AppSpec as AS
|
|
|
|
import qualified Wasp.AppSpec.App as AS.App
|
|
|
|
import qualified Wasp.AppSpec.Core.Decl as AS.Decl
|
2021-11-11 15:26:20 +03:00
|
|
|
import Wasp.Generator.FileDraft
|
2022-01-12 19:28:21 +03:00
|
|
|
import qualified Wasp.Generator.FileDraft.CopyDirFileDraft as CopyDirFD
|
2021-11-11 15:26:20 +03:00
|
|
|
import qualified Wasp.Generator.FileDraft.CopyFileDraft as CopyFD
|
|
|
|
import qualified Wasp.Generator.FileDraft.TemplateFileDraft as TmplFD
|
|
|
|
import qualified Wasp.Generator.FileDraft.TextFileDraft as TextFD
|
2022-01-23 17:21:31 +03:00
|
|
|
import Wasp.Generator.Monad (runGenerator)
|
2021-11-11 15:26:20 +03:00
|
|
|
import Wasp.Generator.WebAppGenerator
|
|
|
|
import qualified Wasp.Generator.WebAppGenerator.Common as Common
|
2019-04-11 00:15:52 +03:00
|
|
|
|
2022-01-20 13:45:14 +03:00
|
|
|
-- TODO(martin): We could maybe define Arbitrary instance for AppSpec, define properties
|
|
|
|
-- over generator functions and then do property testing on them, that would be cool.
|
2019-04-11 00:15:52 +03:00
|
|
|
|
2020-07-21 21:42:29 +03:00
|
|
|
spec_WebAppGenerator :: Spec
|
|
|
|
spec_WebAppGenerator = do
|
2022-01-20 13:45:14 +03:00
|
|
|
let testAppSpec =
|
|
|
|
AS.AppSpec
|
|
|
|
{ AS.decls =
|
|
|
|
[ AS.Decl.makeDecl
|
|
|
|
"TestApp"
|
|
|
|
AS.App.App
|
|
|
|
{ AS.App.title = "Test App",
|
|
|
|
AS.App.db = Nothing,
|
|
|
|
AS.App.server = Nothing,
|
|
|
|
AS.App.auth = Nothing,
|
|
|
|
AS.App.dependencies = Nothing,
|
|
|
|
AS.App.head = Nothing
|
|
|
|
}
|
|
|
|
],
|
|
|
|
AS.externalCodeDirPath = systemSPRoot SP.</> [SP.reldir|test/src|],
|
|
|
|
AS.externalCodeFiles = [],
|
|
|
|
AS.isBuild = False,
|
|
|
|
AS.migrationsDir = Nothing,
|
|
|
|
AS.dotEnvFile = Nothing
|
2021-04-28 18:36:00 +03:00
|
|
|
}
|
2019-04-22 13:58:31 +03:00
|
|
|
|
2022-03-21 17:00:19 +03:00
|
|
|
describe "genWebApp" $ do
|
2021-04-28 18:36:00 +03:00
|
|
|
-- NOTE: This test does not (for now) check that content of files is correct or
|
|
|
|
-- that they will successfully be written, it checks only that their
|
|
|
|
-- destinations are correct.
|
2022-01-20 13:45:14 +03:00
|
|
|
it "Given a simple AppSpec, creates file drafts at expected destinations" $ do
|
2022-03-21 17:00:19 +03:00
|
|
|
let (_, Right fileDrafts) = runGenerator $ genWebApp testAppSpec
|
2021-04-28 18:36:00 +03:00
|
|
|
let expectedFileDraftDstPaths =
|
2021-11-17 02:36:46 +03:00
|
|
|
map (SP.toFilePath Common.webAppRootDirInProjectRootDir </>) $
|
|
|
|
concat
|
2021-04-28 18:36:00 +03:00
|
|
|
[ [ "README.md",
|
|
|
|
"package.json",
|
|
|
|
".gitignore"
|
|
|
|
],
|
|
|
|
map
|
|
|
|
("public" </>)
|
|
|
|
[ "favicon.ico",
|
|
|
|
"index.html",
|
|
|
|
"manifest.json"
|
|
|
|
],
|
|
|
|
map
|
2021-11-17 02:36:46 +03:00
|
|
|
(SP.toFilePath Common.webAppSrcDirInWebAppRootDir </>)
|
2021-04-28 18:36:00 +03:00
|
|
|
[ "logo.png",
|
|
|
|
"index.css",
|
|
|
|
"index.js",
|
|
|
|
"router.js",
|
|
|
|
"serviceWorker.js"
|
2019-04-11 00:15:52 +03:00
|
|
|
]
|
2021-04-28 18:36:00 +03:00
|
|
|
]
|
2019-12-17 23:40:05 +03:00
|
|
|
|
2021-04-28 18:36:00 +03:00
|
|
|
mapM_
|
|
|
|
-- NOTE(martin): I added fd to the pair here in order to have it
|
|
|
|
-- printed when shouldBe fails, otherwise I could not know which
|
|
|
|
-- file draft failed.
|
|
|
|
( \dstPath ->
|
|
|
|
(dstPath, existsFdWithDst fileDrafts dstPath)
|
|
|
|
`shouldBe` (dstPath, True)
|
|
|
|
)
|
|
|
|
expectedFileDraftDstPaths
|
2019-04-11 00:15:52 +03:00
|
|
|
|
2019-04-22 13:58:31 +03:00
|
|
|
existsFdWithDst :: [FileDraft] -> FilePath -> Bool
|
|
|
|
existsFdWithDst fds dstPath = any ((== dstPath) . getFileDraftDstPath) fds
|
2019-04-11 00:15:52 +03:00
|
|
|
|
2020-01-15 15:08:13 +03:00
|
|
|
-- TODO(martin): This should really become part of the Writeable typeclass,
|
2019-07-02 21:47:16 +03:00
|
|
|
-- since it is smth we want to do for all file drafts.
|
2019-04-11 00:15:52 +03:00
|
|
|
getFileDraftDstPath :: FileDraft -> FilePath
|
2020-07-28 17:52:03 +03:00
|
|
|
getFileDraftDstPath (FileDraftTemplateFd fd) = SP.toFilePath $ TmplFD._dstPath fd
|
|
|
|
getFileDraftDstPath (FileDraftCopyFd fd) = SP.toFilePath $ CopyFD._dstPath fd
|
2022-01-12 19:28:21 +03:00
|
|
|
getFileDraftDstPath (FileDraftCopyDirFd fd) = SP.toFilePath $ CopyDirFD._dstPath fd
|
2020-07-28 17:52:03 +03:00
|
|
|
getFileDraftDstPath (FileDraftTextFd fd) = SP.toFilePath $ TextFD._dstPath fd
|