Skip to content

Commit

Permalink
Separate elm src and add unit tests
Browse files Browse the repository at this point in the history
In order to add a test for
rtfeldman#336, this commit
moves all elm source files from `//src` to `//elm/src`.

A unit test has also been added at `//elm/tests/`.
The `//elm/elm.json` file is used when generating the source and for
running unit tests.
There is still `//elm.json` but this is now used only by
`//tests/ci.json`.
  • Loading branch information
harrysarson committed Feb 20, 2019
1 parent 877d818 commit b922cd5
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 10 deletions.
9 changes: 2 additions & 7 deletions elm.json
@@ -1,15 +1,10 @@
{
"type": "application",
"source-directories": [
"src"
],
"source-directories": [],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/core": "1.0.0",
"elm/json": "1.0.0",
"elm/random": "1.0.0",
"elm/time": "1.0.0"
"elm/core": "1.0.0"
},
"indirect": {}
},
Expand Down
1 change: 1 addition & 0 deletions elm/.gitignore
@@ -0,0 +1 @@
elm-stuff/
25 changes: 25 additions & 0 deletions elm/elm.json
@@ -0,0 +1,25 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/core": "1.0.0",
"elm/json": "1.0.0",
"elm/random": "1.0.0",
"elm/time": "1.0.0"
},
"indirect": {}
},
"test-dependencies": {
"direct": {
"elm-explorations/test": "1.2.0"
},
"indirect": {
"elm/html": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
62 changes: 62 additions & 0 deletions elm/tests/Test/Reporter/Console/FormatTest.elm
@@ -0,0 +1,62 @@
module Test.Reporter.Console.FormatTest exposing (suite)

import Test exposing (..)
import Expect
import Test.Reporter.Console.Format exposing (highlightEqual)

suite : Test
suite = describe "highlightEqual"
[ describe "strings that should *not* be highlighted"
[ describe "very different strings"
[ test "Two strings which are *just* too different for high" <|
\() ->
let
expected =
"Err { context = \"Explanation of what went so wrong\", description = \"An error\" }"

actual =
"Ok \"Success.\""
in
highlightEqual expected actual
|> Expect.equal Nothing
, test "A string containing another string interpersed with other characters" <|
\() ->
let
expected =
"OhK3 S-u5c6c4e2s2s 4"

actual =
"Ok (Success.>"
in
highlightEqual expected actual
|> Expect.equal Nothing
]
, test "strings containing floating point numbers" <|
\() ->
let
expected =
"1.6"

actual =
"16"
in
highlightEqual expected actual
|> Expect.equal Nothing
]
, describe "strings that should be highlighted"
[ test "similar strings" <|
\() ->
let
expected =
"Err { context = \"Success\" }"

actual =
"(Ok \"Success\""
in
highlightEqual expected actual
|> Expect.notEqual Nothing

]
]


4 changes: 2 additions & 2 deletions lib/Generate.js
Expand Up @@ -128,7 +128,7 @@ function generateElmJson(
};

var nodeTestRunnerElmJsonPath = path.resolve(
path.join(__dirname, '..', 'elm.json')
path.join(__dirname, '..', 'elm', 'elm.json')
);
var nodeTestRunnerElmJson = fs.readJsonSync(nodeTestRunnerElmJsonPath);
// we want to use the version of elm-explorations/test that the user
Expand Down Expand Up @@ -208,7 +208,7 @@ function generateElmJson(

// NOTE: we must include node-test-runner's Elm source as a source-directory
// instead of adding it as a dependency so that it can include port modules
path.resolve(path.join(__dirname, '..', 'src')),
path.resolve(path.join(__dirname, '..', 'elm', 'src')),
].concat(sourceDirs);

// When running node-test-runner's own test suite, the node-test-runner/src folder
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"flow": "flow",
"test": "flow check && npm run prettier:check && mocha tests",
"test": "flow check && npm run prettier:check && mocha tests && cd elm && ../bin/elm-test",
"prettier:check": "prettier \"lib/**/*.js\" \"tests/**/*.js\" --list-different",
"prettier:write": "prettier \"lib/**/*.js\" \"tests/**/*.js\" --write"
},
Expand Down

0 comments on commit b922cd5

Please sign in to comment.