Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Testing docs #1126

Merged
merged 1 commit into from
Oct 17, 2021
Merged

Fix Testing docs #1126

merged 1 commit into from
Oct 17, 2021

Conversation

amitaibu
Copy link
Collaborator

No description provided.

import IHP.FrameworkConfig (ConfigBuilder(..))
import IHP.Prelude
import IHP.QueryBuilder (fetch, query)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiler complained fetch doesn't exist in this package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fetch functions have moved from IHP.QueryBuilder to IHP.Fetch


import Web.Types
import Web.Routes
import Generated.Types
import Main ()

-- a function like this probably already exists in your Config module:
makeConfig :: IO ConfigBuilder
makeConfig = ...
-- makeConfig :: IO ConfigBuilder
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to make it easier to copy/ paste

@amitaibu
Copy link
Collaborator Author

I'm couldn't install hspec locally (Ubuntu 20), but also couldn't make it work on GitPod.io .

I've shared a workspace. Maybe others could have a look and help find the problem, without needing to install anything locally. (GitPod spinned of https://github.com/gitpod-io/template-ihp)

@mpscholten
Copy link
Member

It got this error when trying to access the gitpod:

image

What command are you using to run the test?

@amitaibu
Copy link
Collaborator Author

What command are you using to run the test?

hspec

@amitaibu
Copy link
Collaborator Author

It got this error when trying to access the gitpod:

Here are the steps how I've tried to add hspec

  1. Spin new GitPod out of https://github.com/gitpod-io/template-ihp
  2. Add hspec to default.nix
  3. Run make -B .envrc
  4. Try to execute hspec - doesn't recognize command

@amitaibu
Copy link
Collaborator Author

Here's a Workspace snapshot, maybe that would work - https://gitpod.io#snapshot/76b48fa0-9e16-49af-8370-1235db2bde39

@mpscholten
Copy link
Member

Thanks :)

Try to execute hspec - doesn't recognize command

I'm not aware that hspec is callable from the CLI. In our projects we typically have a Test/Main.hs file that imports and runs all the tests. Similar like this one in IHP https://github.com/digitallyinduced/ihp/blob/master/Test/Main.hs

Then I run ghci and :l Test/Main and main to run the Test/Main.hs module.

@amitaibu
Copy link
Collaborator Author

Alright, that makes sense. So what commands should we mention in https://ihp.digitallyinduced.com/Guide/testing.html#running-a-test (Running a Test)

@amitaibu
Copy link
Collaborator Author

I mean:

nix-shell
ghci
:l Test/Main
main

And remove the hspec spec?

@amitaibu
Copy link
Collaborator Author

:l Test/Main is actually for IHP lib. Not for a project

@mpscholten
Copy link
Member

Yes 馃憤

:l Test/Main is actually for IHP lib. Not for a project

Should be the same for the actual project itself. Or then we should update the testing docs to make clear that tests should be stored in the Test/ directory of the project (which needs to be created on first use)

@amitaibu
Copy link
Collaborator Author

Yeah, PR is indeed trying to fix the docs 馃樃 . So should I copy the Test/Main.hs from IHP lib?

@mpscholten
Copy link
Member

So should I copy the Test/Main.hs from IHP lib?

Yes that sounds good to me 馃憤

@amitaibu
Copy link
Collaborator Author

Getting closer.. I'm trying to add it here as a playground, but now have

Test/Controller/BidSpec.hs:20:19: error:
    Variable not in scope: makeConfig :: IO ConfigBuilder
   |
20 | spec = beforeAll (makeConfig >>= mockContext WebApplication) do

However I couldn't fund makeConfig - where is it coming from?

@mpscholten
Copy link
Member

However I couldn't fund makeConfig - where is it coming from?

Should be the same as in Config.hs, so something like this:

makeConfig :: ConfigBuilder
makeConfig = do
    option Development
    option (AppHostname "localhost")

@amitaibu
Copy link
Collaborator Author

amitaibu commented Oct 15, 2021

Note to self, add comment about

ghci
GHCi, version 8.10.3: https://www.haskell.org/ghc/  :? for help
*** WARNING: . is writable by someone else, IGNORING!
Suggested fix: execute 'chmod go-w .'

That should become

GHCi, version 8.10.3: https://www.haskell.org/ghc/  :? for help
package flags have changed, resetting and loading new packages...
Loaded GHCi configuration from /home/amitaibu/Sites/Haskell/ihp/blog/.ghci

@amitaibu amitaibu changed the title Attempt to fix Testing docs Fix Testing docs Oct 17, 2021
@mpscholten mpscholten merged commit 3b2270b into digitallyinduced:master Oct 17, 2021
@amitaibu
Copy link
Collaborator Author

PR is actually outdated with your changes - I was just working on an updated one :)

@amitaibu amitaibu deleted the patch-2 branch October 17, 2021 12:53
@mpscholten
Copy link
Member

Ok, feel free to make a new one 馃憤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants