Skip to content

Commit

Permalink
Elm tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Mar 5, 2017
1 parent 4d14634 commit 397efdc
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 28 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -35,4 +35,5 @@ before_install:

script:
- $TRAVIS_BUILD_DIR/sysconfcpus/bin/sysconfcpus -n 2 make build
- $TRAVIS_BUILD_DIR/sysconfcpus/bin/sysconfcpus -n 2 make elm-test
- mix test
26 changes: 17 additions & 9 deletions Makefile
@@ -1,37 +1,45 @@
NBIN=./node_modules/.bin
NBIN=$(shell pwd)/node_modules/.bin
ELM_TEST=$(NBIN)/elm-test --compiler $(NBIN)/elm-make


help: ## Prints help for targets with comments
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'


.PHONY: install
install: ## Install deps
mix deps.get
yarn install
$(NBIN)/elm-package install


.PHONY: start
start: ## Start the server in dev mode
iex -S mix


.PHONY: start-production
start-production:
MIX_ENV=production mix app.start


.PHONY: frontend-server
frontend-server:
NODE_ENV=development $(NBIN)/webpack-dev-server --hot --inline --content-base src/, --no-info --colors


.PHONY: build
build: ## Compile the frontend
rm -rf dist
NODE_ENV=production $(NBIN)/webpack -p


.PHONY: \
start-production \
frontend-server \
install \
start \
build \
help
.PHONY: elm-test
elm-test: ## Run the front end tests
$(ELM_TEST)


.PHONY: elm-test-watch
elm-test-watch: ## Run the front end test watcher
$(ELM_TEST) --watch
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -15,6 +15,11 @@ A massive rip off of Michael Lovitt's [Rubular](http://rubular.com/).
make
# Start the app in dev mode
make start

