Skip to content

Commit

Permalink
Merge pull request #42 from dwyl/testing
Browse files Browse the repository at this point in the history
#5 writing up piece on testing in elm
  • Loading branch information
nelsonic committed Jan 22, 2017
2 parents fbd25dc + a227699 commit e3f344b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Expand Up @@ -221,6 +221,45 @@ as you _really_ should be following the [principle of least privilege](https://e
> Help Wanted summarizing the language features!
> for now see: http://elm-lang.org/docs/syntax
## Testing
Ready to start testing?
Simply follow these 3 steps:

1) ``` npm i -g elm-test```

2) ``` elm test init ```
This will set up your test environment and give you 7 dummy tests in your newly created test folder

3) Run ```elm test``` or the **very nice** ```elm test --watch``` which will re-run your tests as you write them

The general format of the tests are:
```elm
describe "Dummy test"
[ test "dummy test description" <|
\() ->
Expect.equal actualValue expectedValue
]
```
For example:
``` elm
all : Test
all =
describe "My first test"
[ test "Addition test works correctly" <|
\() ->
Expect.equal (2 + 2) 4
, test "Our subtraction function works correctly" <|
\() ->
-- here we are pretending we have a subtract function that takes 2 arguments
Expect.equal (subtract 10 5) 5
]
```

More info on testing can be found [here](https://medium.com/@_rchaves_/testing-in-elm-93ad05ee1832#.3i3ibxcxz) and [here](http://package.elm-lang.org/packages/elm-community/elm-test/2.1.0)

### Circle CI

To set up your elm project on Circle CI, copy over our ```circle.yml``` and ```circle-dependencies.sh``` and follow the instructions on [our Circle CI tutorial](https://github.com/dwyl/learn-circleci)

## Reading

Expand Down
13 changes: 13 additions & 0 deletions circle-dependencies.sh
@@ -0,0 +1,13 @@
# Installs sysconfcpus so we can make elm compile faster
# and limit the CPUS that elm uses to compile.
# See: https://github.com/elm-lang/elm-compiler/issues/1473#issuecomment-245704142
# and https://github.com/JamesHageman/whistlet-elm/blob/1bc50446987e3bcf92a9710698ae417652d7517f/circle-deps.sh
export INSTALL_PATH="$HOME/dependencies"

if [ ! -d $INSTALL_PATH/sysconfcpus/bin ]; then
git clone https://github.com/obmarg/libsysconfcpus.git
cd libsysconfcpus
./configure --prefix=$INSTALL_PATH/sysconfcpus
make && make install
cd ..
fi
17 changes: 17 additions & 0 deletions circle.yml
@@ -0,0 +1,17 @@

machine:
node:
version: 6.0.0

general:
artifacts:
- "test"

test:
pre:
- sh circle-dependencies.sh
- npm i -g elm

# using sysconfcpus to speed up elm compiler # See: https://github.com/elm-lang/elm-compiler/issues/1473#issuecomment-245704142
override:
- ~/dependencies/sysconfcpus/bin/sysconfcpus -n 2 npm test

0 comments on commit e3f344b

Please sign in to comment.