wasp/waspc/e2e-test/Tests/WaspJobTest.hs

60 lines
1.7 KiB
Haskell
Raw Normal View History

module Tests.WaspJobTest (waspJob) where
import GoldenTest (GoldenTest, makeGoldenTest)
import ShellCommands
( ShellCommand,
ShellCommandBuilder,
appendToWaspFile,
cdIntoCurrentProject,
createFile,
setDbToPSQL,
waspCliCompile,
waspCliNew,
)
import Util ((<++>))
import Wasp.Project.Db (databaseUrlEnvVarName)
waspJob :: GoldenTest
waspJob = do
2023-03-02 17:05:24 +03:00
let jobDecl =
" job MySpecialJob { \n\
\ executor: PgBoss, \n\
\ perform: { \n\
Separate user code into client, server, shared (#753) * Separate ext code to client and server * Use skeleton in createNewProject and refactor * Refactor Lib.hs to use ExceptT * Fix formatting * Pop up returns * Extract liftIO and add a do block Co-authored-by: Shayne Czyzewski <523636+shayneczyzewski@users.noreply.github.com> * Address some review comments * Add skeleton comment * Extract common CommandError message * Separate skeleton comment into two rows * Move server and client dirs into src * Simplify maybeToEither * Further refactor Lib.hs * Further simplify skeleton comment * Add shared code directory to project structure * Update e2e test inputs * Update e2e test outputs * Fix formatting * Fix bug in compile function Co-authored-by: Martin Šošić <Martinsos@users.noreply.github.com> * Change map to fmap in compile function * Fix formatting * Force git to include empty directories * Remove extra empty line from .gitkeep files * Watch shared directory for changes * Fix regular and e2e tests * Fix cli template packaging and update todoApp * Add a shared function demo to todoApp * Update waspc and e2e tests * Fix compiler warnings and rename function * Rename mkError to mkParserError * Remove redundant empty line * Fix test warnings * Fix formatting * Fix directory tree watching on wasp start * Implement review feedback Co-authored-by: Shayne Czyzewski <523636+shayneczyzewski@users.noreply.github.com> Co-authored-by: Martin Šošić <Martinsos@users.noreply.github.com>
2022-11-11 19:20:49 +03:00
\ fn: import { foo } from \"@server/jobs/bar.js\" \n\
\ } \n\
\ } \n"
let jobFile =
" export const foo = async (args) => { \n\
\ return 1 \n\
\ } \n"
makeGoldenTest "waspJob" $
sequence
[ waspCliNew,
cdIntoCurrentProject,
setDbToPSQL,
2023-03-02 17:05:24 +03:00
appendToWaspFile jobDecl,
createFile jobFile "./src/server/jobs" "bar.js"
]
<++> addServerEnvFile
<++> sequence
[ waspCliCompile
]
addServerEnvFile :: ShellCommandBuilder [ShellCommand]
addServerEnvFile = do
sequence [createFile envFileContents "./" ".env.server"]
where
envFileContents =
unlines
[ -- NOTE: Since we are using PSQL in this test, if we don't set custom
-- database url in server/.env, Wasp will set its own, for managed dev db.
-- That is problematic because Wasp's db url depends on project's abs path,
-- which is not something we have constant during e2e tests, it depends
-- on the location where the tests are being run.
-- Therefore, we make sure to set custom database url here, to avoid .env
-- changing between different machines / setups.
databaseUrlEnvVarName <> "=" <> "mock-database-url"
]