Skip to content

Commit

Permalink
Fixes e2e tests (#1761)
Browse files Browse the repository at this point in the history
* Fixes e2e tests

Signed-off-by: Mihovil Ilakovac <[email protected]>

* Adds new e2e tests

* Update build tests

---------

Signed-off-by: Mihovil Ilakovac <[email protected]>
Co-authored-by: Filip Sodić <[email protected]>
  • Loading branch information
infomiho and sodic authored Feb 16, 2024
1 parent 5cd5130 commit 292f06b
Show file tree
Hide file tree
Showing 1,601 changed files with 22,216 additions and 10,510 deletions.
12 changes: 6 additions & 6 deletions waspc/e2e-test/ShellCommands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module ShellCommands
waspCliMigrate,
waspCliBuild,
dockerBuild,
insertCodeIntoWaspFileAtLineNumber,
insertCodeIntoFileAtLineNumber,
)
where

Expand Down Expand Up @@ -73,14 +73,14 @@ createFile content relDirFp filename = return $ combineShellCommands [createPare
-- we do not have a `db` field. Consider better alternatives.
setDbToPSQL :: ShellCommandBuilder ShellCommand
-- Change DB to postgres by adding string at specific line so it still parses.
setDbToPSQL = insertCodeIntoWaspFileAtLineNumber 2 " db: { system: PostgreSQL },"
setDbToPSQL = insertCodeIntoFileAtLineNumber "main.wasp" 2 " db: { system: PostgreSQL },"

insertCodeIntoWaspFileAtLineNumber :: Int -> String -> ShellCommandBuilder ShellCommand
insertCodeIntoWaspFileAtLineNumber atLineNumber line =
insertCodeIntoFileAtLineNumber :: FilePath -> Int -> String -> ShellCommandBuilder ShellCommand
insertCodeIntoFileAtLineNumber fileName atLineNumber line =
return $
combineShellCommands
[ "awk 'NR==" ++ show atLineNumber ++ "{print " ++ show line ++ "}1' main.wasp > main.wasp.tmp",
"mv main.wasp.tmp main.wasp"
[ "awk 'NR==" ++ show atLineNumber ++ "{print " ++ show line ++ "}1' " ++ fileName ++ " > " ++ fileName ++ ".tmp",
"mv " ++ fileName ++ ".tmp " ++ fileName
]

waspCliNew :: ShellCommandBuilder ShellCommand
Expand Down
56 changes: 30 additions & 26 deletions waspc/e2e-test/Tests/WaspComplexTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ShellCommands
appendToWaspFile,
cdIntoCurrentProject,
createFile,
insertCodeIntoWaspFileAtLineNumber,
insertCodeIntoFileAtLineNumber,
setDbToPSQL,
waspCliCompile,
waspCliNew,
Expand Down Expand Up @@ -54,8 +54,8 @@ addClientSetup = do
clientField =
unlines
[ " client: {",
" setupFn: import myClientSetupFunction from \"@client/myClientSetupCode.js\",",
" rootComponent: import App from \"@client/App.jsx\"",
" setupFn: import myClientSetupFunction from \"@src/client/myClientSetupCode.js\",",
" rootComponent: import App from \"@src/client/App.jsx\"",
" },"
]
rootComponentContent =
Expand Down Expand Up @@ -87,7 +87,7 @@ addServerSetup = do
serverField =
unlines
[ " server: {",
" setupFn: import mySetupFunction from \"@server/myServerSetupCode.js\",",
" setupFn: import mySetupFunction from \"@src/server/myServerSetupCode.js\",",
" },"
]
serverSetupFnContent =
Expand All @@ -106,10 +106,10 @@ addJob = do
where
jobDecl =
unlines
[ "job MySpecialJob {",
[ "job mySpecialJob {",
" executor: PgBoss,",
" perform: {",
" fn: import { foo } from \"@server/jobs/bar.js\"",
" fn: import { foo } from \"@src/server/jobs/bar.js\"",
" }",
"}"
]
Expand All @@ -130,18 +130,18 @@ addTsJob = do
where
jobDecl =
unlines
[ "job ReturnHelloJob {",
[ "job returnHelloJob {",
" executor: PgBoss,",
" perform: {",
" fn: import { returnHello } from \"@server/jobs/returnHello.js\",",
" fn: import { returnHello } from \"@src/server/jobs/returnHello.js\",",
" },",
" entities: [User],",
"}"
]

jobFile =
unlines
[ "import { ReturnHelloJob } from '@wasp/jobs/ReturnHelloJob'",
[ "import { ReturnHelloJob } from 'wasp/server/jobs'",
"export const returnHello: ReturnHelloJob<{ name: string }, string> = async (args) => {",
" return args.name",
"}"
Expand Down Expand Up @@ -218,8 +218,8 @@ addAction = do
where
actionDecl =
unlines
[ "action MySpecialAction {",
" fn: import { foo } from \"@server/actions/bar.js\",",
[ "action mySpecialAction {",
" fn: import { foo } from \"@src/server/actions/bar.js\",",
" entities: [User],",
"}"
]
Expand All @@ -240,8 +240,8 @@ addQuery = do
where
queryDecl =
unlines
[ "query MySpecialQuery {",
" fn: import { foo } from \"@server/queries/bar.js\",",
[ "query mySpecialQuery {",
" fn: import { foo } from \"@src/server/queries/bar.js\",",
" entities: [User],",
"}"
]
Expand All @@ -256,15 +256,13 @@ addQuery = do
addDependencies :: ShellCommandBuilder [ShellCommand]
addDependencies = do
sequence
[ insertCodeIntoWaspFileAfterVersion deps
[ insertCodeIntoPackageJsonIntoDependencies deps
]
where
deps =
unlines
[ " dependencies: [",
" (\"redux\", \"^4.0.5\"),",
" (\"react-redux\", \"^7.1.3\")",
" ],"
[ " \"redux\": \"^4.0.5\",",
" \"react-redux\": \"^7.1.3\","
]

addApi :: ShellCommandBuilder [ShellCommand]
Expand All @@ -277,21 +275,21 @@ addApi = do
apiDecls =
unlines
[ "api fooBar {",
" fn: import { fooBar } from \"@server/apis.js\",",
" fn: import { fooBar } from \"@src/server/apis.js\",",
" httpRoute: (GET, \"/foo/bar\"),",
" middlewareConfigFn: import { fooBarMiddlewareFn } from \"@server/apis.js\"",
" middlewareConfigFn: import { fooBarMiddlewareFn } from \"@src/server/apis.js\"",
"}",
"api fooBaz {",
" fn: import { fooBaz } from \"@server/apis.js\",",
" fn: import { fooBaz } from \"@src/server/apis.js\",",
" httpRoute: (GET, \"/foo/baz\"),",
" auth: false",
"}"
]

apiFile =
unlines
[ "import { FooBar, FooBaz } from '@wasp/apis/types'",
"import { MiddlewareConfigFn } from '@wasp/middleware'",
[ "import { FooBar, FooBaz } from 'wasp/server/api'",
"import { MiddlewareConfigFn } from 'wasp/server'",
"export const fooBar: FooBar = (req, res, context) => {",
" res.set('Access-Control-Allow-Origin', '*')",
" res.json({ msg: 'Hello, context.user.username!' })",
Expand All @@ -314,14 +312,14 @@ addApiNamespace = do
apiNamespaceDecl =
unlines
[ "apiNamespace fooBarNamespace {",
" middlewareConfigFn: import { fooBarNamespaceMiddlewareFn } from \"@server/apiNamespaces.js\",",
" middlewareConfigFn: import { fooBarNamespaceMiddlewareFn } from \"@src/server/apiNamespaces.js\",",
" path: \"/bar\"",
"}"
]

apiNamespaceFile =
unlines
[ "import { MiddlewareConfigFn } from '@wasp/middleware'",
[ "import { MiddlewareConfigFn } from 'wasp/server'",
"export const fooBarNamespaceMiddlewareFn: MiddlewareConfigFn = (middlewareConfig) => {",
" return middlewareConfig",
"}"
Expand Down Expand Up @@ -372,7 +370,13 @@ addCrud = do
]

insertCodeIntoWaspFileAfterVersion :: String -> ShellCommandBuilder ShellCommand
insertCodeIntoWaspFileAfterVersion = insertCodeIntoWaspFileAtLineNumber lineNumberInWaspFileAfterVersion
insertCodeIntoWaspFileAfterVersion = insertCodeIntoFileAtLineNumber "main.wasp" lineNumberInWaspFileAfterVersion
where
lineNumberInWaspFileAfterVersion :: Int
lineNumberInWaspFileAfterVersion = 5

insertCodeIntoPackageJsonIntoDependencies :: String -> ShellCommandBuilder ShellCommand
insertCodeIntoPackageJsonIntoDependencies = insertCodeIntoFileAtLineNumber "package.json" lineNumberInPackageJsonDependencies
where
lineNumberInPackageJsonDependencies :: Int
lineNumberInPackageJsonDependencies = 3
4 changes: 2 additions & 2 deletions waspc/e2e-test/Tests/WaspJobTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import Wasp.Project.Db (databaseUrlEnvVarName)
waspJob :: GoldenTest
waspJob = do
let jobDecl =
" job MySpecialJob { \n\
" job mySpecialJob { \n\
\ executor: PgBoss, \n\
\ perform: { \n\
\ fn: import { foo } from \"@server/jobs/bar.js\" \n\
\ fn: import { foo } from \"@src/server/jobs/bar.js\" \n\
\ } \n\
\ } \n"

Expand Down
Loading

0 comments on commit 292f06b

Please sign in to comment.