Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# node-elm-test
Runs [elm-test](https://github.com/deadfoxygrandpa/Elm-Test) suites from Node.js

Install it with `npm install -g elm-test`, then try this after downloading this repository:
## Installation

```bash
cd examples
elm-package install --yes
elm-test Test.elm
npm install -g elm-test
```

## Usage

```bash
elm-test init # Adds the Elm-Test dependency and creates TestRunner.elm and Tests.elm
elm-test TestRunner.elm # Runs the tests
```

Then add your tests to Tests.elm.

Also check out [`elm-check`](https://github.com/TheSeamau5/elm-check) for property-based testing via `elm-test`!
32 changes: 30 additions & 2 deletions bin/elm-test
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,39 @@ process.title = 'elm-test';

var compile = require("node-elm-compiler").compile,
suffix = require("../elm-io-ports.js"),
fs = require("fs"),
fs = require("fs-extra"),
path = require("path"),
temp = require("temp").track(), // Automatically cleans up temp files.
util = require("util"),
_ = require("lodash"),
childProcess = require("child_process");

if (process.argv[2] == "init") {
var copyTemplate = function(templateName) {
if (fs.existsSync(templateName)) {
console.log(templateName + " already exists");
} else {
fs.copySync(path.resolve(__dirname, "../templates/" + templateName), templateName);
console.log("Created " + templateName);
}
};

var elmOptions = "";
if (process.argv[3] == "--yes" || process.argv[3] == "-y") {
elmOptions += " --yes";
}

var execElmSync = function(command) {
childProcess.execSync(command + elmOptions, {stdio:[0,1,2]});
}

execElmSync("elm package install deadfoxygrandpa/Elm-Test");
execElmSync("elm package install maxsnew/IO");
copyTemplate("TestRunner.elm");
copyTemplate("Tests.elm");
process.exit(0);
}

var testFile = process.argv[2],
cwd = __dirname;

Expand All @@ -22,7 +49,8 @@ function spawnCompiler(cmd, args, opts) {
}

if (typeof testFile !== "string") {
console.log("Usage: elm-test TESTFILE\n");
console.log("Usage: elm-test init [--yes] # Create example tests\n");
console.log("Usage: elm-test TESTFILE # Run tests\n");
process.exit(1);
}

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.3.0",
"description": "Run elm-test suites.",
"main": "elm-test.js",
"engines" : {
"node" : ">=0.12.0"
"engines": {
"node": ">=0.12.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -28,6 +28,7 @@
},
"homepage": "https://github.com/rtfeldman/node-elm-test#readme",
"dependencies": {
"fs-extra": "0.23.1",
"lodash": "3.9.3",
"node-elm-compiler": "0.4.0+elm-0.15.1",
"temp": "0.8.1"
Expand Down
18 changes: 18 additions & 0 deletions templates/TestRunner.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Main where

import Signal exposing (Signal)

import ElmTest.Runner.Console exposing (runDisplay)
import IO.IO exposing (IO)
import IO.Runner exposing (Request, Response)
import IO.Runner as Run

import Tests

console : IO ()
console = runDisplay Tests.all

port requests : Signal Request
port requests = Run.run responses console

port responses : Signal Response
16 changes: 16 additions & 0 deletions templates/Tests.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Tests where

import ElmTest.Assertion as A exposing (assertEqual, assert)
Copy link
Owner

Choose a reason for hiding this comment

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

Seems reasonable to expose assert and assertEqual by default, but I think as A is more of a personal preference, and might surprise people.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good to remove as A

import ElmTest.Test exposing (..)

import String


all : Test
all =
suite "A Test Suite"
[
test "Addition" (assertEqual (3 + 7) 10),
test "String.left" (assertEqual "a" (String.left 1 "abcdefg")),
test "This test should fail" (assert False)
]
Copy link
Owner

Choose a reason for hiding this comment

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

I'd format this like so:

all : Test
all =
    suite "A Test Suite"
        [
            test "Addition" (assertEqual (3 + 7) 10),
            test "String.left" (assertEqual "a" (String.left 1 "abcdefg")),
            test "This test should fail" (assert False)
        ]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay (I had just copied this code from the examples folder)