2020-07-21 21:42:29 +03:00
|
|
|
module Generator.WebAppGeneratorTest where
|
2019-04-11 00:15:52 +03:00
|
|
|
|
2019-12-17 23:40:05 +03:00
|
|
|
import qualified CompileOptions
|
2021-04-28 18:36:00 +03:00
|
|
|
import Fixtures (systemPathRoot)
|
2019-04-11 00:15:52 +03:00
|
|
|
import Generator.FileDraft
|
2020-01-21 16:55:49 +03:00
|
|
|
import qualified Generator.FileDraft.CopyFileDraft as CopyFD
|
2021-04-28 18:36:00 +03:00
|
|
|
import qualified Generator.FileDraft.TemplateFileDraft as TmplFD
|
2020-01-21 16:55:49 +03:00
|
|
|
import qualified Generator.FileDraft.TextFileDraft as TextFD
|
2021-04-28 18:36:00 +03:00
|
|
|
import Generator.WebAppGenerator
|
2020-07-21 21:42:29 +03:00
|
|
|
import qualified Generator.WebAppGenerator.Common as Common
|
2021-04-28 18:36:00 +03:00
|
|
|
import qualified Path as P
|
|
|
|
import qualified StrongPath as SP
|
|
|
|
import System.FilePath ((</>))
|
|
|
|
import Test.Tasty.Hspec
|
2019-04-11 00:15:52 +03:00
|
|
|
import Wasp
|
|
|
|
|
2019-04-22 13:58:31 +03:00
|
|
|
-- TODO(martin): We could define Arbitrary instance for Wasp, 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
|
2021-04-28 18:36:00 +03:00
|
|
|
let testApp = (App "TestApp" "Test App" Nothing)
|
|
|
|
let testWasp = (fromApp testApp)
|
|
|
|
let testCompileOptions =
|
|
|
|
CompileOptions.CompileOptions
|
|
|
|
{ CompileOptions.externalCodeDirPath = SP.fromPathAbsDir $ systemPathRoot P.</> [P.reldir|test/src|],
|
|
|
|
CompileOptions.isBuild = False
|
|
|
|
}
|
2019-04-22 13:58:31 +03:00
|
|
|
|
2021-04-28 18:36:00 +03:00
|
|
|
describe "generateWebApp" $ do
|
|
|
|
-- 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.
|
|
|
|
it "Given a simple Wasp, creates file drafts at expected destinations" $ do
|
|
|
|
let fileDrafts = generateWebApp testWasp testCompileOptions
|
|
|
|
let expectedFileDraftDstPaths =
|
|
|
|
map ((SP.toFilePath Common.webAppRootDirInProjectRootDir) </>) $
|
|
|
|
concat $
|
|
|
|
[ [ "README.md",
|
|
|
|
"package.json",
|
|
|
|
".gitignore"
|
|
|
|
],
|
|
|
|
map
|
|
|
|
("public" </>)
|
|
|
|
[ "favicon.ico",
|
|
|
|
"index.html",
|
|
|
|
"manifest.json"
|
|
|
|
],
|
|
|
|
map
|
|
|
|
((SP.toFilePath Common.webAppSrcDirInWebAppRootDir) </>)
|
|
|
|
[ "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
|
|
|
|
getFileDraftDstPath (FileDraftTextFd fd) = SP.toFilePath $ TextFD._dstPath fd
|