# Run backend tests
mix test
# Run frontend tests
make elm-test-watch
```


Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -23,6 +23,7 @@
"css-loader": "^0.26.1",
"elm": "^0.18.0",
"elm-hot-loader": "^0.5.4",
"elm-test": "^0.18.2",
"elm-webpack-loader": "^4.2.0",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
Expand Down
1 change: 1 addition & 0 deletions tests/.gitignore
@@ -0,0 +1 @@
/elm-stuff/
13 changes: 13 additions & 0 deletions tests/Main.elm
@@ -0,0 +1,13 @@
port module Main exposing (..)

import Tests
import Test.Runner.Node exposing (run, TestProgram)
import Json.Encode exposing (Value)


main : TestProgram
main =
run emit Tests.all


port emit : ( String, Value ) -> Cmd msg
40 changes: 40 additions & 0 deletions tests/Tests.elm
@@ -0,0 +1,40 @@
module Tests exposing (..)

import Test exposing (..)
import Expect
import Fuzz exposing (list, int, tuple, string)
import String


all : Test
all =
describe "Sample Test Suite"
[ describe "Unit test examples"
[ test "Addition" <|
\() -> Expect.equal (3 + 7) 10
, test "String.left" <|
\() ->
Expect.equal "a" (String.left 1 "abcdefg")
]
, describe "Fuzz test examples, using randomly generated input"
[ fuzz (list int) "Lists always have positive length" <|
\aList ->
List.length aList
|> Expect.atLeast 0
, fuzz (list int) "Sorting a list does not change its length" <|
\aList ->
List.sort aList
|> List.length
|> Expect.equal (List.length aList)
, fuzzWith { runs = 1000 } int "List.member will find an integer in a list containing it" <|
\i ->
List.member i [ i ]
|> Expect.true "If you see this, List.member returned False!"
, fuzz2 string string "The length of a string equals the sum of its substrings' lengths" <|
\s1 s2 ->
s1
++ s2
|> String.length
|> Expect.equal (String.length s1 + String.length s2)
]
]
20 changes: 20 additions & 0 deletions tests/elm-package.json
@@ -0,0 +1,20 @@
{
"version": "1.0.0",
"summary": "",
"repository": "https://github.com/lpil/elixre.git",
"license": "AGPLv3",
"source-directories": [
".",
"../client"
],
"exposed-modules": [],
"dependencies": {
"elm-community/json-extra": "2.0.0 <= v < 3.0.0",
"elm-lang/html": "2.0.0 <= v < 3.0.0",
"mgold/elm-random-pcg": "4.0.2 <= v < 5.0.0",
"elm-lang/core": "5.0.0 <= v < 6.0.0",
"elm-community/elm-test": "3.0.0 <= v < 4.0.0",
"rtfeldman/node-test-runner": "3.0.0 <= v < 4.0.0"
},
"elm-version": "0.18.0 <= v < 0.19.0"
}
90 changes: 71 additions & 19 deletions yarn.lock
Expand Up @@ -334,7 +334,7 @@ center-align@^0.1.1:
align-text "^0.1.3"
lazy-cache "^1.0.3"

chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
chalk@1.1.3, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
dependencies:
Expand All @@ -344,6 +344,21 @@ chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chokidar@1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.6.0.tgz#90c32ad4802901d7713de532dc284e96a63ad058"
dependencies:
anymatch "^1.3.0"
async-each "^1.0.0"
glob-parent "^2.0.0"
inherits "^2.0.1"
is-binary-path "^1.0.0"
is-glob "^2.0.0"
path-is-absolute "^1.0.0"
readdirp "^2.0.0"
optionalDependencies:
fsevents "^1.0.0"

chokidar@^1.0.0:
version "1.6.1"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.6.1.tgz#2f4447ab5e96e50fb3d789fd90d4c72e0e4c70c2"
Expand Down Expand Up @@ -675,13 +690,13 @@ date-now@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b"

debug@2.6.1:
debug@2.6.1, debug@^2.2.0:
version "2.6.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.1.tgz#79855090ba2c4e3115cc7d8769491d58f0491351"
dependencies:
ms "0.7.2"

debug@^2.2.0, debug@~2.2.0:
debug@~2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da"
dependencies:
Expand Down Expand Up @@ -779,6 +794,21 @@ elm-hot-loader@^0.5.4:
dependencies:
loader-utils "^0.2.12"

elm-test@^0.18.2:
version "0.18.2"
resolved "https://registry.yarnpkg.com/elm-test/-/elm-test-0.18.2.tgz#1e94bd292de42a4960c6fdbe64eacee30669040a"
dependencies:
chalk "1.1.3"
chokidar "1.6.0"
cross-spawn "4.0.0"
find-up "^1.1.2"
firstline "^1.2.0"
fs-extra "0.30.0"
lodash "4.13.1"
minimist "^1.2.0"
node-elm-compiler "4.1.0"
temp "0.8.3"

elm-webpack-loader@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/elm-webpack-loader/-/elm-webpack-loader-4.2.0.tgz#469e1832c304182b6b7fc619fb7518fb3eab47f5"
Expand Down Expand Up @@ -983,14 +1013,14 @@ finalhandler@~1.0.0:
statuses "~1.3.1"
unpipe "~1.0.0"

find-up@^1.0.0:
find-up@^1.0.0, find-up@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f"
dependencies:
path-exists "^2.0.0"
pinkie-promise "^2.0.0"

firstline@1.2.0:
firstline@1.2.0, firstline@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/firstline/-/firstline-1.2.0.tgz#c9f4886e7f7fbf0afc12d71941dce06b192aea05"

Expand Down Expand Up @@ -1036,6 +1066,16 @@ fresh@0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.0.tgz#f474ca5e6a9246d6fd8e0953cfa9b9c805afa78e"

fs-extra@0.30.0:
version "0.30.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-0.30.0.tgz#f233ffcc08d4da7d432daa449776989db1df93f0"
dependencies:
graceful-fs "^4.1.2"
jsonfile "^2.1.0"
klaw "^1.0.0"
path-is-absolute "^1.0.0"
rimraf "^2.2.8"

fs-extra@^0.26.4:
version "0.26.7"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-0.26.7.tgz#9ae1fdd94897798edab76d0918cf42d0c3184fa9"
Expand Down Expand Up @@ -1640,6 +1680,10 @@ lodash.uniq@^4.3.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"

lodash@4.13.1:
version "4.13.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.13.1.tgz#83e4b10913f48496d4d16fec4a560af2ee744b68"

lodash@4.14.2:
version "4.14.2"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.14.2.tgz#bbccce6373a400fbfd0a8c67ca42f6d1ef416432"
Expand Down Expand Up @@ -1817,6 +1861,14 @@ node-dir@^0.1.10:
dependencies:
minimatch "^3.0.2"

node-elm-compiler@4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/node-elm-compiler/-/node-elm-compiler-4.1.0.tgz#1b00244902f3f6e5cd5f6a3abadfb0f55b6c35dd"
dependencies:
cross-spawn "4.0.0"
lodash "4.14.2"
temp "^0.8.3"

node-elm-compiler@^4.2.1:
version "4.3.0"
resolved "https://registry.yarnpkg.com/node-elm-compiler/-/node-elm-compiler-4.3.0.tgz#9f4fe793cad6d59a6a124207ac168faf5886d24e"
Expand Down Expand Up @@ -2643,56 +2695,56 @@ repeating@^2.0.0:
dependencies:
is-finite "^1.0.0"

request@2, request@^2.79.0:
version "2.79.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.79.0.tgz#4dfe5bf6be8b8cdc37fcf93e04b65577722710de"
request@2, request@2.74.0, request@^2.61.0:
version "2.74.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.74.0.tgz#7693ca768bbb0ea5c8ce08c084a45efa05b892ab"
dependencies:
aws-sign2 "~0.6.0"
aws4 "^1.2.1"
bl "~1.1.2"
caseless "~0.11.0"
combined-stream "~1.0.5"
extend "~3.0.0"
forever-agent "~0.6.1"
form-data "~2.1.1"
form-data "~1.0.0-rc4"
har-validator "~2.0.6"
hawk "~3.1.3"
http-signature "~1.1.0"
is-typedarray "~1.0.0"
isstream "~0.1.2"
json-stringify-safe "~5.0.1"
mime-types "~2.1.7"
node-uuid "~1.4.7"
oauth-sign "~0.8.1"
qs "~6.3.0"
qs "~6.2.0"
stringstream "~0.0.4"
tough-cookie "~2.3.0"
tunnel-agent "~0.4.1"
uuid "^3.0.0"

request@2.74.0, request@^2.61.0:
version "2.74.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.74.0.tgz#7693ca768bbb0ea5c8ce08c084a45efa05b892ab"
request@^2.79.0:
version "2.79.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.79.0.tgz#4dfe5bf6be8b8cdc37fcf93e04b65577722710de"
dependencies:
aws-sign2 "~0.6.0"
aws4 "^1.2.1"
bl "~1.1.2"
caseless "~0.11.0"
combined-stream "~1.0.5"
extend "~3.0.0"
forever-agent "~0.6.1"
form-data "~1.0.0-rc4"
form-data "~2.1.1"
har-validator "~2.0.6"
hawk "~3.1.3"
http-signature "~1.1.0"
is-typedarray "~1.0.0"
isstream "~0.1.2"
json-stringify-safe "~5.0.1"
mime-types "~2.1.7"
node-uuid "~1.4.7"
oauth-sign "~0.8.1"
qs "~6.2.0"
qs "~6.3.0"
stringstream "~0.0.4"
tough-cookie "~2.3.0"
tunnel-agent "~0.4.1"
uuid "^3.0.0"

require-directory@^2.1.1:
version "2.1.1"
Expand Down Expand Up @@ -3030,7 +3082,7 @@ tar@2.2.1, tar@^2.0.0, tar@~2.2.1:
fstream "^1.0.2"
inherits "2"

temp@^0.8.3:
temp@0.8.3, temp@^0.8.3:
version "0.8.3"
resolved "https://registry.yarnpkg.com/temp/-/temp-0.8.3.tgz#e0c6bc4d26b903124410e4fed81103014dfc1f59"
dependencies:
Expand Down

0 comments on commit 397efdc

Please sign in to comment.